2012-05-12 23:08:43 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-08-05 15:48:15 +02:00
|
|
|
|
2012-05-16 21:29:53 +02:00
|
|
|
#include "wip.h"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "memory/mem2.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
static WIP_Code *CodeList = NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
static u32 CodesCount = 0;
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
u32 get_wip_count()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
return CodesCount;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
WIP_Code *get_wip_list()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
return CodeList;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int load_wip_patches(u8 *dir, u8 *gameid)
|
|
|
|
{
|
|
|
|
char filepath[150];
|
2012-11-01 17:39:42 +01:00
|
|
|
char GameID[7];
|
|
|
|
GameID[6] = '\0';
|
2012-07-26 00:12:17 +02:00
|
|
|
memcpy(GameID, gameid, 6);
|
2012-01-21 21:57:41 +01:00
|
|
|
snprintf(filepath, sizeof(filepath), "%s/%s.wip", dir, GameID);
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
FILE *fp = fopen(filepath, "rb");
|
|
|
|
if(!fp)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
memcpy(GameID, gameid, 3);
|
2012-11-01 17:39:42 +01:00
|
|
|
GameID[3] = '\0';
|
2012-01-21 21:57:41 +01:00
|
|
|
snprintf(filepath, sizeof(filepath), "%s/%s.wip", dir, GameID);
|
|
|
|
fp = fopen(filepath, "rb");
|
|
|
|
}
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!fp)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char line[255];
|
|
|
|
gprintf("\nLoading WIP code from %s.\n", filepath);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
while(fgets(line, sizeof(line), fp))
|
|
|
|
{
|
|
|
|
if(line[0] == '#' || strlen(line) < 26)
|
|
|
|
continue;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 offset = (u32) strtoul(line, NULL, 16);
|
|
|
|
u32 srcaddress = (u32) strtoul(line+9, NULL, 16);
|
|
|
|
u32 dstaddress = (u32) strtoul(line+18, NULL, 16);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!CodeList)
|
2012-05-12 23:08:43 +02:00
|
|
|
CodeList = MEM2_alloc(sizeof(WIP_Code));
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
WIP_Code *tmp = MEM2_realloc(CodeList, (CodesCount+1)*sizeof(WIP_Code));
|
|
|
|
if(!tmp)
|
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
free(CodeList);
|
2012-07-26 00:12:17 +02:00
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
CodeList = tmp;
|
|
|
|
CodeList[CodesCount].offset = offset;
|
|
|
|
CodeList[CodesCount].srcaddress = srcaddress;
|
|
|
|
CodeList[CodesCount].dstaddress = dstaddress;
|
|
|
|
CodesCount++;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|