-
Notifications
You must be signed in to change notification settings - Fork 14
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
5 changed files
with
161 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "ObjInitFactory.h" | ||
#include "utils/Decompressor.h" | ||
#include "Companion.h" | ||
#include <iomanip> | ||
|
||
void SF64::ObjInitCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { | ||
auto symbol = GetSafeNode(node, "symbol", entryName); | ||
auto objs = std::static_pointer_cast<ObjInitData>(raw)->mObjInit; | ||
|
||
write << "ObjectInit " << symbol << "[] = {\n"; | ||
for(auto& obj : objs) { | ||
auto enumName = Companion::Instance->GetEnumFromValue("obj_id", obj.id).value_or(std::to_string(obj.id)); | ||
write << fourSpaceTab << "{ " << obj.zPos1 << ", "; | ||
write << obj.zPos2 << ", "; | ||
write << obj.xPos << ", "; | ||
write << obj.yPos << ", "; | ||
write << "{ " << std::hex << obj.rot.x << ", " << std::hex << obj.rot.y << ", " << std::hex << obj.rot.z << " }, "; | ||
write << enumName << " },\n"; | ||
} | ||
write << "};\n\n"; | ||
} | ||
|
||
void SF64::ObjInitBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { | ||
auto writer = LUS::BinaryWriter(); | ||
auto data = std::static_pointer_cast<ObjInitData>(raw)->mObjInit; | ||
|
||
WriteHeader(writer, LUS::ResourceType::ObjectInit, 0); | ||
writer.Write((uint32_t) data.size()); | ||
for(auto& obj : data) { | ||
writer.Write(obj.zPos1); | ||
writer.Write(obj.zPos2); | ||
writer.Write(obj.xPos); | ||
writer.Write(obj.yPos); | ||
writer.Write(obj.rot.x); | ||
writer.Write(obj.rot.y); | ||
writer.Write(obj.rot.z); | ||
writer.Write(obj.id); | ||
} | ||
writer.Finish(write); | ||
} | ||
|
||
std::optional<std::shared_ptr<IParsedData>> SF64::ObjInitFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { | ||
auto [_, segment] = Decompressor::AutoDecode(node, buffer); | ||
auto count = GetSafeNode<size_t>(node, "count"); | ||
|
||
LUS::BinaryReader reader(segment.data, sizeof(ObjectInit) * count); | ||
reader.SetEndianness(LUS::Endianness::Big); | ||
std::vector<ObjectInit> objects; | ||
|
||
for (int i = 0; i < count; i++) { | ||
|
||
float zPos1 = reader.ReadFloat(); | ||
int16_t zPos2 = reader.ReadInt16(); | ||
int16_t xPos = reader.ReadInt16(); | ||
int16_t yPos = reader.ReadInt16(); | ||
int16_t rotX = reader.ReadInt16(); | ||
int16_t rotY = reader.ReadInt16(); | ||
int16_t rotZ = reader.ReadInt16(); | ||
int16_t id = reader.ReadInt16(); | ||
reader.ReadInt16(); // padding | ||
|
||
ObjectInit objInit{ | ||
zPos1, zPos2, | ||
xPos, yPos, | ||
{ rotX, rotY, rotZ }, | ||
id | ||
}; | ||
|
||
objects.push_back(objInit); | ||
} | ||
|
||
|
||
return std::make_shared<ObjInitData>(objects); | ||
} |
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,51 @@ | ||
#pragma once | ||
|
||
#include "../BaseFactory.h" | ||
#include "../../types/RawBuffer.h" | ||
|
||
namespace SF64 { | ||
struct Vec3s { | ||
/* 0x0 */ int16_t x; | ||
/* 0x2 */ int16_t y; | ||
/* 0x4 */ int16_t z; | ||
}; // size = 0x6; | ||
|
||
struct ObjectInit { | ||
/* 0x00 */ float zPos1; | ||
/* 0x04 */ uint16_t zPos2; | ||
/* 0x06 */ uint16_t xPos; | ||
/* 0x08 */ int16_t yPos; | ||
/* 0x0A */ Vec3s rot; | ||
/* 0x10 */ int16_t id; | ||
}; | ||
|
||
class ObjInitData : public IParsedData { | ||
public: | ||
std::vector<ObjectInit> mObjInit; | ||
|
||
explicit ObjInitData(std::vector<ObjectInit> objInit) : mObjInit(objInit) {} | ||
}; | ||
|
||
class ObjInitBinaryExporter : public BaseExporter { | ||
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; | ||
}; | ||
|
||
class ObjInitCodeExporter : public BaseExporter { | ||
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; | ||
}; | ||
|
||
class ObjInitFactory : public BaseFactory { | ||
public: | ||
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; | ||
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override { | ||
return std::nullopt; | ||
} | ||
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { | ||
return { | ||
REGISTER(Binary, ObjInitBinaryExporter) | ||
REGISTER(Code, ObjInitCodeExporter) | ||
}; | ||
} | ||
bool SupportModdedAssets() override { return false; } | ||
}; | ||
} |