blob: 4ab8ec088dfd39e7ad590b3f947bd9ed841564ec (
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#include "Inventory.hpp"
#include "lib/math.h"
#include "global.h"
extern u32 *data_027e0ce0[];
#pragma thumb on
Inventory* Inventory::Create() {
gInventory = new(data_027e0ce0[1], 4) Inventory();
return gInventory;
}
void Inventory::Destroy() {
delete gInventory;
gInventory = 0;
}
#pragma interworking on
void Inventory::ClearPrevEquippedItem() {
this->mPrevEquippedItem = ItemFlag_None;
}
#pragma interworking off
NONMATCH void Inventory::Save(SaveInventory *save) {
#ifndef NONMATCHING
#include "../asm/ov00/inventory/Inventory_Save.inc"
#else
save->itemFlags = this->mItemFlags;
save->numRupees = this->mNumRupees;
for (s32 i = 0; i < NUM_POTIONS; ++i) {
save->potions[i] = this->mPotions[i];
}
save->numBombs = (u8) (*this->mAmmo)[ItemFlag_BombBag];
save->numBombchus = (u8) (*this->mAmmo)[ItemFlag_BombchuBag];
save->numArrows = (u8) (*this->mAmmo)[ItemFlag_Bow];
save->equippedItem = (u8) this->mEquippedItem;
save->salvagedTreasureFlags = this->mSalvagedTreasureFlags;
save->hourglassSeconds = FastDivide(this->mHourglassSandFrames, 60);
for (s32 i = 0; i < Gem_COUNT; ++i) {
save->numGems[i] = this->mNumGems[i];
}
u8 *saveEquippedParts = save->equippedShipParts;
const u32 *equippedParts = this->mEquippedShipParts;
s32 i = 0;
SaveInventory *save2 = save;
Inventory *this2 = this;
ShipParts (Inventory::*shipParts)[ShipPart_COUNT] = &Inventory::mShipParts;
for (; i < ShipPart_COUNT; ++i) {
save->equippedShipParts[i] = this->mEquippedShipParts[i];
for (s32 j = 0; j < ShipType_COUNT; ++j) {
u8 shipPartCount = ((Inventory*) ((u32)this2 + j)->*shipParts)[0].parts[0];
((SaveInventory*) ((u32)save2 + j))->shipParts[0].parts[0] = shipPartCount;
}
this2 = (Inventory*) ((u32)this2 + sizeof(this2->mShipParts[0]));
save2 = (SaveInventory*) ((u32)save2 + sizeof(save2->shipParts[0]));
}
save->shipPartPricesShown = this->mShipPartPricesShown;
for (s32 i = 0; i < Treasure_COUNT; ++i) {
save->treasure[i] = this->mTreasure[i];
}
save->treasurePriceShownFlags[0] = this->mTreasurePriceShownFlags[0];
for (s32 i = 0; i < 6; ++i) {
save->unk_9f[i] = this->mUnk_098[i];
save->unk_82[i] = this->mUnk_09e[i];
}
save->quiverSize = this->mQuiverSize;
save->bombBagSize = this->mBombBagSize;
save->bombchuBagSize = this->mBombchuBagSize;
if (this->mEquippedFairy == FairyId_None) {
save->equippedFairy = 3;
return;
}
save->equippedFairy = (u8) this->mEquippedFairy;
#endif
}
extern "C" bool _ZN9Inventory7HasItemEj();
NONMATCH void Inventory::Load(const SaveInventory *save) {
#ifndef NONMATCHING
#include "../asm/ov00/inventory/Inventory_Load.inc"
#else
this->mItemFlags = save->itemFlags;
this->mNumRupees = save->numRupees;
this->mHourglassSandFrames = save->hourglassSeconds <= MAX_HOURGLASS_SECONDS
? save->hourglassSeconds * 60
: MAX_HOURGLASS_SECONDS * 60;
for (s32 i = ItemFlag_EQUIP_START; i < ItemFlag_EQUIP_END; ++i) {
if (GET_FLAG(this->mItemFlags.flags, (u32) i)) {
(*this->mAmmo)[i] = 1;
}
}
(*this->mAmmo)[ItemFlag_BombBag] = save->numBombs;
(*this->mAmmo)[ItemFlag_BombchuBag] = save->numBombchus;
(*this->mAmmo)[ItemFlag_Bow] = save->numArrows;
for (s32 i = 0; i < NUM_POTIONS; ++i) {
this->mPotions[i] = save->potions[i];
}
this->mEquippedItem = save->equippedItem;
this->mSalvagedTreasureFlags = save->salvagedTreasureFlags;
for (s32 i = 0; i < Gem_COUNT; ++i) {
this->mNumGems[i] = save->numGems[i];
}
s32 i = 0; // ip (r0)
Inventory *this2 = this; // sp+0
const SaveInventory *save2 = save; // r3
Inventory *this3 = this; // r5
ShipParts (SaveInventory::*shipParts)[ShipPart_COUNT] = &SaveInventory::shipParts; // r7
do {
this2->mEquippedShipParts[0] = save->equippedShipParts[i];
for (s32 j = 0; j < ShipType_COUNT; ++j) {
u8 partCount = (((const SaveInventory*) ((u32)save2 + j))->*shipParts)[0].parts[0];
((Inventory*) ((u32)this3 + j))->mShipParts[0].parts[0] = partCount;
}
save2 = (const SaveInventory*) ((u32)save2 + sizeof(save->shipParts[0]));
this2 = (Inventory*) ((u32)this2 + sizeof(this->mEquippedShipParts[0]));
++i;
this3 = (Inventory*) ((u32)this3 + sizeof(this->mShipParts[0]));
}
while(i < ShipPart_COUNT);
this->mShipPartPricesShown = save->shipPartPricesShown;
for (s32 i = 0; i < Treasure_COUNT; ++i) {
this->mTreasure[i] = save->treasure[i];
}
this->mTreasurePriceShownFlags[0] = save->treasurePriceShownFlags[0];
for (s32 i = 0; i < 6; ++i) {
this->mUnk_098[i] = save->unk_9f[i];
this->mUnk_09e[i] = save->unk_82[i];
}
this->mQuiverSize = save->quiverSize;
this->mBombBagSize = save->bombBagSize;
this->mBombchuBagSize = save->bombchuBagSize;
this->mEquippedFairy = save->equippedFairy;
if (this->mEquippedFairy >= FairyId_COUNT) {
this->mEquippedFairy = FairyId_None;
}
if (this->mEquippedItem - 9 <= 1) {
if (this->HasItem(ItemFlag_Boomerang)) {
this->mEquippedItem = ItemFlag_Boomerang;
} else {
this->mEquippedItem = ItemFlag_None;
}
} else if (this->mEquippedItem == ItemFlag_None) {
if (this->HasItem(ItemFlag_Boomerang)) {
this->mEquippedItem = ItemFlag_Boomerang;
}
}
#endif
}
#pragma thumb off
|