-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgameinfo.c
More file actions
289 lines (272 loc) · 9.08 KB
/
gameinfo.c
File metadata and controls
289 lines (272 loc) · 9.08 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include "gameinfo.h"
ColorConfig* gameinfoconfig_get_colorconfig(GameInfoConfig* prCfg) {
if (prCfg != NULL) {
return &prCfg->color;
}
return NULL;
}
CursorPos* gameinfoconfig_get_cursorpos(GameInfoConfig* prCfg) {
if (prCfg != NULL) {
return &prCfg->position;
}
return NULL;
}
int gameinfoconfig_init(GameInfoConfig* prCfg) {
ColorConfig *prCc = NULL;
CursorPos *prCp = NULL;
int r = 0;
if (prCfg == NULL) {
return GAMEINFO_NULLPTR;
}
prCc = &prCfg->color;
prCp = &prCfg->position;
r = colorconfig_init(prCc);
if (r != COLORCONFIG_SUCCESS) {
return GAMEINFO_FAILURE;
}
r = cursorpos_init(prCp);
if (r != CURSORPOS_SUCCESS) {
return GAMEINFO_FAILURE;
}
return GAMEINFO_SUCCESS;
}
int gameinfoconfig_set_colorconfig(GameInfoConfig* prCfg, ColorConfig* prColor)
{
ColorConfig* prDest = NULL;
int r = 0;
if (prCfg == NULL || prColor == NULL) {
return GAMEINFO_NULLPTR;
}
prDest = gameinfoconfig_get_colorconfig(prCfg);
if (prDest == NULL) {
return GAMEINFO_FAILURE;
}
r = colorconfig_copy(prDest, prColor);
if (r != COLORCONFIG_SUCCESS) {
return GAMEINFO_FAILURE;
}
return GAMEINFO_SUCCESS;
}
int gameinfoconfig_set_cursor(GameInfoConfig* prCfg, int x, int y) {
CursorPos* prPos = NULL;
if (prCfg == NULL) {
return GAMEINFO_NULLPTR;
}
prPos = gameinfoconfig_get_cursorpos(prCfg);
if (prPos == NULL) {
return GAMEINFO_FAILURE;
}
prPos->x = x;
prPos->y = y;
return GAMEINFO_SUCCESS;
}
int gameinfoconfig_set_cursorpos(GameInfoConfig* prCfg, CursorPos* prPos) {
CursorPos* prDest = NULL;
int r = 0;
if (prCfg == NULL || prPos == NULL) {
return GAMEINFO_NULLPTR;
}
prDest = gameinfoconfig_get_cursorpos(prCfg);
if (prDest == NULL) {
return GAMEINFO_FAILURE;
}
r = cursorpos_copy(prDest, prPos);
if (r != CURSORPOS_SUCCESS) {
return GAMEINFO_FAILURE;
}
return GAMEINFO_SUCCESS;
}
GameInfoConfig* gameinfo_get_config(GameInfo* prInfo) {
if (prInfo != NULL) {
return &prInfo->config;
}
return NULL;
}
int gameinfo_init(GameInfo *prInfo) {
GameInfoConfig* prCfg = NULL;
int i = 0;
int r = 0;
if (prInfo == NULL) {
return GAMEINFO_NULLPTR;
}
for (i = 0; i < GAMEINFO_MAXSTUBCT; i++) {
prInfo->aprStubTable[i] = NULL;
prInfo->arUID[i] = 0;
}
prCfg = &prInfo->config;
r = gameinfoconfig_init(prCfg);
if (r != GAMEINFO_SUCCESS) {
return GAMEINFO_FAILURE;
}
prInfo->libEntryCount = 0;
prInfo->libStubCount = 0;
prInfo->loaded = 0;
prInfo->module_count = 0;
prInfo->prApCfg = NULL;
prInfo->prLibTable = NULL;
prInfo->prModule = NULL;
prInfo->sGameId = NULL;
prInfo->textEnd = NULL;
return GAMEINFO_SUCCESS;
}
int gameinfo_load(GameInfo *prInfo) {
SceModule* prModule = NULL;
SceLibraryEntryTable* prEntTable = NULL;
SceLibraryStubTable* prStubTable = NULL;
SceLibraryStubTable* prCur = NULL;
int stubsz = 0;
int stubct = 0;
unsigned int tablesz = 0;
unsigned int tablep = 0;
int i = 0;
char sMsg[256];
if (prInfo == NULL) {
return GAMEINFO_NULLPTR;
}
if (prInfo->loaded == 1) {
return GAMEINFO_SUCCESS;
}
prInfo->textEnd = 0x09FFFFFF;
prModule = sceKernelFindModuleByAddress(0x08804000);
if (prModule != NULL) {
prInfo->prModule = prModule;
prEntTable = (SceLibraryEntryTable*)prModule->ent_top;
if (prEntTable != NULL) {
prInfo->prLibTable = prEntTable;
prInfo->libEntryCount = prModule->ent_size / sizeof(SceLibraryEntryTable);
} else {
}
prStubTable = (SceLibraryStubTable*)prModule->stub_top;
if (prStubTable != NULL) {
tablesz = prModule->stub_size;
while (tablep < tablesz) {
prCur = (SceLibraryStubTable*)(prModule->stub_top + tablep);
stubsz = prCur->len * 4;
prInfo->aprStubTable[stubct] = prCur;
stubct++;
tablep += stubsz;
}
prInfo->libStubCount = stubct;
} else {
}
for (i = 0; i < prInfo->libStubCount; i++) {
prCur = prInfo->aprStubTable[i];
if (prCur->stubtable < prInfo->textEnd) {
prInfo->textEnd = prCur->stubtable;
}
}
} else {
}
prInfo->loaded = 1;
return GAMEINFO_SUCCESS;
}
int gameinfoRedraw(GameInfo *prInfo) {
AppletConfig* prCfg = NULL;
ColorConfig* prColor = NULL;
if (prInfo == NULL) {
return GAMEINFO_NULLPTR;
}
prCfg = prInfo->prApCfg;
if (prInfo->loaded == 0) {
if (gameinfo_load(prInfo) != GAMEINFO_SUCCESS) {
return GAMEINFO_FAILURE;
}
}
if (prCfg != NULL) {
prColor = appletconfig_get_panelcolor(prCfg);
} else {
prColor = &prInfo->config.color;
}
pspDebugScreenSetBackColor(prColor->background);
pspDebugScreenSetTextColor(prColor->text);
pspDebugScreenSetXY(prInfo->config.position.x, prInfo->config.position.y);
SceModule *prMod = prInfo->prModule;
if (prMod != NULL) {
pspDebugScreenKprintf("Attribute: 0x%04X Version: %d.%d\n",
prMod->attribute, prMod->version[0], prMod->version[1]);
pspDebugScreenKprintf("Module Name: %s\n", prMod->modname);
/*
pspDebugScreenKprintf("unknown1: 0x%08X unknown2: 0x%08X\n",
prMod->unknown1, prMod->unknown2);
*/
pspDebugScreenKprintf("Module Id: 0x%08X\n", prMod->modid);
/*
pspDebugScreenKprintf("unknown3[4]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
prMod->unknown3[0], prMod->unknown3[1], prMod->unknown3[2],
prMod->unknown3[3]);
*/
pspDebugScreenKprintf("Ent Top: 0x%08X Ent Size: 0x%08X\n",
prMod->ent_top, prMod->ent_size);
pspDebugScreenKprintf("Stub Top: 0x%08X Stub Size: 0x%08X\n",
prMod->stub_top, prMod->stub_size);
/*
pspDebugScreenKprintf("unknown4[4]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
prMod->unknown4[0], prMod->unknown4[1], prMod->unknown4[2],
prMod->unknown4[3]);
*/
pspDebugScreenKprintf("GP Value: 0x%08X Entry Address: 0x%08X\n",
prMod->gp_value, prMod->entry_addr);
pspDebugScreenKprintf("Text Address: 0x%08X Text Size: 0x%08X\n",
prMod->text_addr, prMod->text_size);
pspDebugScreenKprintf("Data Size: 0x%08X BSS Size: 0x%08X\n",
prMod->data_size, prMod->bss_size);
pspDebugScreenKprintf("nsegment: 0x%08X\n", prMod->nsegment);
int i = 0;
for (i = 0; i < 4; i++) {
pspDebugScreenKprintf("Segment %d: 0x%08X (0x%08X)\n",
i, prMod->segmentaddr[i], prMod->segmentsize[i]);
}
pspDebugScreenKprintf(".text ends at 0x%08X.\n", prInfo->textEnd);
pspDebugScreenKprintf("Library Entry Count: %d, Stub Count: %d\n",
prInfo->libEntryCount, prInfo->libStubCount);
SceLibraryEntryTable* prEnt = prInfo->prLibTable;
pspDebugScreenKprintf(
"Exported Library Version: %d.%d, Attributes: 0x%04X\n",
prEnt->version[0], prEnt->version[1], prEnt->attribute);
pspDebugScreenKprintf(
"Exported Variables: %d, Functions: %d, Entry Table: 0x%08X\n",
prEnt->vstubcount, prEnt->stubcount, prEnt->entrytable);
pspDebugScreenKprintf("Import 0 Address: 0x%08X\n",
prInfo->aprStubTable[0]);
pspDebugScreenKprintf("Import 1 Address: 0x%08X\n",
prInfo->aprStubTable[1]);
pspDebugScreenKprintf("Import 2 Address: 0x%08X\n",
prInfo->aprStubTable[2]);
pspDebugScreenKprintf("Import 3 Address: 0x%08X\n",
prInfo->aprStubTable[3]);
} else {
pspDebugScreenKprintf("Could not find SceModule pointer.\n");
}
return GAMEINFO_SUCCESS;
}
int gameinfo_set_appletconfig(GameInfo* prInfo, AppletConfig* prCfg) {
if (prInfo == NULL) {
return GAMEINFO_MEMORY;
}
prInfo->prApCfg = prCfg;
return GAMEINFO_SUCCESS;
}
int gameinfo_set_colorconfig(GameInfo* prInfo, ColorConfig* prColor) {
GameInfoConfig *prConfig = NULL;
if (prInfo == NULL || prColor == NULL) {
return GAMEINFO_NULLPTR;
}
prConfig = gameinfo_get_config(prInfo);
return gameinfoconfig_set_colorconfig(prConfig, prColor);
}
int gameinfo_set_cursor(GameInfo* prInfo, int x, int y) {
GameInfoConfig* prConfig = NULL;
if (prInfo == NULL) {
return GAMEINFO_NULLPTR;
}
prConfig = gameinfo_get_config(prInfo);
return gameinfoconfig_set_cursor(prConfig, x, y);
}
int gameinfo_set_cursorpos(GameInfo* prInfo, CursorPos* prPos) {
GameInfoConfig* prConfig = NULL;
if (prInfo == NULL || prPos == NULL) {
return GAMEINFO_NULLPTR;
}
prConfig = gameinfo_get_config(prInfo);
return gameinfoconfig_set_cursorpos(prConfig, prPos);
}