Skip to content

Commit 4111461

Browse files
See desc for more.
1.) The Movement Offset was related to the Items you have in your House. The Core should work properly now. 2.) Added GBAItem + GBAHouseItem class. 3.) Added Sanity.
1 parent 99d67cd commit 4111461

8 files changed

Lines changed: 372 additions & 45 deletions

File tree

include/gba/GBAEpisode.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,10 @@ class GBAEpisode {
4545
uint8_t Episode = 0;
4646
uint32_t Offs = 0;
4747

48-
static constexpr uint32_t EPOffs[11] = { 0x10A, 0x114, 0x128, 0x123, 0x137, 0x12D, 0x150, 0x146, 0x11E, 0x173, 0x16E }; // 11 Episodes.
48+
static constexpr uint32_t EPOffs[11] = { 0x104, 0x10E, 0x122, 0x11D, 0x131, 0x127, 0x14A, 0x140, 0x118, 0x16D, 0x168 }; // 11 Episodes.
4949

5050
/* Sets the base offset for the Episodes. */
51-
uint32_t SetOffset(const uint8_t Move) const {
52-
switch(Move) {
53-
case 1:
54-
return this->EPOffs[this->Episode];
55-
56-
case 2:
57-
return this->EPOffs[this->Episode] + 0x6;
58-
}
59-
60-
return this->EPOffs[this->Episode] - 0x6;
61-
};
51+
uint32_t SetOffset(const uint8_t Move) const { return this->EPOffs[this->Episode] + (Move * 0x6); };
6252
};
6353

6454
#endif

include/gba/GBAHouseItem.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* This file is part of Sim2Editor-CPPCore
3+
* Copyright (C) 2020-2021 SuperSaiyajinStackZ, Universal-Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
19+
* * Requiring preservation of specified reasonable legal notices or
20+
* author attributions in that material or in the Appropriate Legal
21+
* Notices displayed by works containing it.
22+
* * Prohibiting misrepresentation of the origin of that material,
23+
* or requiring that modified versions of such material be marked in
24+
* reasonable ways as different from the original version.
25+
*/
26+
27+
#ifndef _SIM2EDITOR_CPP_CORE_GBA_HOUSE_ITEM_HPP
28+
#define _SIM2EDITOR_CPP_CORE_GBA_HOUSE_ITEM_HPP
29+
30+
#include "CoreCommon.hpp"
31+
32+
enum class GBAHouseItemDirection : uint8_t {
33+
Right = 0x1,
34+
Down = 0x3,
35+
Left = 0x5,
36+
Up = 0x7,
37+
Invalid = 0xFF
38+
};
39+
40+
class GBAHouseItem {
41+
public:
42+
GBAHouseItem(const uint32_t Offset) : Offs(Offset) { };
43+
44+
uint8_t Count() const;
45+
void Count(const uint8_t V);
46+
47+
uint8_t ID(const uint8_t Index) const;
48+
void ID(const uint8_t Index, const uint8_t V);
49+
50+
uint8_t Flag(const uint8_t Index) const;
51+
void Flag(const uint8_t Index, const uint8_t V);
52+
53+
uint8_t UseCount(const uint8_t Index) const;
54+
void UseCount(const uint8_t Index, const uint8_t V);
55+
56+
uint8_t XPos(const uint8_t Index) const;
57+
void XPos(const uint8_t Index, const uint8_t V);
58+
59+
uint8_t YPos(const uint8_t Index) const;
60+
void YPos(const uint8_t Index, const uint8_t V);
61+
62+
GBAHouseItemDirection Direction(const uint8_t Index) const;
63+
void Direction(const uint8_t Index, const GBAHouseItemDirection V);
64+
65+
/* Add and Removes. */
66+
void AddItem(const uint8_t ID, const uint8_t Flag, const uint8_t UseCount, const uint8_t XPos, const uint8_t YPos, const GBAHouseItemDirection Direction);
67+
void RemoveItem(const uint8_t Index);
68+
private:
69+
uint32_t Offs = 0;
70+
};
71+
72+
#endif

