daPy_lk_c::dProcTool 99%

This commit is contained in:
LagoLunatic
2025-06-16 13:15:02 -04:00
parent f042f156f5
commit bc2f5c8fd0
8 changed files with 316 additions and 33 deletions
+83
View File
@@ -30,6 +30,10 @@ template <int T>
struct TParseData_aligned : public TParseData {
TParseData_aligned(const void* pContent) : TParseData(pContent) {}
void setRaw(const void* p) {
/* if ((u32)p % T != 0) {
JUTWarn w;
w << "misaligned : " << (u32)p;
} */
static_cast<TParseData*>(this)->setRaw(p);
}
};
@@ -58,6 +62,7 @@ struct TParse_header_block {
template <typename T>
struct TParseValue_raw_ {
typedef T ParseType;
static T parse(const void* data) { return *(T*)data; }
};
@@ -79,6 +84,84 @@ struct TParseValue : public Parser<T> {
}
};
template<class Parser, int size>
struct TValueIterator {
TValueIterator(const void* begin) {
mBegin = begin;
}
// TValueIterator(const TValueIterator<Parser, size>& other) {
// mBegin = other.mBegin;
// }
const void* get() const { return mBegin; }
typename Parser::ParseType operator*() const {
return Parser::parse(get());
}
TValueIterator& operator++() {
mBegin = reinterpret_cast<u8*>(const_cast<void*>(mBegin)) + size;
return *this;
}
const TValueIterator operator++(int) {
TValueIterator old(*this);
++(*this);
return old;
}
TValueIterator& operator+=(s32 v) {
mBegin = reinterpret_cast<u8*>(const_cast<void*>(mBegin)) + size * v;
return *this;
}
TValueIterator& operator--() {
mBegin = reinterpret_cast<u8*>(const_cast<void*>(mBegin)) - size;
return *this;
}
const TValueIterator operator--(int) {
TValueIterator old(*this);
--(*this);
return old;
}
const void* mBegin;
};
template<typename T>
struct TValueIterator_raw : public TValueIterator<TParseValue_raw_<T>, sizeof(T)> {
TValueIterator_raw(const void* begin) : TValueIterator<TParseValue_raw_<T>, sizeof(T)>(begin) {}
// TValueIterator_raw(const TValueIterator_raw<T>& other) : TValueIterator<TValueIterator_raw<T>, sizeof(T)>(other) {}
friend bool operator==(TValueIterator<TParseValue_raw_<T>, sizeof(T)> a, TValueIterator<TParseValue_raw_<T>, sizeof(T)> b) {
return a.mBegin == b.mBegin;
}
friend T* operator+(TValueIterator<TParseValue_raw_<T>, sizeof(T)> a, s32 b) {
return (T*)a.mBegin + b;
}
};
template <typename T>
struct TParseValue_misaligned : TParseValue_raw_<T> {
static T parse(const void* data) { return TParseValue_raw_<T>::parse(data); }
};
template<typename T>
struct TValueIterator_misaligned : public TValueIterator<TParseValue_misaligned<T>, sizeof(T)> {
TValueIterator_misaligned(const void* begin) : TValueIterator<TParseValue_misaligned<T>, sizeof(T)>(begin) {}
// TValueIterator_misaligned(const TValueIterator_misaligned<T>& other) : TValueIterator<TParseValue_misaligned<T>, sizeof(T)>(other) {}
friend bool operator==(TValueIterator<TParseValue_misaligned<T>, sizeof(T)> a, TValueIterator<TParseValue_misaligned<T>, sizeof(T)> b) {
return a.mBegin == b.mBegin;
}
friend T* operator+(TValueIterator<TParseValue_misaligned<T>, sizeof(T)> a, s32 b) {
return (T*)a.mBegin + b;
}
};
} // namespace binary
} // namespace JGadget
+4 -4
View File
@@ -228,12 +228,12 @@ inline u32 JKRReadIdxResource(void* buffer, u32 bufferSize, u32 index, JKRArchiv
return arc->readIdxResource(buffer, bufferSize, index);
}
inline u32 JKRReadIdResource(void* buffer, u32 bufferSize, u16 id, JKRArchive* arc) {
return arc->readResource(buffer, bufferSize, id);
}
inline u32 JKRReadResource(void* buffer, u32 bufferSize, u16 id, JKRArchive* arc) {
return arc->readResource(buffer, bufferSize, id);
}
inline u32 JKRReadIdResource(void* buffer, u32 bufferSize, u16 id, JKRArchive* arc) {
return JKRReadResource(buffer, bufferSize, id, arc);
}
#endif
@@ -65,8 +65,9 @@ public:
void getData(TData*) const;
};
struct TParse_TParagraph_data : public TParseData_aligned<4> {
struct TParse_TParagraph_data : public TParseData {
struct TData {
// TODO: these field names are wrong
/* 0x00 */ u8 status;
/* 0x04 */ u32 dataSize;
/* 0x08 */ u32 _8;
@@ -74,7 +75,7 @@ struct TParse_TParagraph_data : public TParseData_aligned<4> {
/* 0x10 */ const void* _10;
};
TParse_TParagraph_data(const void* content) : TParseData_aligned<4>(content) {}
TParse_TParagraph_data(const void* content) : TParseData(content) {}
void getData(TData* pData) const;
};
+41 -15
View File
@@ -153,43 +153,69 @@ private:
/* 0x54 */ s32 _54;
};
template <int T>
struct TParseData {
template <int S>
struct TParseData : public data::TParse_TParagraph_data::TData {
TParseData(const void* pContent) {
data::TParse_TParagraph_data data(pContent);
set(data);
set(data::TParse_TParagraph_data(pContent));
}
void set(const data::TParse_TParagraph_data& data) {
//data::TParse_TParagraph_data::TData* p = (data::TParse_TParagraph_data::TData*)this;
data.getData(m_data);
data.getData(this);
}
bool isEnd() const {
return m_data->status == 0;
return status == 0;
}
bool empty() const {
return m_data->fileCount == NULL;
return fileCount == NULL;
}
bool isValid() const {
return !empty() && m_data->status == 50;
return !empty() && status == S;
}
data::TParse_TParagraph_data::TData* m_data;
u32 size() const { return _8; }
};
template <int T>
struct TParseData_fixed : public TParseData<T> {
TParseData_fixed(const void* pContent) : TParseData<T>(pContent) {}
template <int S, class Iterator=JGadget::binary::TValueIterator_raw<u8> >
struct TParseData_fixed : public TParseData<S> {
TParseData_fixed(const void* pContent) : TParseData<S>(pContent) {}
const void* getNext() const {
return this->m_data->fileCount;
return this->_10;
}
bool isValid() const {
return TParseData<T>::isValid() && getNext() != NULL;
return TParseData<S>::isValid() && getNext() != NULL;
}
Iterator begin() const {
return Iterator(this->fileCount);
}
Iterator end() const {
Iterator i(this->fileCount);
i += this->size();
return i;
}
// TODO: front and back are needed to daPy_lk_c::dProcTool
// these implementations are just guesses though, probably wrong
Iterator front() const {
// Iterator i = begin();
// i++;
// return i;
// Iterator i(begin());
// ++i;
// return i;
return Iterator(begin()) + 1;
}
Iterator back() const {
Iterator i = end();
return i + (-1);
}
};