-
Notifications
You must be signed in to change notification settings - Fork 46
/
global.h
72 lines (55 loc) · 1.63 KB
/
global.h
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
//Module name: Floating IPS, global header
//Author: Alcaro
//Date: See Git history
//Licence: GPL v3.0 or higher
#ifndef struct_mem
#define struct_mem
//the standard library can be assumed to exist
#include <stddef.h>//size_t, SIZE_MAX
#include <stdint.h>//uint8_t
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)-1)
#endif
struct mem {
uint8_t * ptr;
size_t len;
};
#if defined(FLIPS_WINDOWS)
#define LPCWSTR const wchar_t *
#else
#define LPCWSTR const char *
#endif
#ifdef __cplusplus
//used by both Flips core/GUI and the BPS creator
class file {
public:
static file* create(LPCWSTR filename);
static file* create_libc(const char * filename);
static bool exists(LPCWSTR filename);
static bool exists_libc(const char * filename);
virtual size_t len() = 0;
virtual bool read(uint8_t* target, size_t start, size_t len) = 0;
//these two add sizeof(WCHAR) 00s after the actual data, so you can cast it to LPCWSTR
static struct mem read(LPCWSTR filename); // provided by Flips core
struct mem read(); // provided by Flips core
virtual ~file() {}
};
class filemap {
public:
static filemap* create(LPCWSTR filename);
static filemap* create_fallback(LPCWSTR filename);
virtual size_t len() = 0;
virtual const uint8_t * ptr() = 0;
struct mem get() { struct mem m = { (uint8_t*)ptr(), len() }; return m; }
virtual ~filemap() {}
};
class filewrite {
public:
static filewrite* create(LPCWSTR filename);
static filewrite* create_libc(const char * filename);
virtual bool append(const uint8_t* data, size_t len) = 0;
static bool write(LPCWSTR filename, struct mem data); // provided by Flips core
virtual ~filewrite() {}
};
#endif
#endif