forked from czajowaty/ad_resources_dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdMemoryHandler.hpp
144 lines (130 loc) · 4.76 KB
/
AdMemoryHandler.hpp
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
#ifndef ADMEMORYHANDLER_HPP
#define ADMEMORYHANDLER_HPP
#include "AdDefinitions.hpp"
#include "AdSpeakerId.hpp"
#include "BinCdImageReader.hpp"
#include "VirtualPsxRam.hpp"
#include "VirtualPsxVRam.hpp"
#include <QImage>
#include <QVector>
#include <memory>
struct CharacterPortraitData
{
PsxRamAddress portraitDataAddress;
PortraitData portraitData;
};
using CharacterPortraitsData = QVector<CharacterPortraitData>;
using GraphicsSeries = QVector<QPair<Graphic, QImage>>;
using AnimationFrame = QPair<Animation, GraphicsSeries>;
using AnimationFrames = QVector<AnimationFrame>;
struct CharacterPortraitResource
{
MemoryLoadInfo resourcesMemoryLoadInfo;
AnimationFrames animationFrames;
bool graphicsOffsetHalved;
};
struct SpeakerInfo
{
char const* name;
AdSpeakerId speakerId;
uint32_t variantsNumber;
bool isValid() const
{ return variantsNumber > 0; }
};
using SpeakersInfo = std::array<SpeakerInfo, 15>;
static constexpr SpeakersInfo SPEAKERS_INFO = {
{
{"Aunt", AdSpeakerId::Aunt, 2},
{"Cherrl", AdSpeakerId::Cherrl, 9},
{"Fur", AdSpeakerId::Fur, 6},
{"Ghosh", AdSpeakerId::Ghosh, 3},
{"Grandpa", AdSpeakerId::Grandpa, 1},
{"Guy", AdSpeakerId::Guy, 3},
{"Jorda", AdSpeakerId::Jorda, 1},
{"Kewne", AdSpeakerId::Kewne, 13},
{"Miya", AdSpeakerId::Miya, 7},
{"Nico", AdSpeakerId::Nico, 8},
{"Patty", AdSpeakerId::Patty, 5},
{"Selfi", AdSpeakerId::Selfi, 6},
{"Vivian", AdSpeakerId::Vivian, 6},
{"Weedy", AdSpeakerId::Weedy, 2},
{"Wreath", AdSpeakerId::Wreath, 4}
}
};
class AdMemoryHandler
{
static constexpr uint8_t INVALID_SPEAKER_PORTRAIT_INDEX = 0xff;
static const QPoint PORTRAIT_POSITION;
static constexpr SpeakerInfo INVALID_SPEAKER_INFO =
{nullptr, AdSpeakerId::None, 0};
public:
AdMemoryHandler();
VirtualPsxRam const& ram() const
{ return *ram_; }
VirtualPsxVRam const& vram() const
{ return *vram_; }
// TODO: remove them?
VirtualPsxVRam& vram()
{ return *vram_; }
// TODO: remove them?
BinCdImageReader const* adCdImageReader() const
{ return adCdImageReader_.get(); }
// TODO: remove them?
BinCdImageReader* adCdImageReader()
{ return adCdImageReader_.get(); }
void loadCdImage(QString const& cdImagePath);
void loadGameModeResources(GameMode gameMode);
CharacterPortraitsData readCharacterPortraitsData(AdSpeakerId speakerId);
CharacterPortraitResource loadCharacterPortrait(PortraitData portraitData);
AnimationFrames readAnimation(PsxRamAddress animationAddress);
GraphicsSeries readGraphicsSeries(PsxRamAddress graphicAddress);
QImage readGraphic(Graphic const& graphic);
QImage readPlainGraphic(Graphic const& graphic);
QImage combinePortraitGraphicSeries(
GraphicsSeries const& graphicsSeries,
PortraitData const& portraitData);
QImage combineGraphicSeries(
GraphicsSeries const& graphicsSeries,
bool graphicOffsetHalved);
QImage combineGraphicSeries(
GraphicsSeries const& graphicsSeries,
bool graphicOffsetHalved,
QPoint const& anchorPoint,
QSize const& size);
private:
void loadSlusTextSection();
void loadTownResources();
GameModeData readGameModeData(GameMode gameMode) const;
uint32_t readGameModeDataSectorsNumber(GameMode gameMode);
uint32_t gameModeToIndex(GameMode gameMode) const
{ return static_cast<uint32_t>(gameMode); }
void loadTownVRamResources();
void loadVRamLoadablePackedImage(
ResourceType1Header const* resourceHeader,
uint8_t const* resourceData,
uint32_t maxSize);
QByteArray unpackResourceTexture(
uint8_t const* resourceData,
uint32_t maxSize);
void loadVRamPalette(
ResourceType2Header const* resourceHeader,
uint8_t const* resourceData);
uint8_t readSpeakerPortraitIndex(AdSpeakerId speakerId);
SpeakerInfo const& findSpeakerInfo(AdSpeakerId speakerId) const;
void loadPortraitResourceIntoVRam(MemoryLoadInfo const& memoryLoadInfo);
bool doesAnimationHaveHalvedGraphicsOffsets(PsxRamAddress animationAddress);
QRect calculateGraphicsSeriesBounds(
GraphicsSeries const& graphicsSeries,
bool graphicOffsetHalved);
QPoint calculateGraphicPosition(
Graphic const& graphic,
bool graphicOffsetHalved);
QPoint calculateGraphicInSeriesPosition(
Graphic const& graphic,
bool graphicOffsetHalved,
QPoint const& anchorPoint);
std::unique_ptr<VirtualPsxRam> ram_;
std::unique_ptr<VirtualPsxVRam> vram_;
std::unique_ptr<BinCdImageReader> adCdImageReader_;
};
#endif // ADMEMORYHANDLER_HPP