include/gba/GBAItem.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of Sim2Editor-CPPCore
3+
* Copyright (C) 2020-2021 SuperSaiyajinStackZ, Universal-Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
19+
* * Requiring preservation of specified reasonable legal notices or
20+
* author attributions in that material or in the Appropriate Legal
21+
* Notices displayed by works containing it.
22+
* * Prohibiting misrepresentation of the origin of that material,
23+
* or requiring that modified versions of such material be marked in
24+
* reasonable ways as different from the original version.
25+
*/
26+
27+
#ifndef _SIM2EDITOR_CPP_CORE_GBA_ITEM_HPP
28+
#define _SIM2EDITOR_CPP_CORE_GBA_ITEM_HPP
29+
30+
#include "CoreCommon.hpp"
31+
32+
class GBAItem {
33+
public:
34+
GBAItem(const uint32_t Offset) : Offs(Offset) { };
35+
36+
uint8_t Count() const;
37+
void Count(const uint8_t V);
38+
39+
uint8_t ID(const uint8_t Index) const;
40+
void ID(const uint8_t Index, const uint8_t V);
41+
private:
42+
uint32_t Offs = 0;
43+
};
44+
45+
#endif

include/gba/GBASlot.hpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "CoreCommon.hpp"
3131
#include "GBACast.hpp"
3232
#include "GBAEpisode.hpp"
33+
#include "GBAHouseItem.hpp"
34+
#include "GBAItem.hpp"
3335
#include "GBASocialMove.hpp"
3436

