-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7abe307
commit 9e71806
Showing
6 changed files
with
485 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* Xenoblade Engine Format Library | ||
Copyright(C) 2022 Lukas Cone | ||
This program is free software : you can redistribute it and / or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program.If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace V1 { | ||
using namespace BDAT; | ||
template <class C> using Pointer16 = es::PointerX86<C, int16>; | ||
|
||
enum class BaseType : uint8 { | ||
None, | ||
Default, | ||
Array, | ||
Flag, | ||
}; | ||
|
||
struct KeyDesc; | ||
|
||
struct BaseTypeDesc { | ||
BaseType baseType; | ||
}; | ||
|
||
struct FlagTypeDesc : BaseTypeDesc { | ||
uint8 index; | ||
uint16 null; | ||
uint16 value; | ||
Pointer16<KeyDesc> belongsTo; | ||
}; | ||
|
||
struct TypeDesc : BaseTypeDesc { | ||
DataType type; | ||
uint16 offset; | ||
}; | ||
|
||
struct ArrayTypeDesc : TypeDesc { | ||
uint16 numItems; | ||
}; | ||
|
||
struct KeyDesc { | ||
Pointer16<BaseTypeDesc> typeDesc; | ||
Pointer16<KeyDesc> unk; // random refs | ||
Pointer16<char> name; | ||
}; | ||
|
||
struct KVPair { | ||
const BaseTypeDesc *desc; | ||
union { | ||
const char *data; | ||
const Value *value; | ||
}; | ||
|
||
bool XN_EXTERN operator==(const Value &other) const; | ||
|
||
bool operator==(es::string_view other) const { | ||
if (IsString()) { | ||
return other == value->asString.Get(); | ||
} | ||
|
||
throw std::runtime_error("Invalid call for string comparison"); | ||
} | ||
|
||
bool IsString() const { | ||
if (desc->baseType != BaseType::Default) { | ||
return false; | ||
} | ||
|
||
auto &asDef = *static_cast<const TypeDesc *>(desc); | ||
|
||
return asDef.type == DataType::StringPtr; | ||
} | ||
}; | ||
|
||
enum class Type : uint8 { | ||
EncryptFloat, | ||
PersistentFlag, // Is this whole encryption? | ||
}; | ||
|
||
using Flags = es::Flags<Type>; | ||
|
||
struct Header { | ||
uint32 id; | ||
uint8 version; | ||
Flags flags; | ||
Pointer16<char> name; | ||
uint16 kvBlockStride; | ||
Pointer16<char> unk1Offset; | ||
uint16 unk1Size; | ||
Pointer16<char> keyValues; | ||
uint16 numKeyValues; | ||
uint16 unk3; | ||
uint16 numEncKeys; | ||
uint8 encKeys[2]; | ||
Pointer<char> strings; | ||
uint32 stringsSize; | ||
Pointer16<KeyDesc> keyDescs; | ||
uint16 numKeyDescs; | ||
|
||
const char XN_EXTERN *FindBlock(es::string_view keyName, Value value); | ||
const char XN_EXTERN *FindBlock(es::string_view keyName, | ||
es::string_view value); | ||
}; | ||
|
||
struct Collection { | ||
uint32 numDatas; | ||
uint32 fileSize; | ||
Pointer<Header> datas[1]; | ||
|
||
Pointer<Header> *begin() { return datas; } | ||
Pointer<Header> *end() { return datas + numDatas; } | ||
const Pointer<Header> *begin() const { return datas; } | ||
const Pointer<Header> *end() const { return datas + numDatas; } | ||
|
||
const Header XN_EXTERN *FindData(es::string_view name) const; | ||
}; | ||
} // namespace V1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Xenoblade Engine Format Library | ||
Copyright(C) 2022 Lukas Cone | ||
This program is free software : you can redistribute it and / or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program.If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace V4 { | ||
using namespace BDAT; | ||
|
||
enum class Type : uint8 { | ||
Data, | ||
Collection, | ||
}; | ||
|
||
struct HeaderBase { | ||
uint32 id; | ||
uint8 version; | ||
uint8 headerSize; | ||
uint8 null; | ||
Type type; | ||
}; | ||
|
||
struct Descriptor { | ||
DataType type; | ||
uint8 nameOffset0; | ||
uint8 nameOffset1; | ||
uint16 NameOffset() const { return nameOffset0 + (nameOffset1 * 256); } | ||
}; | ||
|
||
struct Key { | ||
uint32 hash; | ||
uint32 index; | ||
}; | ||
|
||
struct Header : HeaderBase { | ||
uint32 numDescs; | ||
uint32 numKeys; | ||
uint32 unk3; | ||
uint32 selfHash; // could be used as encKey? | ||
Pointer<Descriptor> descriptors; | ||
Pointer<Key> keys; | ||
Pointer<char> values; | ||
uint32 kvBlockSize; | ||
Pointer<char> strings; | ||
uint32 stringsSize; | ||
}; | ||
|
||
struct Collection : HeaderBase { | ||
uint32 numDatas; | ||
uint32 fileSize; | ||
Pointer<Header> datas[1]; | ||
|
||
Pointer<Header> *begin() { return datas; } | ||
Pointer<Header> *end() { return datas + numDatas; } | ||
const Pointer<Header> *begin() const { return datas; } | ||
const Pointer<Header> *end() const { return datas + numDatas; } | ||
}; | ||
|
||
} // namespace V4 |
Oops, something went wrong.