Skip to content

Commit f7dc19d

Browse files
This should be good now, i hope.
1 parent aa392fc commit f7dc19d

13 files changed

Lines changed: 65 additions & 51 deletions

File tree

include/nds/NDSPainting.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#ifndef _SIM2EDITOR_CPP_CORE_NDS_PAINTING_HPP
2828
#define _SIM2EDITOR_CPP_CORE_NDS_PAINTING_HPP
2929

30-
#include "CoreCommon.hpp"
30+
#include "../shared/CoreCommon.hpp"
3131

3232

3333
namespace S2Editor {

include/nds/NDSSlot.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#ifndef _SIM2EDITOR_CPP_CORE_NDS_SLOT_HPP
2828
#define _SIM2EDITOR_CPP_CORE_NDS_SLOT_HPP
2929

30-
#include "CoreCommon.hpp"
30+
#include "../shared/CoreCommon.hpp"
3131

3232

3333
namespace S2Editor {

include/shared/CoreCommon.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#ifndef _SIM2EDITOR_CPP_CORE_COMMON_HPP
2828
#define _SIM2EDITOR_CPP_CORE_COMMON_HPP
2929

30-
#include <cstring>
31-
#include <math.h>
32-
#include <memory>
33-
#include <string>
30+
#include <cstring> // std::memcpy.
31+
#include <math.h> // std::min and std::max.
32+
#include <memory> // std::unique_ptr.
33+
#include <string> // Base include.
3434

3535

3636
namespace S2Editor {

include/shared/Sav.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace S2Editor {
4242

4343
void ValidationCheck();
4444
bool SlotExist(const uint8_t Slot) const;
45+
void SetChangesMade(const bool V) { this->ChangesMade = V; };
4546
void Finish();
4647

4748
/* GBA Core returns. */
@@ -52,15 +53,16 @@ namespace S2Editor {
5253
std::unique_ptr<NDSSlot> _NDSSlot(const uint8_t Slot) const;
5354
std::unique_ptr<NDSPainting> _NDSPainting(const uint8_t Idx) const;
5455

55-
/* Some Returns. */
56+
/* Some basic returns. */
5657
uint32_t GetSize() const { return this->SavSize; };
5758
uint8_t *GetData() const { return this->SavData.get(); };
5859
SavType GetType() const { return this->SType; };
59-
NDSSavRegion GetRegion() const { return this->Region; };
60-
bool GetValid() const { return this->SavValid; };
6160
bool GetChangesMade() const { return this->ChangesMade; };
62-
void SetChangesMade(const bool V) { this->ChangesMade = V; };
61+
bool GetValid() const { return this->SavValid; };
6362
std::string GetPath() const { return this->SavPath; };
63+
64+
/* NDS returns. */
65+
NDSSavRegion GetRegion() const { return this->Region; };
6466
private:
6567
/* Some basic vars. */
6668
std::unique_ptr<uint8_t[]> SavData = nullptr;
@@ -77,8 +79,8 @@ namespace S2Editor {
7779
int8_t InitNDSSlotIdxs(const uint8_t SavSlot, const uint8_t Reg);
7880

7981
/* 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 };
82+
static constexpr uint8_t GBAIdent[0x7] = { 0x53, 0x54, 0x57, 0x4E, 0x30, 0x32, 0x34 };
83+
static constexpr uint8_t NDSIdent[0x8] = { 0x64, 0x61, 0x74, 0x0, 0x1F, 0x0, 0x0, 0x0 };
8284
};
8385
};
8486

include/shared/SavUtils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ namespace S2Editor {
4040
namespace SavUtils {
4141
extern std::unique_ptr<SAV> Sav;
4242

43-
bool LoadSav(const std::string &File, const std::string &BasePath = "", const bool DoBackup = false);
44-
bool LoadSav(std::unique_ptr<uint8_t[]> &Data, const uint32_t Size, const std::string &BasePath = "", const bool DoBackup = false);
43+
SavType LoadSav(const std::string &File, const std::string &BasePath = "", const bool DoBackup = false);
44+
SavType LoadSav(std::unique_ptr<uint8_t[]> &Data, const uint32_t Size, const std::string &BasePath = "", const bool DoBackup = false);
4545
bool CreateBackup(const std::string &BasePath);
46-
void Finish();
46+
void Finish(const bool Reset = true);
4747
bool ChangesMade();
4848

4949

source/gba/GBAEpisode.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030

3131
namespace S2Editor {
3232
/* Get and Set Episode Ratings. */
33-
uint8_t GBAEpisode::Rating(const uint8_t Category) const {
34-
return SavUtils::Read<uint8_t>(this->Offs + std::min<uint8_t>(3, Category));
35-
};
36-
void GBAEpisode::Rating(const uint8_t Category, const uint8_t V) {
37-
SavUtils::Write<uint8_t>(this->Offs + std::min<uint8_t>(3, Category), std::min<uint8_t>(25, V));
38-
};
33+
uint8_t GBAEpisode::Rating(const uint8_t Category) const { return SavUtils::Read<uint8_t>(this->Offs + std::min<uint8_t>(3, Category)); };
34+
void GBAEpisode::Rating(const uint8_t Category, const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs + std::min<uint8_t>(3, Category), std::min<uint8_t>(25, V)); };
3935

4036
/* Get and Set the Unlocked State. */
4137
bool GBAEpisode::State() const { return SavUtils::Read<uint8_t>(this->Offs + 0x4); };

source/gba/GBAItem.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ namespace S2Editor {
3434
void GBAItem::Count(const uint8_t V) { SavUtils::Write<uint8_t>(this->Offs, V); };
3535

3636
/* Get and Set the Item's ID. */
37-
uint8_t GBAItem::ID(const uint8_t Index) const {
38-
return SavUtils::Read<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(5, Index) * 0x3));
39-
};
37+
uint8_t GBAItem::ID(const uint8_t Index) const { return SavUtils::Read<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(5, Index) * 0x3)); };
4038
void GBAItem::ID(const uint8_t Index, const uint8_t V) {
4139
SavUtils::Write<uint8_t>(this->Offs + 0x1 + (std::min<uint8_t>(5, Index) * 0x3), V);
4240

source/gba/GBASettings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,22 @@ namespace S2Editor {
3434
uint8_t GBASettings::SFX() const { return SavUtils::Read<uint8_t>(0x8); };
3535
void GBASettings::SFX(const uint8_t V) {
3636
if (V > 10) return; // 0 - 10 only valid.
37+
3738
SavUtils::Write<uint8_t>(0x8, this->SFXLevels[V]);
3839
};
3940

4041
/* Get and Set the Music Volume. */
4142
uint8_t GBASettings::Music() const { return SavUtils::Read<uint8_t>(0x9); };
4243
void GBASettings::Music(const uint8_t V) {
4344
if (V > 10) return; // 0 - 10 only valid.
45+
4446
SavUtils::Write<uint8_t>(0x9, this->MusicLevels[V]);
4547
};
4648

4749
/* Get and Set the Language. */
4850
GBALanguage GBASettings::Language() const {
4951
if (SavUtils::Read<uint8_t>(0xA) > 5) return GBALanguage::EN; // Technically, that would be a "blank" Language in game, but ehh that's not good.
52+
5053
return (GBALanguage)SavUtils::Read<uint8_t>(0xA);
5154
};
5255
void GBASettings::Language(const GBALanguage V) { SavUtils::Write<uint8_t>(0xA, (uint8_t)V); };

source/gba/GBASlot.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ namespace S2Editor {
3636
3737
const uint32_t DefaultOffs: The Default Offset, for things without an Item in your house.
3838
*/
39-
uint32_t GBASlot::Offset(const uint32_t DefaultOffs) const {
40-
return (this->Offs + DefaultOffs) + (SavUtils::Read<uint8_t>(this->Offs + 0xD6) * 0x6);
41-
};
39+
uint32_t GBASlot::Offset(const uint32_t DefaultOffs) const { return (this->Offs + DefaultOffs) + (SavUtils::Read<uint8_t>(this->Offs + 0xD6) * 0x6); };
4240

4341

4442
/* Get and Set Time. */
@@ -205,7 +203,7 @@ namespace S2Editor {
205203
if (SavUtils::Read<uint8_t>(this->Offset(0x1A3)) == this->EPVals[Idx]) return Idx;
206204
}
207205

208-
return 12; // 12 -> "Unofficial Episode". ;P
206+
return 12; // 12 -> "Unofficial Episode".
209207
};
210208

211209
/*
@@ -230,7 +228,7 @@ namespace S2Editor {
230228
}
231229
};
232230

233-
/* Get a Minigame class. */
231+
/* Return a Minigame class Pointer. */
234232
std::unique_ptr<GBAMinigame> GBASlot::Minigame(const uint8_t Game) {
235233
return std::make_unique<GBAMinigame>(this->Offset(0x1AD), Game);
236234
};
@@ -263,17 +261,17 @@ namespace S2Editor {
263261
uint8_t GBASlot::TheChopperColor() const { return SavUtils::ReadBits(this->Offset(0x1F2), true); };
264262
void GBASlot::TheChopperColor(const uint8_t V) { SavUtils::WriteBits(this->Offset(0x1F2), true, std::min<uint8_t>(9, V)); };
265263

266-
/* Get an Episode class. */
264+
/* Return an Episode class Pointer. */
267265
std::unique_ptr<GBAEpisode> GBASlot::Episode(const uint8_t EP) const {
268266
return std::make_unique<GBAEpisode>(this->Slot, EP, SavUtils::Read<uint8_t>(this->Offs + 0xD6));
269267
};
270268

271-
/* Get a Social Move class. */
269+
/* Return a Social Move class Pointer. */
272270
std::unique_ptr<GBASocialMove> GBASlot::SocialMove(const uint8_t Move) const {
273271
return std::make_unique<GBASocialMove>(this->Offset(0x3EE) + (std::min<uint8_t>(14, Move)) * 0x8, Move);
274272
};
275273

276-
/* Get a Cast class. */
274+
/* Return a Cast class Pointer. */
277275
std::unique_ptr<GBACast> GBASlot::Cast(const uint8_t CST) const {
278276
return std::make_unique<GBACast>(this->Offset(0x466) + (std::min<uint8_t>(25, CST)) * 0xA, CST);
279277
};

source/nds/NDSPainting.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ namespace S2Editor {
8888

8989
/* Get the Rank name of the Painting. */
9090
std::string NDSPainting::RankName() const {
91-
if (this->Flag() >= 0x29) return S2Editor::Strings::NDSPaintingRankNames_EN[0]; // 0x29+ is out of scope. Only range 0x0 - 0x28 is valid.
91+
if (this->Flag() >= 0x29) return Strings::NDSPaintingRankNames_EN[0]; // 0x29+ is out of scope. Only range 0x0 - 0x28 is valid.
9292

9393
const uint8_t Category = 1 + (this->Flag() / 8);
94-
return (this->Flag() % 2 == 0 ? S2Editor::Strings::NDSPaintingRankNames_EN[0] : S2Editor::Strings::NDSPaintingRankNames_EN[std::min<uint8_t>(5, Category)]);
94+
return (this->Flag() % 2 == 0 ? Strings::NDSPaintingRankNames_EN[0] : Strings::NDSPaintingRankNames_EN[std::min<uint8_t>(5, Category)]);
9595
};
9696

9797
/* Update the Checksum of the Painting. */
9898
void NDSPainting::UpdateChecksum() {
9999
/* First: Main. */
100-
uint16_t Calced = S2Editor::Checksum::Calc(SavUtils::Sav->GetData(), (this->Offs + 0x10) / 2, (this->Offs + 0x400) / 2, { (this->Offs + 0x10) / 2 });
100+
uint16_t Calced = Checksum::Calc(SavUtils::Sav->GetData(), (this->Offs + 0x10) / 2, (this->Offs + 0x400) / 2, { (this->Offs + 0x10) / 2 });
101101
uint16_t CurCHKS = SavUtils::Read<uint16_t>(this->Offs + 0x10);
102102
if (CurCHKS != Calced) SavUtils::Write<uint16_t>(this->Offs + 0x10, Calced);
103103

104104
/* Then: Header. */
105-
Calced = S2Editor::Checksum::Calc(SavUtils::Sav->GetData(), (this->Offs) / 2, (this->Offs + 0x13) / 2, { (this->Offs + 0xE) / 2 });
105+
Calced = Checksum::Calc(SavUtils::Sav->GetData(), (this->Offs) / 2, (this->Offs + 0x13) / 2, { (this->Offs + 0xE) / 2 });
106106
CurCHKS = SavUtils::Read<uint16_t>(this->Offs + 0xE);
107107
if (CurCHKS != Calced) SavUtils::Write<uint16_t>(this->Offs + 0xE, Calced);
108108
};

0 commit comments

Comments
 (0)