mirror of
https://github.com/jpluimers/macrompatcher.git
synced 2024-05-28 07:41:36 +00:00
875de91fce
1) htonl() and htons() are declared in winsock.h on Windows and require ws2_32 to be linked in. 2) mingw does not have asprintf, so I changed the Qt GUI to use QString's sprintf() member function which should behave identically. 3) Windows Vista and 7 try to run any program with "patch" in the name with administrative privileges for backwards compatibility with legacy stuff, so I added a build step to the Qt app to embed a manifest. I also need to do the same thing with the cli app...
35 lines
636 B
C
35 lines
636 B
C
#include <stdlib.h>
|
|
#ifdef __MINGW32__
|
|
#include <winsock.h>
|
|
#else
|
|
#include <arpa/inet.h>
|
|
#endif
|
|
#include "macrompatcher.h"
|
|
|
|
RomErr GetChecksum(RomCtx *rom, uint32_t *checksum) {
|
|
uint8_t *tmpptr = NULL;
|
|
size_t i;
|
|
|
|
if(!rom || !rom->data || !checksum) return eParmErr;
|
|
|
|
tmpptr = rom->data+4;
|
|
|
|
*checksum = 0;
|
|
for(i = 0; i < rom->filesize; i++) {
|
|
*checksum += tmpptr[i++] << 8;
|
|
*checksum += tmpptr[i];
|
|
}
|
|
|
|
return eSuccess;
|
|
}
|
|
|
|
RomErr UpdateChecksum(RomCtx *rom) {
|
|
uint32_t checksum;
|
|
RomErr ret;
|
|
ret = GetChecksum(rom, &checksum);
|
|
if(ret != eSuccess) return ret;
|
|
|
|
*(uint32_t*)(rom->data) = htonl(checksum);
|
|
return eSuccess;
|
|
}
|