Skip to content

Commit 8580b8a

Browse files
See desc for more.
- Add Plot Twists / Points stuff for GBA. - Use memcpy() instead of reinterpret_cast.
1 parent 17af861 commit 8580b8a

9 files changed

Lines changed: 201 additions & 86 deletions

File tree

include/gba/GBACast.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ namespace S2Editor {
3737

3838
uint8_t Index() const { return this->Cast; };
3939

40+
/* Conversation Levels. */
4041
uint8_t Friendly() const;
4142
void Friendly(const uint8_t V);
42-
4343
uint8_t Romance() const;
4444
void Romance(const uint8_t V);
45-
4645
uint8_t Intimidate() const;
4746
void Intimidate(const uint8_t V);
4847

48+
/* Unlockables. */
4949
bool Alternativepic() const;
5050
void Alternativepic(const bool V);
51-
5251
bool Mystery() const;
5352
void Mystery(const bool V);
5453
private:

include/gba/GBAHouseItem.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ namespace S2Editor {
5656
uint8_t ID(const uint8_t Index) const;
5757
void ID(const uint8_t Index, const uint8_t V);
5858

59+
/* Flag and Use count. */
5960
uint8_t Flag(const uint8_t Index) const;
6061
void Flag(const uint8_t Index, const uint8_t V);
61-
6262
uint8_t UseCount(const uint8_t Index) const;
6363
void UseCount(const uint8_t Index, const uint8_t V);
6464

65+
/* Positions. */
6566
uint8_t XPos(const uint8_t Index) const;
6667
void XPos(const uint8_t Index, const uint8_t V);
67-
6868
uint8_t YPos(const uint8_t Index) const;
6969
void YPos(const uint8_t Index, const uint8_t V);
7070

7171
GBAHouseItemDirection Direction(const uint8_t Index) const;
7272
void Direction(const uint8_t Index, const GBAHouseItemDirection V);
7373

74-
/* Add and Removes. */
74+
/* Add and Remove. */
7575
bool AddItem(const uint8_t ID, const uint8_t Flag, const uint8_t UseCount, const uint8_t XPos, const uint8_t YPos, const GBAHouseItemDirection Direction);
7676
bool RemoveItem(const uint8_t Index);
7777
private:

include/gba/GBASettings.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ namespace S2Editor {
4444
public:
4545
GBASettings() { };
4646

47+
/* Volume Levels. */
4748
uint8_t SFX() const;
4849
void SFX(const uint8_t V);
49-
5050
uint8_t Music() const;
5151
void Music(const uint8_t V);
5252

include/gba/GBASlot.hpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,69 +39,53 @@ namespace S2Editor {
3939
public:
4040
GBASlot(const uint8_t Slot) : Slot(Slot), Offs(Slot * 0x1000) { };
4141

42+
/* Main things. */
4243
uint16_t Time() const;
4344
void Time(const uint16_t V);
44-
4545
uint32_t Simoleons() const;
4646
void Simoleons(const uint32_t V);
47-
4847
uint16_t Ratings() const;
4948
void Ratings(const uint16_t V);
50-
5149
std::string Name() const;
5250
void Name(const std::string &V);
5351

52+
/* Appearance. */
5453
uint8_t Hairstyle() const;
5554
void Hairstyle(const uint8_t V);
56-
5755
uint8_t Shirtcolor3() const;
5856
void Shirtcolor3(const uint8_t V);
59-
6057
uint8_t Tan() const;
6158
void Tan(const uint8_t V);
62-
6359
uint8_t Shirtcolor2() const;
6460
void Shirtcolor2(const uint8_t V);
65-
6661
uint8_t Haircolor() const;
6762
void Haircolor(const uint8_t V);
68-
6963
uint8_t Hatcolor() const;
7064
void Hatcolor(const uint8_t V);
71-
7265
uint8_t Shirt() const;
7366
void Shirt(const uint8_t V);
74-
7567
uint8_t Shirtcolor1() const;
7668
void Shirtcolor1(const uint8_t V);
77-
7869
uint8_t Pants() const;
7970
void Pants(const uint8_t V);
80-
8171
uint8_t Pantscolor() const;
8272
void Pantscolor(const uint8_t V);
8373

74+
/* Skill Points. */
8475
uint8_t Confidence() const;
8576
void Confidence(const uint8_t V);
86-
8777
uint8_t Mechanical() const;
8878
void Mechanical(const uint8_t V);
89-
9079
uint8_t Strength() const;
9180
void Strength(const uint8_t V);
92-
9381
uint8_t Personality() const;
9482
void Personality(const uint8_t V);
95-
9683
uint8_t Hotness() const;
9784
void Hotness(const uint8_t V);
98-
9985
uint8_t Intellect() const;
10086
void Intellect(const uint8_t V);
101-
10287
uint8_t Sanity() const;
10388
void Sanity(const uint8_t V);
104-
10589
uint8_t Aspiration() const;
10690
void Aspiration(const uint8_t V);
10791

@@ -111,34 +95,52 @@ namespace S2Editor {
11195
std::unique_ptr<GBAItem> Skills() const;
11296
std::unique_ptr<GBAItem> Mailbox() const;
11397
std::unique_ptr<GBAItem> Inventory() const;
98+
99+
/* House data. */
114100
std::unique_ptr<GBAHouse> House() const;
115101

102+
/* Collectables Amount. */
116103
uint8_t Cans() const;
117104
void Cans(const uint8_t V);
118-
uint8_t CansPrice() const;
119-
void CansPrice(const uint8_t V);
120-
121105
uint8_t Cowbells() const;
122106
void Cowbells(const uint8_t V);
123-
uint8_t CowbellsPrice() const;
124-
void CowbellsPrice(const uint8_t v);
125-
126107
uint8_t Spaceship() const;
127108
void Spaceship(const uint8_t V);
128-
uint8_t SpaceshipPrice() const;
129-
void SpaceshipPrice(const uint8_t V);
130-
131109
uint8_t Fuelrods() const;
132110
void Fuelrods(const uint8_t V);
111+
112+
/* Collectables Price. */
113+
uint8_t CansPrice() const;
114+
void CansPrice(const uint8_t V);
115+
uint8_t CowbellsPrice() const;
116+
void CowbellsPrice(const uint8_t v);
117+
uint8_t SpaceshipPrice() const;
118+
void SpaceshipPrice(const uint8_t V);
133119
uint8_t FuelrodsPrice() const;
134120
void FuelrodsPrice(const uint8_t V);
135121

122+
/* Episode stuff. */
136123
uint8_t CurrentEpisode() const;
137124
void CurrentEpisode(const uint8_t V, const bool ValidCheck = true);
138125

126+
/* Plot Points stuff. */
127+
bool MysteryPlot() const;
128+
void MysteryPlot(const bool V);
129+
bool FriendlyPlot() const;
130+
void FriendlyPlot(const bool V);
131+
bool RomanticPlot() const;
132+
void RomanticPlot(const bool V);
133+
bool IntimidatingPlot() const;
134+
void IntimidatingPlot(const bool V);
135+
bool TheChopperPlot() const;
136+
void TheChopperPlot(const bool V);
137+
bool WeirdnessPlot() const;
138+
void WeirdnessPlot(const bool V);
139+
140+
/* Some class pointers. */
139141
std::unique_ptr<GBAEpisode> Episode(const uint8_t EP) const;
140-
std::unique_ptr<GBACast> Cast(const uint8_t CST) const;
141142
std::unique_ptr<GBASocialMove> SocialMove(const uint8_t Move) const;
143+
std::unique_ptr<GBACast> Cast(const uint8_t CST) const;
142144

143145
bool FixChecksum();
144146
private:

include/nds/NDSSlot.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,31 @@ namespace S2Editor {
3434
public:
3535
NDSSlot(const uint8_t Slot) : Slot(Slot), Offs(Slot * 0x1000) { };
3636

37+
/* Main things. */
3738
uint32_t Simoleons() const;
3839
void Simoleons(const uint32_t V);
39-
4040
std::string Name() const;
4141
void Name(const std::string &V);
4242

43+
/* Collectables. */
4344
uint8_t Fuelrods() const;
4445
void Fuelrods(const uint8_t V);
45-
4646
uint8_t Plates() const;
4747
void Plates(const uint8_t V);
48-
4948
uint8_t Gourds() const;
5049
void Gourds(const uint8_t V);
51-
5250
uint8_t Spaceship() const;
5351
void Spaceship(const uint8_t V);
5452

53+
/* Skill Points. */
5554
uint8_t Creativity() const;
5655
void Creativity(const uint8_t V);
57-
5856
uint8_t Business() const;
5957
void Business(const uint8_t V);
60-
6158
uint8_t Body() const;
6259
void Body(const uint8_t V);
63-
6460
uint8_t Charisma() const;
6561
void Charisma(const uint8_t V);
66-
6762
uint8_t Mechanical() const;
6863
void Mechanical(const uint8_t V);
6964

include/shared/CoreCommon.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
#include <string>
3333

3434
namespace S2Editor {
35-
enum class SAVType {
36-
_GBA,
37-
_NDS,
38-
_NONE
39-
};
35+
enum class SAVType { _GBA, _NDS, _NONE };
4036
};
4137

4238
#endif

include/shared/SAVUtils.hpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "../gba/GBASav.hpp"
3131
#include "../nds/NDSSav.hpp"
32+
#include <cstring>
3233

3334
namespace S2Editor {
3435
/*
@@ -48,7 +49,11 @@ namespace S2Editor {
4849

4950
const std::string ReadString(const uint8_t *Buffer, const uint32_t Offset, const uint32_t Length);
5051
void WriteString(uint8_t *Buffer, const uint32_t Offset, const uint32_t Length, const std::string &Str);
51-
uint8_t ReadBits(const uint8_t *Buffer, const uint32_t Offs, const bool First);
52+
53+
/* BIT stuff. */
54+
const bool ReadBit(const uint8_t *Buffer, const uint32_t Offs, const uint8_t BitIndex);
55+
void WriteBit(uint8_t *Buffer, const uint32_t Offs, const uint8_t BitIndex, const bool IsSet);
56+
const uint8_t ReadBits(const uint8_t *Buffer, const uint32_t Offs, const bool First);
5257
void WriteBits(uint8_t *Buffer, const uint32_t Offs, const bool First, const uint8_t Data);
5358
};
5459

@@ -63,27 +68,36 @@ namespace S2Editor {
6368
const uint32_t Offs: The Offset from where to read.
6469
*/
6570
template <typename T>
66-
const T Read(const uint32_t Offs) {
71+
T Read(const uint32_t Offs) {
6772
if (!GBASAVUtils::SAV || !GBASAVUtils::SAV->GetValid()) return 0; // Return 0, if nullptr OR invalid.
6873

69-
return *reinterpret_cast<T *>(GBASAVUtils::SAV->GetData() + Offs);
74+
T Res = 0;
75+
memcpy(&Res, GBASAVUtils::SAV->GetData() + Offs, sizeof(T));
76+
return Res;
7077
};
7178

7279
/*
7380
Write to the SAVBuffer.
7481
7582
const uint32_t Offs: The Offset where to write to.
76-
const T Data: The data which to write.
83+
T Data: The data which to write.
7784
*/
7885
template <typename T>
79-
void Write(const uint32_t Offs, const T Data) {
86+
void Write(const uint32_t Offs, T Data) {
8087
if (!GBASAVUtils::SAV || !GBASAVUtils::SAV->GetValid()) return;
8188

82-
*reinterpret_cast<T *>(GBASAVUtils::SAV->GetData() + Offs) = Data;
89+
for (size_t Idx = 0; Idx < sizeof(T); Idx++) {
90+
GBASAVUtils::SAV->GetData()[Offs + Idx] = (uint8_t)Data;
91+
Data >>= 8; // Go to next byte.
92+
}
93+
8394
if (!GBASAVUtils::SAV->GetChangesMade()) GBASAVUtils::SAV->SetChangesMade(true);
8495
};
8596

86-
uint8_t ReadBits(const uint32_t Offs, const bool First = true);
97+
/* BIT stuff. */
98+
const bool ReadBit(const uint32_t Offs, const uint8_t BitIndex);
99+
void WriteBit(const uint32_t Offs, const uint8_t BitIndex, const bool IsSet);
100+
const uint8_t ReadBits(const uint32_t Offs, const bool First = true);
87101
void WriteBits(const uint32_t Offs, const bool First = true, const uint8_t Data = 0x0);
88102
};
89103

@@ -97,28 +111,36 @@ namespace S2Editor {
97111
const uint32_t Offs: The Offset from where to read.
98112
*/
99113
template <typename T>
100-
const T Read(const uint32_t Offs) {
114+
T Read(const uint32_t Offs) {
101115
if (!NDSSAVUtils::SAV || !NDSSAVUtils::SAV->GetValid()) return 0; // Return 0, if nullptr OR invalid.
102116

103-
return *reinterpret_cast<T *>(NDSSAVUtils::SAV->GetData() + Offs);
117+
T Res = 0;
118+
memcpy(&Res, NDSSAVUtils::SAV->GetData() + Offs, sizeof(T));
119+
return Res;
104120
};
105121

106122
/*
107123
Write to the SAVBuffer.
108124
109125
const uint32_t Offs: The Offset where to write to.
110-
const T Data: The data which to write.
126+
T Data: The data which to write.
111127
*/
112128
template <typename T>
113-
void Write(const uint32_t Offs, const T Data) {
129+
void Write(const uint32_t Offs, T Data) {
114130
if (!NDSSAVUtils::SAV || !NDSSAVUtils::SAV->GetValid()) return;
115131

116-
*reinterpret_cast<T *>(NDSSAVUtils::SAV->GetData() + Offs) = Data;
132+
for (size_t Idx = 0; Idx < sizeof(T); Idx++) {
133+
NDSSAVUtils::SAV->GetData()[Offs + Idx] = (uint8_t)Data;
134+
Data >>= 8; // Go to next byte.
135+
}
136+
117137
if (!NDSSAVUtils::SAV->GetChangesMade()) NDSSAVUtils::SAV->SetChangesMade(true);
118138
};
119139

120-
121-
uint8_t ReadBits(const uint32_t Offs, const bool First = true);
140+
/* BIT stuff. */
141+
const bool ReadBit(const uint32_t Offs, const uint8_t BitIndex);
142+
void WriteBit(const uint32_t Offs, const uint8_t BitIndex, const bool IsSet);
143+
const uint8_t ReadBits(const uint32_t Offs, const bool First = true);
122144
void WriteBits(const uint32_t Offs, const bool First = true, const uint8_t Data = 0x0);
123145
};
124146
};

0 commit comments

Comments
 (0)