Skip to content

Commit aa392fc

Browse files
WIP attempt at merging the Sav classes.
TODO: Likely style fixes, might do that later.
1 parent c5d5f9d commit aa392fc

21 files changed

+624
-1003
lines changed

include/gba/GBASav.hpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

include/nds/NDSSlot.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
namespace S2Editor {
3434
class NDSSlot {
3535
public:
36-
NDSSlot(const uint8_t Slot, const NDSSavRegion Reg)
37-
: Slot(Slot), Offs(Slot * 0x1000), Region(Reg) { };
36+
NDSSlot(const uint8_t Slot)
37+
: Slot(Slot), Offs(Slot * 0x1000) { };
3838

3939
/* Main things. */
4040
uint32_t Simoleons() const;
@@ -74,7 +74,6 @@ namespace S2Editor {
7474
private:
7575
uint8_t Slot = 0;
7676
uint32_t Offs = 0;
77-
NDSSavRegion Region = NDSSavRegion::Unknown;
7877
};
7978
};
8079

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,61 @@
2424
* reasonable ways as different from the original version.
2525
*/
2626

27-
#ifndef _SIM2EDITOR_CPP_CORE_NDS_SAV_HPP
28-
#define _SIM2EDITOR_CPP_CORE_NDS_SAV_HPP
27+
#ifndef _SIM2EDITOR_CPP_CORE_SAV_HPP
28+
#define _SIM2EDITOR_CPP_CORE_SAV_HPP
2929

30-
#include "NDSPainting.hpp"
31-
#include "NDSSlot.hpp"
30+
#include "CoreCommon.hpp"
31+
#include "../gba/GBASettings.hpp"
32+
#include "../gba/GBASlot.hpp"
33+
#include "../nds/NDSPainting.hpp"
34+
#include "../nds/NDSSlot.hpp"
3235

3336

3437
namespace S2Editor {
35-
class NDSSav {
38+
class SAV {
3639
public:
37-
NDSSav(const std::string &SavFile);
38-
NDSSav(std::unique_ptr<uint8_t[]> &Data, const uint32_t Size);
40+
SAV(const std::string &SavFile);
41+
SAV(std::unique_ptr<uint8_t[]> &Data, const uint32_t Size);
3942

4043
void ValidationCheck();
41-
int8_t FetchSlot(const uint8_t SavSlot, const uint8_t Reg);
42-
43-
/* Core Returns and Actions. */
44-
std::unique_ptr<NDSPainting> Painting(const uint8_t Idx) const;
45-
std::unique_ptr<NDSSlot> Slot(const uint8_t Slot) const;
46-
void Finish();
4744
bool SlotExist(const uint8_t Slot) const;
45+
void Finish();
46+
47+
/* GBA Core returns. */
48+
std::unique_ptr<GBASlot> _GBASlot(const uint8_t Slot) const;
49+
std::unique_ptr<GBASettings> _GBASettings() const;
50+
51+
/* NDS Core returns. */
52+
std::unique_ptr<NDSSlot> _NDSSlot(const uint8_t Slot) const;
53+
std::unique_ptr<NDSPainting> _NDSPainting(const uint8_t Idx) const;
4854

4955
/* Some Returns. */
5056
uint32_t GetSize() const { return this->SavSize; };
5157
uint8_t *GetData() const { return this->SavData.get(); };
58+
SavType GetType() const { return this->SType; };
5259
NDSSavRegion GetRegion() const { return this->Region; };
5360
bool GetValid() const { return this->SavValid; };
5461
bool GetChangesMade() const { return this->ChangesMade; };
5562
void SetChangesMade(const bool V) { this->ChangesMade = V; };
63+
std::string GetPath() const { return this->SavPath; };
5664
private:
65+
/* Some basic vars. */
5766
std::unique_ptr<uint8_t[]> SavData = nullptr;
5867
uint32_t SavSize = 0;
5968
bool SavValid = false, ChangesMade = false;
69+
std::string SavPath = "";
6070

61-
static constexpr uint8_t SlotIdent[8] = { 0x64, 0x61, 0x74, 0x0, 0x1F, 0x0, 0x0, 0x0 };
62-
int8_t Slots[3] = { -1, -1, -1 };
71+
/* Savtype & NDS Region. */
72+
SavType SType = SavType::_NONE;
6373
NDSSavRegion Region = NDSSavRegion::Unknown;
74+
75+
/* NDS only Related things. */
76+
int8_t NDSSlots[3] = { -1, -1, -1 };
77+
int8_t InitNDSSlotIdxs(const uint8_t SavSlot, const uint8_t Reg);
78+
79+
/* Identifiers to check for Savetypes. */
80+
static constexpr uint8_t GBAIdent[7] = { 0x53, 0x54, 0x57, 0x4E, 0x30, 0x32, 0x34 };
81+
static constexpr uint8_t NDSIdent[8] = { 0x64, 0x61, 0x74, 0x0, 0x1F, 0x0, 0x0, 0x0 };
6482
};
6583
};
6684

include/shared/SavUtils.hpp

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
#define _SIM2EDITOR_CPP_CORE_SAV_UTILS_HPP
2929

3030
#include "DataHelper.hpp"
31-
#include "../gba/GBASav.hpp"
32-
#include "../nds/NDSSav.hpp"
31+
#include "Sav.hpp"
3332

3433

3534
namespace S2Editor {
@@ -39,62 +38,14 @@ namespace S2Editor {
3938
Used for SavType Detection and various other common things.
4039
*/
4140
namespace SavUtils {
42-
extern SavType Sav; // Active SavType.
43-
extern std::string SavName;
41+
extern std::unique_ptr<SAV> Sav;
4442

45-
SavType DetectType(const std::string &File);
46-
SavType DetectType(const std::unique_ptr<uint8_t[]> &Data, const uint32_t Size);
4743
bool LoadSav(const std::string &File, const std::string &BasePath = "", const bool DoBackup = false);
4844
bool LoadSav(std::unique_ptr<uint8_t[]> &Data, const uint32_t Size, const std::string &BasePath = "", const bool DoBackup = false);
4945
bool CreateBackup(const std::string &BasePath);
5046
void Finish();
5147
bool ChangesMade();
52-
};
53-
54-
55-
/* SavUtils for GBA. */
56-
namespace GBASavUtils {
57-
extern std::unique_ptr<GBASav> Sav;
58-
59-
/*
60-
Read from the SavBuffer.
61-
62-
const uint32_t Offs: The Offset from where to read.
63-
*/
64-
template <typename T>
65-
T Read(const uint32_t Offs) {
66-
if (!GBASavUtils::Sav || !GBASavUtils::Sav->GetValid() || !GBASavUtils::Sav->GetData()) return 0;
67-
return DataHelper::Read<T>(GBASavUtils::Sav->GetData(), Offs);
68-
};
69-
70-
/*
71-
Write to the SavBuffer.
72-
73-
const uint32_t Offs: The Offset where to write to.
74-
T Data: The data which to write.
75-
*/
76-
template <typename T>
77-
void Write(const uint32_t Offs, T Data) {
78-
if (!GBASavUtils::Sav || !GBASavUtils::Sav->GetValid()) return;
79-
80-
if (DataHelper::Write<T>(GBASavUtils::Sav->GetData(), Offs, Data)) {
81-
if (!GBASavUtils::Sav->GetChangesMade()) GBASavUtils::Sav->SetChangesMade(true);
82-
}
83-
};
84-
85-
/* BIT stuff. */
86-
const bool ReadBit(const uint32_t Offs, const uint8_t BitIndex);
87-
void WriteBit(const uint32_t Offs, const uint8_t BitIndex, const bool IsSet);
88-
const uint8_t ReadBits(const uint32_t Offs, const bool First = true);
89-
void WriteBits(const uint32_t Offs, const bool First = true, const uint8_t Data = 0x0);
90-
91-
const std::string ReadString(const uint32_t Offs, const uint32_t Length);
92-
void WriteString(const uint32_t Offs, const uint32_t Length, const std::string &Str);
93-
};
9448

95-
/* SavUtils for NDS. */
96-
namespace NDSSavUtils {
97-
extern std::unique_ptr<NDSSav> Sav;
9849

9950
/*
10051
Read from the SavBuffer.
@@ -103,8 +54,8 @@ namespace S2Editor {
10354
*/
10455
template <typename T>
10556
T Read(const uint32_t Offs) {
106-
if (!NDSSavUtils::Sav || !NDSSavUtils::Sav->GetValid() || !NDSSavUtils::Sav->GetData()) return 0;
107-
return DataHelper::Read<T>(NDSSavUtils::Sav->GetData(), Offs);
57+
if (!SavUtils::Sav || !SavUtils::Sav->GetValid() || !SavUtils::Sav->GetData()) return 0;
58+
return DataHelper::Read<T>(SavUtils::Sav->GetData(), Offs);
10859
};
10960

11061
/*
@@ -115,10 +66,10 @@ namespace S2Editor {
11566
*/
11667
template <typename T>
11768
void Write(const uint32_t Offs, T Data) {
118-
if (!NDSSavUtils::Sav || !NDSSavUtils::Sav->GetValid()) return;
69+
if (!SavUtils::Sav || !SavUtils::Sav->GetValid()) return;
11970

120-
if (DataHelper::Write<T>(NDSSavUtils::Sav->GetData(), Offs, Data)) {
121-
if (!NDSSavUtils::Sav->GetChangesMade()) NDSSavUtils::Sav->SetChangesMade(true);
71+
if (DataHelper::Write<T>(SavUtils::Sav->GetData(), Offs, Data)) {
72+
if (!SavUtils::Sav->GetChangesMade()) SavUtils::Sav->SetChangesMade(true);
12273
}
12374
};
12475

source/gba/GBACast.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@
3030

3131
namespace S2Editor {
3232
/* Get and Set Friendly Conversation level. */
33-
uint8_t GBACast::Friendly() const { return GBASavUtils::Read<uint8_t>(this->Offs); };
34-
void GBACast::Friendly(const uint8_t V) { GBASavUtils::Write<uint8_t>(this->Offs, std::min<uint8_t>(3, V)); };
33+
uint8_t GBACast::Friendly() const { return SavUtils::Read<uint8_t>(this->Offs); };
34+
void GBACast::Friendly(const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs, std::min<uint8_t>(3, V)); };
3535

3636
/* Get and Set Romance Conversation level. */
37-
uint8_t GBACast::Romance() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x1); };
38-
void GBACast::Romance(const uint8_t V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x1, std::min<uint8_t>(3, V)); };
37+
uint8_t GBACast::Romance() const { return SavUtils::Read<uint8_t>(this->Offs + 0x1); };
38+
void GBACast::Romance(const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs + 0x1, std::min<uint8_t>(3, V)); };
3939

4040
/* Get and Set Intimidate Conversation level. */
41-
uint8_t GBACast::Intimidate() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x2); };
42-
void GBACast::Intimidate(const uint8_t V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x2, std::min<uint8_t>(3, V)); };
41+
uint8_t GBACast::Intimidate() const { return SavUtils::Read<uint8_t>(this->Offs + 0x2); };
42+
void GBACast::Intimidate(const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs + 0x2, std::min<uint8_t>(3, V)); };
4343

