generated from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
20 changed files
with
4,263 additions
and
24 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
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
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,120 @@ | ||
/* Mostly code from swbf2-unmunge, as everything is */ | ||
|
||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
#include "Native/Hashes.hpp" | ||
|
||
#include "Native/Chunks/ConfigReader.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
ConfigReader::ConfigReader(StreamReader &streamReader) | ||
: m_data({}) | ||
{ | ||
auto nameReaderChild = streamReader.ReadChildWithHeader<"NAME"_m>(); | ||
|
||
if (nameReaderChild.has_value()) | ||
{ | ||
uint32_t nameHash; | ||
*nameReaderChild >> nameHash; | ||
|
||
m_name = GameHashes.contains(nameHash) ? GameHashes.at(nameHash) : "unknown"; | ||
} | ||
|
||
while (streamReader.IsNextHeader<"DATA"_m>()) | ||
{ | ||
ReadData(streamReader, m_data); | ||
} | ||
} | ||
|
||
void ConfigReader::ReadData(StreamReader &streamReader, ConfigNode &parentConfigNode) | ||
{ | ||
auto dataReaderChild = streamReader.ReadChildWithHeader<"DATA"_m>(); | ||
{ | ||
FNVHash hash; | ||
*dataReaderChild >> hash; | ||
|
||
auto scopReaderChild = streamReader.ReadChildWithHeader<"SCOP"_m>(); | ||
{ | ||
ReadDataScop(*scopReaderChild, parentConfigNode.createNode(hash)); | ||
} | ||
} | ||
} | ||
|
||
void ConfigReader::ReadDataScop(StreamReader &streamReader, ConfigNode &parentConfigNode) | ||
{ | ||
while (streamReader.IsNextHeader<"DATA"_m>()) | ||
{ | ||
if (streamReader.IsNextHeader2<"DATA"_m, "SCOP"_m>()) | ||
{ | ||
ReadData(streamReader, parentConfigNode); | ||
|
||
continue; | ||
} | ||
|
||
auto scopDataReaderChild = streamReader.ReadChildWithHeader<"DATA"_m>(); | ||
if (!scopDataReaderChild.has_value()) | ||
throw std::runtime_error{ "wait, thats illegal" }; | ||
|
||
StreamReader r{ *scopDataReaderChild }; | ||
ReadDataElementInfo(r, parentConfigNode); | ||
} | ||
} | ||
|
||
void ConfigReader::ReadDataElementInfo(StreamReader &streamReader, ConfigNode &parentConfigNode) | ||
{ | ||
#pragma pack(push, 1) | ||
struct { | ||
FNVHash tag; | ||
uint8_t count; | ||
} data; | ||
#pragma pack(pop) | ||
|
||
streamReader >> data; | ||
|
||
if (data.count > 0) | ||
ReadDataElements(streamReader, parentConfigNode.createNode(data.tag), data.count); | ||
} | ||
|
||
void ConfigReader::ReadDataElements(StreamReader &streamReader, ConfigNode &parentConfigNode, uint8_t count) | ||
{ | ||
#pragma pack(push, 1) | ||
struct | ||
{ | ||
float floatValue; | ||
uint32_t stringSize; | ||
} data_element; | ||
#pragma pack(pop) | ||
|
||
streamReader >> data_element; | ||
|
||
if (count == 1) | ||
{ | ||
if (data_element.stringSize > 0) | ||
{ | ||
parentConfigNode.m_dataType = ConfigDataType::STRING; | ||
|
||
streamReader >> parentConfigNode.m_string; | ||
} | ||
else | ||
{ | ||
parentConfigNode.m_dataType = ConfigDataType::FLOAT; | ||
parentConfigNode.m_float = data_element.floatValue; | ||
} | ||
} | ||
else | ||
{ | ||
parentConfigNode.m_dataType = ConfigDataType::FLOAT_VECTOR; | ||
parentConfigNode.m_vecFloat.push_back(data_element.floatValue); | ||
|
||
for (int i = 1; i < count; i++) | ||
{ | ||
float elementValue; | ||
streamReader >> elementValue; | ||
|
||
parentConfigNode.m_dataType = ConfigDataType::FLOAT_VECTOR; | ||
parentConfigNode.m_vecFloat.push_back(elementValue); | ||
} | ||
} | ||
} | ||
} |
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,55 @@ | ||
#pragma once | ||
|
||
#include "Native/Chunks/StreamReader.hpp" | ||
|
||
#include "Native/Hashes.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
enum class ConfigDataType | ||
{ | ||
FLOAT, | ||
STRING, | ||
FLOAT_VECTOR | ||
}; | ||
|
||
class ConfigData { | ||
public: | ||
ConfigDataType m_dataType; | ||
|
||
float m_float; | ||
std::string m_string; | ||
std::vector<float> m_vecFloat; | ||
}; | ||
|
||
class ConfigNode : public ConfigData { | ||
protected: | ||
std::unordered_multimap<FNVHash, std::unique_ptr<ConfigNode>> m_childs; | ||
public: | ||
ConfigNode &createNode(FNVHash hash) { | ||
auto it = m_childs.emplace(hash, std::make_unique<ConfigNode>()); | ||
if (it == m_childs.end()) | ||
throw std::runtime_error{ "failed to create node " }; | ||
return *it->second; | ||
} | ||
|
||
auto &getNodes() { | ||
return m_childs; | ||
} | ||
}; | ||
|
||
class ConfigReader : public StreamReader { | ||
public: | ||
ConfigReader(StreamReader &streamReader); | ||
|
||
std::string m_name; | ||
|
||
ConfigNode m_data; | ||
|
||
private: | ||
void ReadData(StreamReader &streamReader, ConfigNode &parentConfigNode); | ||
void ReadDataScop(StreamReader &streamReader, ConfigNode &parentConfigNode); | ||
void ReadDataElementInfo(StreamReader &streamReader, ConfigNode &parentConfigNode); | ||
void ReadDataElements(StreamReader &streamReader, ConfigNode &parentConfigNode, uint8_t count); | ||
}; | ||
} |
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,29 @@ | ||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
#include "Native/Chunks/ConfigReader.hpp" | ||
#include "Native/Chunks/StreamReader.hpp" | ||
#include "Native/Chunks/SkyChunk.hpp" | ||
#include "Native/SWBF2.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
void SkyChunk::ProcessChunk(StreamReader &streamReader) | ||
{ | ||
ConfigReader configReader{ streamReader }; | ||
|
||
for (auto const &[idhead, headnode] : configReader.m_data.getNodes()) | ||
{ | ||
for (auto const &[attr, val] : headnode->getNodes()) | ||
{ | ||
switch (attr) | ||
{ | ||
case "Texture"_fnv: | ||
{ | ||
SWBF2::m_skyDome.m_texture = val->m_string; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
#pragma once | ||
|
||
#include "StreamReader.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
class SkyChunk { | ||
public: | ||
static void ProcessChunk(StreamReader &streamReader); | ||
}; | ||
|
||
} |
Oops, something went wrong.