blob: be2896bf46840fa7ae0aa7b2eca925a4241c0a36 (
plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include "d/flag/flag_managers.h"
// clang-format off
#include "common.h"
#include "egg/core/eggHeap.h"
#include "m/m_heap.h"
// vtable order
#include "d/flag/flag_space.h"
#include "d/flag/tboxflag_manager.h"
#include "d/flag/enemyflag_manager.h"
#include "d/flag/storyflag_manager.h"
#include "d/flag/itemflag_manager.h"
// actual managers
#include "d/flag/sceneflag_manager.inc"
#include "d/flag/committable_flag_manager.inc"
#include "d/flag/tboxflag_manager.inc"
#include "d/flag/enemyflag_manager.inc"
#include "d/flag/flag_space.inc"
#include "d/flag/flag_index.inc"
#include "d/flag/bitwise_flag_helper.inc"
#include "d/flag/baseflag_manager.inc"
#include "d/flag/storyflag_manager.inc"
#include "d/flag/itemflag_manager.inc"
#include "d/flag/dungeonflag_manager.inc"
#include "d/flag/skipflag_manager.inc"
// clang-format on
static void postSetup();
template <typename T>
class MyFlagManager : public T {
public:
MyFlagManager<T>() {}
~MyFlagManager<T>() {}
};
void setupFlagManagers(EGG::Heap *heap) {
if (SceneflagManager::sInstance == nullptr) {
SceneflagManager::sInstance = new (heap) MyFlagManager<SceneflagManager>();
mHeap m(heap);
SceneflagManager::sInstance->init();
}
if (TBoxflagManager::sInstance == nullptr) {
TBoxflagManager::sInstance = new (heap) MyFlagManager<TBoxflagManager>();
mHeap m(heap);
TBoxflagManager::sInstance->init();
}
if (EnemyflagManager::sInstance == nullptr) {
EnemyflagManager::sInstance = new (heap) MyFlagManager<EnemyflagManager>();
mHeap m(heap);
EnemyflagManager::sInstance->init();
}
if (StoryflagManager::sInstance == nullptr) {
StoryflagManager::sInstance = new (heap) MyFlagManager<StoryflagManager>();
mHeap m(heap);
StoryflagManager::sInstance->init();
}
if (ItemflagManager::sInstance == nullptr) {
ItemflagManager::sInstance = new (heap) MyFlagManager<ItemflagManager>();
mHeap m(heap);
ItemflagManager::sInstance->init();
}
if (DungeonflagManager::sInstance == nullptr) {
DungeonflagManager::sInstance = new (heap) MyFlagManager<DungeonflagManager>();
mHeap m(heap);
DungeonflagManager::sInstance->init();
}
if (SkipflagManager::sInstance == nullptr) {
SkipflagManager::sInstance = new (heap) MyFlagManager<SkipflagManager>();
mHeap m(heap);
SkipflagManager::sInstance->init();
}
postSetup();
}
static void postSetup() {
updateFlagForFlagIndex(0);
}
void copyAllFlagManagersFromSave() {
u16 flag = FileManager::GetInstance()->getSceneFlagIndex();
SceneflagManager::sInstance->copyFromSave(flag);
TBoxflagManager::sInstance->copyFromSave(flag);
StoryflagManager::sInstance->copyFromSave();
ItemflagManager::sInstance->copyFromSave();
DungeonflagManager::sInstance->copyFromSave(flag);
SkipflagManager::sInstance->copyFromSave();
EnemyflagManager::sInstance->copyFromSave(flag);
}
void updateFlagForFlagIndex(u16 stage) {
SceneflagManager::sInstance->updateFlagindex(stage);
TBoxflagManager::sInstance->copyFromSave(stage);
EnemyflagManager::sInstance->updateFlagIndex(stage);
DungeonflagManager::sInstance->copyFromSave(stage);
}
void commitAllFlagManagers() {
StoryflagManager::sInstance->commit();
ItemflagManager::sInstance->commit();
DungeonflagManager::sInstance->commit();
SkipflagManager::sInstance->commit();
SceneflagManager::sInstance->commit();
TBoxflagManager::sInstance->commit();
EnemyflagManager::sInstance->commit();
}
bool checkedMemcpy(void *dest, u32 destLen, const void *src, u32 count) {
if (dest == nullptr || src == nullptr || destLen < count || destLen > 0xFFFF) {
return true;
} else {
memcpy(dest, src, count);
return false;
}
}
|