4444
/* Get and Set Cast Feeling. */
45-
GBACastFeeling GBACast::Feeling() const { return (GBACastFeeling)GBASavUtils::Read<uint8_t>(this->Offs + 0x3); };
46-
void GBACast::Feeling(const GBACastFeeling V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x3, (uint8_t)V); };
45+
GBACastFeeling GBACast::Feeling() const { return (GBACastFeeling)SavUtils::Read<uint8_t>(this->Offs + 0x3); };
46+
void GBACast::Feeling(const GBACastFeeling V) { SavUtils::Write<uint8_t>(this->Offs + 0x3, (uint8_t)V); };
4747

4848
/* Get and Set the hours how long the feeling lasts. */
49-
uint8_t GBACast::FeelingEffectHours() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x6); };
50-
void GBACast::FeelingEffectHours(const uint8_t V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x6, V); };
49+
uint8_t GBACast::FeelingEffectHours() const { return SavUtils::Read<uint8_t>(this->Offs + 0x6); };
50+
void GBACast::FeelingEffectHours(const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs + 0x6, V); };
5151

5252
/* Get and Set registered on phone state. */
53-
bool GBACast::RegisteredOnPhone() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x7); };
54-
void GBACast::RegisteredOnPhone(const bool V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x7, V); };
53+
bool GBACast::RegisteredOnPhone() const { return SavUtils::Read<uint8_t>(this->Offs + 0x7); };
54+
void GBACast::RegisteredOnPhone(const bool V) { SavUtils::Write<uint8_t>(this->Offs + 0x7, V); };
5555

