common.h/common.cpp garbage cleanup

This commit is contained in:
zeromus 2016-08-16 03:08:52 -05:00
parent ff3eb24e2a
commit b646efdd55
6 changed files with 23 additions and 66 deletions

View File

@ -379,9 +379,7 @@ void GameInfo::populate()
};
memset(ROMserial, 0, sizeof(ROMserial));
memset(ROMname, 0, sizeof(ROMname));
//set or build as appropriate ROMserial
if(isHomebrew())
{
//we can't really make a serial for a homebrew game that hasnt set a game code
@ -405,9 +403,8 @@ void GameInfo::populate()
}
//rom name is probably set even in homebrew, so do it regardless
memset(ROMname, 0, sizeof(ROMname));
memcpy(ROMname, header.gameTile, 12);
trim(ROMname,20);
ROMname[12] = 0;
/*if(header.IconOff < romsize)
{

View File

@ -325,7 +325,7 @@ struct GameInfo
u32 romType;
u32 headerOffset;
char ROMserial[20];
char ROMname[20];
char ROMname[13];
bool _isDSiEnhanced;
NDS_header header;
//a copy of the pristine secure area from the rom

View File

@ -561,6 +561,22 @@ void CHEATS::setDescription(const char *description, u32 pos)
list[pos].description[sizeof(list[pos].description) - 1] = '\0';
}
static char *trim(char *s, int len = -1)
{
char *ptr = NULL;
if (!s) return NULL;
if (!*s) return s;
if(len==-1)
ptr = s + strlen(s) - 1;
else ptr = s+len - 1;
for (; (ptr >= s) && (!*ptr || isspace((u8)*ptr)) ; ptr--);
ptr[1] = '\0';
return s;
}
BOOL CHEATS::save()
{
const char *types[] = {"DS", "AR", "CB"};
@ -722,7 +738,7 @@ BOOL CHEATS::load()
char tmp_buf[9] = {0};
strncpy(tmp_buf, &codeStr[i * 16], 8);
sscanf_s(tmp_buf, "%x", &tmp_cht.code[i][0]);
sscanf(tmp_buf, "%x", &tmp_cht.code[i][0]);
if (tmp_cht.type == 0)
{
@ -731,7 +747,7 @@ BOOL CHEATS::load()
}
strncpy(tmp_buf, &codeStr[(i * 16) + 8], 8);
sscanf_s(tmp_buf, "%x", &tmp_cht.code[i][1]);
sscanf(tmp_buf, "%x", &tmp_cht.code[i][1]);
}
list.push_back(tmp_cht);

View File

@ -32,38 +32,6 @@
static std::map<void *, void *> _alignedPtrList; // Key: Aligned pointer / Value: Original pointer
char *trim(char *s, int len)
{
char *ptr = NULL;
if (!s) return NULL;
if (!*s) return s;
if(len==-1)
ptr = s + strlen(s) - 1;
else ptr = s+len - 1;
for (; (ptr >= s) && (!*ptr || isspace((u8)*ptr)) ; ptr--);
ptr[1] = '\0';
return s;
}
char *removeSpecialChars(char *s)
{
char *buf = s;
if (!s) return NULL;
if (!*s) return s;
for (u32 i = 0; i < strlen(s); i++)
{
if (isspace((u8)s[i]) && (s[i] != 0x20))
*buf = 0x20;
else
*buf = s[i];
buf++;
}
*buf = 0;
return s;
}
static MAKER makerCodes[] = {
{ 0x3130, "Nintendo" },
{ 0x3230, "Rocket Games, Ajinomoto" },

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2015 DeSmuME team
Copyright (C) 2008-2016 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -25,30 +25,6 @@
#include <string>
#include "types.h"
#if defined(WIN32)
#define CLASSNAME "DeSmuME"
#else // non Windows
#define sscanf_s sscanf
#endif
template<typename T>
T reverseBits(T x)
{
T h = 0;
T i = 0;
for (i = 0; i < sizeof(T)*8; i++)
{
h = (h << 1) + (x & 1);
x >>= 1;
}
return h;
}
extern char *trim(char *s, int len=-1);
extern char *removeSpecialChars(char *s);
// ===============================================================================
// Message dialogs
// ===============================================================================

View File

@ -202,7 +202,7 @@ u32 ADVANsCEne::convertDB(const char *in_filename, EMUFILE* output)
// CRC32
el_crc32 = el->FirstChildElement("files");
sscanf_s(el_crc32->FirstChildElement("romCRC")->GetText(), "%x", &crc32);
sscanf(el_crc32->FirstChildElement("romCRC")->GetText(), "%x", &crc32);
output->fwrite(&crc32, sizeof(u32));
// Save type