-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCheatSearch_Dev.c
More file actions
78 lines (60 loc) · 1.67 KB
/
Copy pathCheatSearch_Dev.c
File metadata and controls
78 lines (60 loc) · 1.67 KB
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
73
74
75
76
77
78
#include <Windows.h>
#include "CheatSearch_Dev.h"
#define arr_growth 10
void CS_InitDev(CS_DEV *dev) {
dev->allocated = 0;
dev->codes = NULL;
dev->modify = NULL;
dev->num_stored = 0;
}
void CS_AddCode(CS_DEV *dev, CODEENTRY code) {
CODEENTRY *tmp;
// Reallocate memory if needed
if (dev->allocated == dev->num_stored) {
tmp = (CODEENTRY *)realloc(dev->codes, sizeof(*dev->codes) * (dev->allocated + arr_growth));
// Failure to allocate more memory
// Consider throwing an error here of some kind
if (tmp == NULL) {
CS_ClearDev(dev);
return;
}
dev->codes = tmp;
dev->allocated += arr_growth;
}
memcpy(&dev->codes[dev->num_stored], &code, sizeof(code));
dev->num_stored++;
}
// This is not a real deletion but simply a swap of pointers
// The item that was removed will be at the end of the list, ready to be replaced/updated
void CS_RemoveCodeAt(CS_DEV *dev, int location) {
int count;
// Cannot swap if there are less than 2 items
if ((dev->num_stored - location) >= 2) {
for (count = location; count < dev->num_stored - 1; count++) {
CS_SwapDev(dev, count, count + 1);
}
}
dev->num_stored--;
}
CODEENTRY* CS_GetCodeAt(CS_DEV *dev, int location) {
// Check if the location is in bounds
if (dev->num_stored == 0 || location < 0 || location > dev->num_stored - 1)
return NULL;
return &dev->codes[location];
}
void CS_ClearDev(CS_DEV *dev) {
if (dev->codes != NULL)
free(dev->codes);
CS_InitDev(dev);
}
void CS_SwapDev(CS_DEV *dev, int loc1, int loc2) {
CODEENTRY *one, *two;
CODEENTRY hold;
one = CS_GetCodeAt(dev, loc1);
two = CS_GetCodeAt(dev, loc2);
if (one != NULL && two != NULL) {
hold = *one;
*one = *two;
*two = hold;
}
}