forked from jackalstomper/AutomataSpeedrunMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChipManager.cpp
More file actions
40 lines (31 loc) · 1.1 KB
/
ChipManager.cpp
File metadata and controls
40 lines (31 loc) · 1.1 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
#include <cstring>
#include <algorithm>
#include "ChipManager.hpp"
namespace AutomataMod {
static_assert(sizeof(ChipManager::ChipSlot) == 48, "ChipSlot isn't 48 bytes in size! This breaks pointer reading logic with game memory!");
const int ChipManager::MAX_SLOT_COUNT = 300;
const uint32_t ChipManager::EMPTY_SLOT_ID = ~0;
const uint32_t ChipManager::WAUP_CHIP_ID = 3007;
const uint32_t ChipManager::RAUP_CHIP_ID = 3034;
const uint32_t ChipManager::TAUNT2_CHIP_ID = 3228;
ChipManager::Iterator ChipManager::begin()
{
return Iterator(_firstChip);
}
ChipManager::Iterator ChipManager::end()
{
return Iterator(_firstChip + MAX_SLOT_COUNT);
}
ChipManager::ChipManager(uint64_t chipTableRamStart) : _firstChip(reinterpret_cast<ChipSlot*>(chipTableRamStart))
{}
ChipManager::Iterator ChipManager::getChipSlotById(uint32_t chipId)
{
return std::find_if(begin(), end(), [chipId](const ChipSlot& i) { return i.id == chipId; });
}
void ChipManager::addChip(const ChipSlot& newChip)
{
Iterator slot = getChipSlotById(EMPTY_SLOT_ID);
if (slot != end())
*slot = newChip;
}
} // namespace AutomataMod