ff7tk 0.80.25
Work with Final Fantasy 7 game data
Lgp_p.h
Go to the documentation of this file.
1/****************************************************************************/
2// copyright 2009 - 2021 Arzel Jérôme <myst6re@gmail.com> //
3// copyright 2019 Chris Rizzitello <sithlord48@gmail.com> //
4// //
5// This file is part of FF7tk //
6// //
7// FF7tk is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// FF7tk is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16/****************************************************************************/
17/*
18 * This file may contains some code (especially the conflict part)
19 * inspired from LGP/UnLGP tool written by Aali.
20 * http://forums.qhimm.com/index.php?topic=8641.0
21 */
22#pragma once
23
24#include <QIODevice>
25#include <QString>
26#include <QMultiHash>
27
28#include "ff7tkformats_export.h"
29
30#define LGP_COMPANY_NAME_SIZE 12
31#define LGP_PRODUCT_NAME_SIZE 14
32
33#define LOOKUP_VALUE_MAX 30
34#define LOOKUP_TABLE_ENTRIES LOOKUP_VALUE_MAX * LOOKUP_VALUE_MAX
35
36#define MAX_CONFLICTS 4096
37
38#ifdef _MSC_VER
39# define PACK(structure) \
40 __pragma(pack(push, 1)) \
41 structure \
42 __pragma(pack(pop))
43#else
44# define PACK(structure) structure Q_PACKED
45#endif
46
48struct FF7TKFORMATS_EXPORT LgpLookupTableEntry {
49 quint16 tocOffset;
50 quint16 fileCount;
51});
52
53struct FF7TKFORMATS_EXPORT LgpConflictEntry {
54 LgpConflictEntry() : fileDir(QString()), tocIndex(0) {}
55 LgpConflictEntry(const QString &fileDir, quint16 tocIndex = 0) :
56 fileDir(fileDir), tocIndex(tocIndex) {}
57 QString fileDir;
58 quint16 tocIndex;
59};
60
61struct FF7TKFORMATS_EXPORT LgpTocEntry {
62 LgpTocEntry() : conflict(0), tocIndex(0) {}
63 LgpTocEntry(quint16 tocIndex, quint16 conflict = 0) :
64 conflict(conflict), tocIndex(tocIndex) {}
65 quint16 conflict;
66 quint16 tocIndex;
67};
68
69class FF7TKFORMATS_EXPORT LgpHeaderEntry
70{
71public:
72 LgpHeaderEntry(const QString &fileName, quint32 filePosition);
73 virtual ~LgpHeaderEntry();
74 const QString &fileName() const;
75 const QString &fileDir() const;
76 QString filePath() const;
77 quint32 filePosition() const;
78 qint64 fileSize() const;
79 void setFileName(const QString &fileName);
80 void setFileDir(const QString &fileDir);
81 void setFilePath(const QString &filePath);
82 void setFilePosition(quint32 filePosition);
83 void setFileSize(quint32 fileSize);
84 QIODevice *file(QIODevice *lgp);
85 QIODevice *modifiedFile(QIODevice *lgp);
86 void setFile(QIODevice *io);
87 void setModifiedFile(QIODevice *io);
88private:
89 QIODevice *createFile(QIODevice *lgp);
90 QString _fileName;
91 QString _fileDir;
92 quint32 _filePosition;
93 quint32 _fileSize;
94 bool _hasFileSize;
95 QIODevice *_io;
96 QIODevice *_newIO;
97};
98
99class FF7TKFORMATS_EXPORT LgpIO : public QIODevice
100{
101public:
102 LgpIO(QIODevice *lgp, const LgpHeaderEntry *header, QObject *parent = nullptr);
103 bool open(OpenMode mode) override;
104 qint64 size() const override;
105 bool canReadLine() const override;
106protected:
107 qint64 readData(char *data, qint64 maxSize) override;
108 qint64 writeData(const char *data, qint64 maxSize) override;
109private:
110 QIODevice *_lgp;
111 const LgpHeaderEntry *_header;
112};
113
114class LgpIterator;
115
116class FF7TKFORMATS_EXPORT LgpToc
117{
118public:
119 LgpToc();
120 LgpToc(const LgpToc &other);
121 virtual ~LgpToc();
122 bool addEntry(LgpHeaderEntry *entry);
123 LgpHeaderEntry *entry(const QString &filePath) const;
124 QList<LgpHeaderEntry *> entries(quint16 id) const;
125 const QMultiHash<quint16, LgpHeaderEntry *> &table() const;
126 bool hasEntries(quint16 id) const;
127 bool removeEntry(const QString &filePath);
128 static bool isNameValid(const QString &filePath);
129 bool renameEntry(const QString &filePath, const QString &newFilePath);
130 bool contains(const QString &filePath) const;
131 void clear();
132 bool isEmpty() const;
133 int size() const;
134 QList<const LgpHeaderEntry *> filesSortedByPosition() const;
135 LgpToc &operator=(const LgpToc &other);
136private:
137 LgpHeaderEntry *entry(const QString &filePath, quint16 id) const;
138 static qint32 lookupValue(const QString &filePath);
139 static quint8 lookupValue(const QChar &qc);
140 QMultiHash<quint16, LgpHeaderEntry *> _header;
141};
#define PACK(structure)
Definition: Lgp_p.h:44
Definition: Lgp_p.h:70
Definition: Lgp_p.h:100
Definition: Lgp.h:36
Definition: Lgp_p.h:117
Definition: Lgp_p.h:53
LgpConflictEntry(const QString &fileDir, quint16 tocIndex=0)
Definition: Lgp_p.h:55
QString fileDir
Definition: Lgp_p.h:57
LgpConflictEntry()
Definition: Lgp_p.h:54
quint16 tocIndex
Definition: Lgp_p.h:58
Definition: Lgp_p.h:61
quint16 tocIndex
Definition: Lgp_p.h:66
quint16 conflict
Definition: Lgp_p.h:65
LgpTocEntry(quint16 tocIndex, quint16 conflict=0)
Definition: Lgp_p.h:63
LgpTocEntry()
Definition: Lgp_p.h:62