5656
/* Get and Set Secret Unlock state. */
57-
bool GBACast::Secret() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x8); };
58-
void GBACast::Secret(const bool V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x8, V); };
57+
bool GBACast::Secret() const { return SavUtils::Read<uint8_t>(this->Offs + 0x8); };
58+
void GBACast::Secret(const bool V) { SavUtils::Write<uint8_t>(this->Offs + 0x8, V); };
5959
};

source/gba/GBAEpisode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
namespace S2Editor {
3232
/* Get and Set Episode Ratings. */
3333
uint8_t GBAEpisode::Rating(const uint8_t Category) const {
34-
return GBASavUtils::Read<uint8_t>(this->Offs + std::min<uint8_t>(3, Category));
34+
return SavUtils::Read<uint8_t>(this->Offs + std::min<uint8_t>(3, Category));
3535
};
3636
void GBAEpisode::Rating(const uint8_t Category, const uint8_t V) {
37-
GBASavUtils::Write<uint8_t>(this->Offs + std::min<uint8_t>(3, Category), std::min<uint8_t>(25, V));
37+
SavUtils::Write<uint8_t>(this->Offs + std::min<uint8_t>(3, Category), std::min<uint8_t>(25, V));
3838
};
3939

4040
/* Get and Set the Unlocked State. */
41-
bool GBAEpisode::State() const { return GBASavUtils::Read<uint8_t>(this->Offs + 0x4); };
42-
void GBAEpisode::State(const bool V) { GBASavUtils::Write<uint8_t>(this->Offs + 0x4, V); };
41+
bool GBAEpisode::State() const { return SavUtils::Read<uint8_t>(this->Offs + 0x4); };
42+
void GBAEpisode::State(const bool V) { SavUtils::Write<uint8_t>(this->Offs + 0x4, V); };
4343
};

source/gba/GBAHouse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace S2Editor {
3333
Get and Set the Room Design.
3434
Only 0 - 3 SHOULD be used at all, the others aren't actual room designs and instead may cause issues.
3535
*/
36-
uint8_t GBAHouse::Roomdesign() const { return GBASavUtils::ReadBits(this->Offs + 0x2E, true); };
37-
void GBAHouse::Roomdesign(const uint8_t V) { GBASavUtils::WriteBits(this->Offs + 0x2E, true, V); };
36+
uint8_t GBAHouse::Roomdesign() const { return SavUtils::ReadBits(this->Offs + 0x2E, true); };
37+
void GBAHouse::Roomdesign(const uint8_t V) { SavUtils::WriteBits(this->Offs + 0x2E, true, V); };
3838

3939
/* Get the Items of your House / Room. */
4040
std::unique_ptr<GBAHouseItem> GBAHouse::Items() const { return std::make_unique<GBAHouseItem>(this->Offs + 0xD6); };

0 commit comments

Comments
 (0)