#if defined(FLIPS_WINDOWS) || defined(FLIPS_GTK) || defined(FLIPS_CLI)
#elif defined(_WIN32)
#define FLIPS_WINDOWS
#elif defined(__linux__)
#define FLIPS_GTK
#else
#define FLIPS_CLI
#endif
#define flipsversion "Floating IPS v1.40-pre"
#define flips_rc_vermajor 1
#define flips_rc_verminor 4
#define flips_rc_verpatch 0
#define flips_rc_verstr "1.4.0.0"
#define flips_rc_copyrightstr "\xA9 2013-2019 Alcaro"
#if defined(FLIPS_WINDOWS)
#define UNICODE
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0600
#define NOMINMAX
#ifdef __MINGW32__
#include <stdlib.h>
#undef __USE_MINGW_ANSI_STDIO
#endif #include <windows.h>
#include <windowsx.h>
#include <shlobj.h>
#include <wchar.h>
#include <stdio.h>
#include <commctrl.h>
#include <ctype.h>
#define wcsicmp _wcsicmp
#define wcsdup _wcsdup
#define wtoi _wtoi
#else
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define LPCWSTR const char *
#define LPWSTR char *
#define WCHAR char
#define wcscpy strcpy
#define wcscat strcat
#define wcschr strchr
#define wcslen strlen
#define wcsdup strdup
#define wcsrchr strrchr
#define wcscmp strcmp
#define wcsncmp strncmp
#define wcsicmp strcasecmp
#define wprintf printf
#define wsprintf sprintf
#define wscanf scanf
#define swscanf sscanf
#define wtoi atoi
#define iswalnum isalnum
#define iswalpha isalpha
#define iswascii isascii
#define iswblank isblank
#define iswcntrl iscntrl
#define iswdigit isdigit
#define iswgraph isgraph
#define iswlower islower
#define iswprint isprint
#define iswpunct ispunct
#define iswspace isspace
#define iswupper isupper
#define iswxdigit isxdigit
#define TEXT(text) text
#define strdup strdup_flips
static inline char* strdup(const char * in)
{
size_t len=strlen(in);
char * ret=(char*)malloc(len+1);
memcpy(ret, in, len+1);
return ret;
}
#endif
#include "libbps.h"
#include "libips.h"
#include "libups.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "global.h"
enum patchtype {
ty_null,
ty_bps,
ty_ips,
ty_bps_linear,
ty_bps_moremem,
ty_ups,
ty_shut_up_gcc
};
enum errorlevel {
el_ok,
el_notice,
el_unlikelythis,
el_warning,
el_notthis,
el_broken,
el_shut_up_gcc
};
struct errorinfo {
enum errorlevel level;
const char * description;
};
struct manifestinfo {
bool use;
bool required;
LPCWSTR name;
};
class file;
class filewrite;
LPWSTR GetExtension(LPCWSTR fname);
LPWSTR GetBaseName(LPCWSTR fname);
bool shouldRemoveHeader(LPCWSTR romname, size_t romlen);
class config
{
LPWSTR filename;
size_t numentries;
LPWSTR * names;
LPWSTR * values;
void sort();
public:
config()
{
numentries = 0;
names = NULL;
values = NULL;
}
void init_file(LPCWSTR filename);
void init_raw(LPWSTR contents);
void set(LPCWSTR key, LPCWSTR value); LPCWSTR get(LPCWSTR key, LPCWSTR def = NULL);
void setint(LPCWSTR key, int value) { WCHAR valstr[16]; wsprintf(valstr, TEXT("%i"), value); set(key, valstr); }
int getint(LPCWSTR key, int def = 0) { LPCWSTR val = get(key); return val ? wtoi(val) : def; }
size_t getcount() { return numentries; }
LPCWSTR getnamebyid(size_t i) { return names[i]; }
LPCWSTR getvaluebyid(size_t i) { return values[i]; }
LPWSTR flatten(); ~config(); };
extern config cfg;
struct mem GetRomList();
void SetRomList(struct mem data);
LPCWSTR FindRomForPatch(file* patch, bool * possibleToFind);
void AddToRomList(file* patch, LPCWSTR path);
void AddConfigToRomList(LPCWSTR key, LPCWSTR value);
void DeleteRomFromList(LPCWSTR path);
LPCWSTR GetEmuFor(LPCWSTR filename); void SetEmuFor(LPCWSTR filename, LPCWSTR emu);
struct errorinfo ApplyPatchMem2(file* patch, struct mem inrom, bool removeheader, bool verifyinput,
LPCWSTR outromname, struct manifestinfo * manifestinfo);
struct errorinfo ApplyPatchMem(file* patch, LPCWSTR inromname, bool verifyinput,
LPCWSTR outromname, struct manifestinfo * manifestinfo, bool update_rom_list);
struct errorinfo ApplyPatch(LPCWSTR patchname, LPCWSTR inromname, bool verifyinput,
LPCWSTR outromname, struct manifestinfo * manifestinfo, bool update_rom_list);
struct errorinfo CreatePatchToMem(LPCWSTR inromname, LPCWSTR outromname, enum patchtype patchtype,
struct manifestinfo * manifestinfo, struct mem * patchmem);
struct errorinfo CreatePatch(LPCWSTR inromname, LPCWSTR outromname, enum patchtype patchtype,
struct manifestinfo * manifestinfo, LPCWSTR patchname);
extern char bpsdProgStr[24];
extern int bpsdLastPromille;
bool bpsdeltaGetProgress(size_t done, size_t total);
int flipsmain(int argc, WCHAR * argv[]);
void usage();
struct mem ReadWholeFile(LPCWSTR filename);
bool WriteWholeFile(LPCWSTR filename, struct mem data);
bool WriteWholeFileWithHeader(LPCWSTR filename, struct mem header, struct mem data);
void FreeFileMemory(struct mem mem);
void bpsdeltaBegin();
bool bpsdeltaProgress(void* userdata, size_t done, size_t total);
void bpsdeltaEnd();
int GUIShow(LPCWSTR filename);
void GUILoadConfig();
#ifdef FLIPS_WINDOWS
void GUIClaimConsole();
#else
#define GUIClaimConsole()
#endif