3537
class GBASlot {
@@ -66,6 +68,17 @@ class GBASlot {
6668
uint8_t Intellect() const;
6769
void Intellect(const uint8_t V);
6870

71+
uint8_t Sanity() const;
72+
void Sanity(const uint8_t V);
73+
74+
/* Items. */
75+
std::unique_ptr<GBAItem> PawnShop() const;
76+
std::unique_ptr<GBAItem> Saloon() const;
77+
std::unique_ptr<GBAItem> Skills() const;
78+
std::unique_ptr<GBAItem> Mailbox() const;
79+
std::unique_ptr<GBAItem> Inventory() const;
80+
std::unique_ptr<GBAHouseItem> House() const;
81+
6982
uint8_t Cans() const;
7083
void Cans(const uint8_t V);
7184
uint8_t CansPrice() const;
@@ -99,18 +112,8 @@ class GBASlot {
99112
uint8_t Slot = 0;
100113
uint32_t Offs = 0;
101114

102-
/* The Sims 2 GBA is annoying and their movement crap, so this is necessary. */
103-
uint32_t Offset(const uint32_t DefaultOffs = 0x0, const uint32_t MoveOffs1 = 0x0, const uint32_t MoveOffs2 = 0x0) const {
104-
switch(this->Move) {
105-
case 1:
106-
return this->Offs + MoveOffs1;
107-
108-
case 2:
109-
return this->Offs + MoveOffs2;
110-
}
111-
112-
return this->Offs + DefaultOffs;
113-
};
115+
/* The House Item Amount seems to affect some stuff and move things around for 0x6 per Item. */
116+
uint32_t Offset(const uint32_t DefaultOffs = 0x0) const { return this->Offs + DefaultOffs + (this->Move * 0x6); };
114117

115118
/* This contains all official Episode Values found at offset (Slot * 0x1000) + 0x1A9. */
116119
static constexpr uint8_t EPVals[12] = {

source/gba/GBAHouseItem.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* This file is part of Sim2Editor-CPPCore
3+
* Copyright (C) 2020-2021 SuperSaiyajinStackZ, Universal-Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
19+
* * Requiring preservation of specified reasonable legal notices or
20+
* author attributions in that material or in the Appropriate Legal
21+
* Notices displayed by works containing it.
22+
* * Prohibiting misrepresentation of the origin of that material,
23+
* or requiring that modified versions of such material be marked in
24+
* reasonable ways as different from the original version.
25+
*/
26+
27+
#include "GBAHouseItem.hpp"
28+
#include "../shared/SAVUtils.hpp"
29+
#include <cstring>
30+
31+
/* Get and Set the Item Count. */
32+
uint8_t GBAHouseItem::Count() const { return GBASAVUtils::Read<uint8_t>(this->Offs); };
33+
void GBAHouseItem::Count(const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs, V); };
34+
35+
/* Get and Set the Item ID. */
36+
uint8_t GBAHouseItem::ID(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(this->Count(), Index) * 0x6)); };
37+
void GBAHouseItem::ID(const uint8_t Index, const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(this->Count(), Index) * 0x6), V); };
38+
39+
/* Get and Set the Item Flag. */
40+
uint8_t GBAHouseItem::Flag(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x2 + (std::min<uint8_t>(this->Count(), Index) * 0x6)); };
41+
void GBAHouseItem::Flag(const uint8_t Index, const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs + 0x2 + (std::min<uint8_t>(this->Count(), Index) * 0x6), V); };
42+
43+
/* Get and Set the Use Count(?). */
44+
uint8_t GBAHouseItem::UseCount(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x3 + (std::min<uint8_t>(this->Count(), Index) * 0x6)); };
45+
void GBAHouseItem::UseCount(const uint8_t Index, const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs + 0x3 + (std::min<uint8_t>(this->Count(), Index) * 0x6), V); };
46+
47+
/* Get and Set the X Position of the Item. */
48+
uint8_t GBAHouseItem::XPos(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x4 + (std::min<uint8_t>(this->Count(), Index) * 0x6)); };
49+
void GBAHouseItem::XPos(const uint8_t Index, const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs + 0x4 + (std::min<uint8_t>(this->Count(), Index) * 0x6), V); };
50+
51+
/* Get and Set the Y Position of the Item. */
52+
uint8_t GBAHouseItem::YPos(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x5 + (std::min<uint8_t>(this->Count(), Index) * 0x6)); };
53+
void GBAHouseItem::YPos(const uint8_t Index, const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs + 0x5 + (std::min<uint8_t>(this->Count(), Index) * 0x6), V); };
54+
55+
/* Get and Set the Item Direction. */
56+
GBAHouseItemDirection GBAHouseItem::Direction(const uint8_t Index) const {
57+
const uint8_t D = GBASAVUtils::Read<uint8_t>(this->Offs + 0x6 + (std::min<uint8_t>(this->Count(), Index)) * 0x6);
58+
59+
switch(D) {
60+
case 0x1:
61+
return GBAHouseItemDirection::Right;
62+
63+
case 0x3:
64+
return GBAHouseItemDirection::Down;
65+
66+
case 0x5:
67+
return GBAHouseItemDirection::Left;
68+
69+
case 0x7:
70+
return GBAHouseItemDirection::Up;
71+
}
72+
73+
return GBAHouseItemDirection::Invalid;
74+
};
75+
void GBAHouseItem::Direction(const uint8_t Index, const GBAHouseItemDirection V) {
76+
switch(V) {
77+
case GBAHouseItemDirection::Right:
78+
GBASAVUtils::Write<uint8_t>(this->Offs + 0x6 + (std::min<uint8_t>(this->Count(), Index)) * 0x6, 0x1);
79+
break;
80+
81+
case GBAHouseItemDirection::Down:
82+
GBASAVUtils::Write<uint8_t>(this->Offs + 0x6 + (std::min<uint8_t>(this->Count(), Index)) * 0x6, 0x3);
83+
break;
84+
85+
case GBAHouseItemDirection::Left:
86+
GBASAVUtils::Write<uint8_t>(this->Offs + 0x6 + (std::min<uint8_t>(this->Count(), Index)) * 0x6, 0x5);
87+
break;
88+
89+
case GBAHouseItemDirection::Up:
90+
GBASAVUtils::Write<uint8_t>(this->Offs + 0x6 + (std::min<uint8_t>(this->Count(), Index)) * 0x6, 0x7);
91+
break;
92+
93+
case GBAHouseItemDirection::Invalid:
94+
break;
95+
}
96+
};
97+
98+
/*
99+
Add an Item to the House.
100+
This needs to be handled like this, because things move 0x6 bytes up when an Item is being added.
101+
*/
102+
void GBAHouseItem::AddItem(const uint8_t ID, const uint8_t Flag, const uint8_t UseCount, const uint8_t XPos, const uint8_t YPos, const GBAHouseItemDirection Direction) {
103+
if (this->Count() == 0xC) return; // Not allowed to add more than 0xC / 12 Items.
104+
105+
const uint8_t CT = this->Count();
106+
this->Count(CT + 0x1);
107+
108+
std::unique_ptr<uint8_t[]> TMP = std::make_unique<uint8_t[]>(0xF26 - (this->Count() * 6));
109+
memcpy( // Copy first to a TMP pointer.
110+
TMP.get(),
111+
GBASAVUtils::SAV->GetData() + (this->Offs + 0x1) + (CT * 0x6),
112+
0xF26 - (this->Count() * 6)
113+
);
114+
115+
memcpy( // Then copy to the actual location from the TMP pointer.
116+
GBASAVUtils::SAV->GetData() + (this->Offs + 0x1) + (this->Count() * 0x6),
117+
TMP.get(),
118+
0xF26 - (this->Count() * 6)
119+
);
120+
121+
/* Set Item Data. */
122+
this->ID(CT, ID);
123+
this->Flag(CT, Flag);
124+
this->UseCount(CT, UseCount);
125+
this->XPos(CT, XPos);
126+
this->YPos(CT, YPos);
127+
this->Direction(CT, Direction);
128+
};
129+
130+
/*
131+
Remove an Item from the House.
132+
This needs to be handled like this, because things move 0x6 bytes down when an Item is being removed.
133+
*/
134+
void GBAHouseItem::RemoveItem(const uint8_t Index) {
135+
if ((this->Count() == 0) || (this->Count() - 1 < Index)) return; // Nanana, Index and or Count is not good.
136+
137+
const uint8_t CT = this->Count();
138+
this->Count(this->Count() - 0x1);
139+
140+
std::unique_ptr<uint8_t[]> TMP = std::make_unique<uint8_t[]>(0xF26 - (this->Count() * 6));
141+
memcpy( // Copy first to a TMP pointer.
142+
TMP.get(),
143+
GBASAVUtils::SAV->GetData() + (this->Offs + 0x1) + ((Index + 0x1) * 0x6),
144+
0xF26 - (this->Count() * 6)
145+
);
146+
147+
memcpy( // Then copy to the actual location from the TMP pointer.
148+
GBASAVUtils::SAV->GetData() + (this->Offs + 0x1) + (Index * 0x6),
149+
TMP.get(),
150+
0xF26 - (this->Count() * 6)
151+
);
152+
};

source/gba/GBAItem.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of Sim2Editor-CPPCore
3+
* Copyright (C) 2020-2021 SuperSaiyajinStackZ, Universal-Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
19+
* * Requiring preservation of specified reasonable legal notices or
20+
* author attributions in that material or in the Appropriate Legal
21+
* Notices displayed by works containing it.
22+
* * Prohibiting misrepresentation of the origin of that material,
23+
* or requiring that modified versions of such material be marked in
24+
* reasonable ways as different from the original version.
25+
*/
26+
27+
#include "GBAItem.hpp"
28+
#include "../shared/SAVUtils.hpp"
29+
30+
/* Get and Set the Item Count. */
31+
uint8_t GBAItem::Count() const { return GBASAVUtils::Read<uint8_t>(this->Offs); };
32+
void GBAItem::Count(const uint8_t V) { GBASAVUtils::Write<uint8_t>(this->Offs, V); };
33+
34+
/* Get and Set the Item's ID. */
35+
uint8_t GBAItem::ID(const uint8_t Index) const { return GBASAVUtils::Read<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(5, Index) * 0x3)); };
36+
void GBAItem::ID(const uint8_t Index, const uint8_t V) {
37+
GBASAVUtils::Write<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(5, Index) * 0x3), V);
38+
39+
/* Update Item Count. */
40+
uint8_t Amount = 0;
41+
for (uint8_t Idx = 0; Idx < 6; Idx++) {
42+
if (this->ID(Idx) != 0xE6) Amount++; // If not 0xE6 (Empty Item), increase count.
43+
}
44+
45+
if (this->Count() != Amount) this->Count(Amount);
46+
};

0 commit comments

Comments
 (0)