mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
little boxes
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "factories/sf64/SkeletonFactory.h"
|
||||
#include "factories/sf64/AnimFactory.h"
|
||||
#include "factories/sf64/ScriptFactory.h"
|
||||
#include "factories/sf64/HitboxFactory.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
namespace fs = std::filesystem;
|
||||
@@ -75,6 +76,7 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("SF64:MESSAGE", std::make_shared<SF64::MessageFactory>());
|
||||
this->RegisterFactory("SF64:MSG_TABLE", std::make_shared<SF64::MessageLookupFactory>());
|
||||
this->RegisterFactory("SF64:SCRIPT", std::make_shared<SF64::ScriptFactory>());
|
||||
this->RegisterFactory("SF64:HITBOX", std::make_shared<SF64::HitboxFactory>());
|
||||
|
||||
|
||||
this->Process();
|
||||
|
||||
@@ -36,5 +36,8 @@ enum class ResourceType {
|
||||
AnimData = 0x414E494D, // ANIM
|
||||
Message = 0x4D53474C, // MSG
|
||||
MessageTable = 0x4D534754, // MSGT
|
||||
Skeleton = 0x534B454C, // SKEL
|
||||
Script = 0x53435250, // SCRP
|
||||
Hitbox = 0x48544258, // HTBX
|
||||
};
|
||||
} // namespace LUS
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
#include "HitboxFactory.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include "Companion.h"
|
||||
#include "utils/Decompressor.h"
|
||||
#include "utils/TorchUtils.h"
|
||||
|
||||
SF64::HitboxData::HitboxData(std::vector<float> data, std::vector<int> types): mData(data), mTypes(types) {
|
||||
|
||||
}
|
||||
|
||||
void SF64::HitboxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
|
||||
const auto symbol = GetSafeNode(node, "symbol", entryName);
|
||||
|
||||
if(Companion::Instance->IsOTRMode()){
|
||||
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
|
||||
return;
|
||||
}
|
||||
|
||||
write << "extern f32 " << symbol << "[];\n";
|
||||
}
|
||||
|
||||
void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
const auto symbol = GetSafeNode(node, "symbol", entryName);
|
||||
const auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
auto hitbox = std::static_pointer_cast<SF64::HitboxData>(raw);
|
||||
auto index = 0;
|
||||
auto count = hitbox->mData[index++];
|
||||
auto off = offset;
|
||||
if(IS_SEGMENTED(off)) {
|
||||
off = SEGMENT_OFFSET(off);
|
||||
}
|
||||
|
||||
if (Companion::Instance->IsDebug()) {
|
||||
write << "// 0x" << std::uppercase << std::hex << off << "\n";
|
||||
}
|
||||
write << "f32 " << symbol << "[] = {\n";
|
||||
write << fourSpaceTab << count << ",\n";
|
||||
|
||||
for(int i = 0; i < (int)count; i++) {
|
||||
if(hitbox->mTypes[i] == 4) {
|
||||
write << fourSpaceTab << "HITBOX_TYPE_4, ";
|
||||
index++;
|
||||
} else if (hitbox->mTypes[i] == 3) {
|
||||
write << fourSpaceTab << "HITBOX_TYPE_3, ";
|
||||
index++;
|
||||
} else if (hitbox->mTypes[i] == 2) {
|
||||
write << fourSpaceTab << "HITBOX_TYPE_2, ";
|
||||
index++;
|
||||
for(int j = 0; j < 3; j++) {
|
||||
write << hitbox->mData[index++] << ", ";
|
||||
}
|
||||
write << fourSpaceTab;
|
||||
} else {
|
||||
write << " /* HITBOX_TYPE_1 */ ";
|
||||
}
|
||||
for(int j = 0; j < 6; j++) {
|
||||
write << hitbox->mData[index++] << ", ";
|
||||
}
|
||||
write << "\n";
|
||||
}
|
||||
write << "};\n";
|
||||
if (Companion::Instance->IsDebug()) {
|
||||
write << "// 0x" << std::uppercase << std::hex << off + sizeof(float) * index << "\n";
|
||||
}
|
||||
write << "\n";
|
||||
}
|
||||
|
||||
void SF64::HitboxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
auto hitbox = std::static_pointer_cast<SF64::HitboxData>(raw);
|
||||
auto writer = LUS::BinaryWriter();
|
||||
|
||||
WriteHeader(writer, LUS::ResourceType::Hitbox, 0);
|
||||
for (float value : hitbox->mData) {
|
||||
writer.Write(value);
|
||||
}
|
||||
writer.Finish(write);
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<IParsedData>> SF64::HitboxFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
|
||||
std::vector<float> data;
|
||||
int count;
|
||||
std::vector<int> types;
|
||||
auto [_, segment] = Decompressor::AutoDecode(node, buffer, 0x10000);
|
||||
LUS::BinaryReader reader(segment.data, segment.size);
|
||||
reader.SetEndianness(LUS::Endianness::Big);
|
||||
|
||||
data.push_back(reader.ReadFloat());
|
||||
count = data[0];
|
||||
|
||||
while(count > 0) {
|
||||
auto typecode = reader.ReadFloat();
|
||||
auto readCount = 0;
|
||||
if(typecode == 300000.0f || typecode == 400000.0f) {
|
||||
readCount = 6;
|
||||
types.push_back((typecode == 300000.0f) ? 3 : 4);
|
||||
} else if (typecode == 200000.0f) {
|
||||
readCount = 9;
|
||||
types.push_back(2);
|
||||
} else {
|
||||
readCount = 5;
|
||||
types.push_back(1);
|
||||
}
|
||||
data.push_back(typecode);
|
||||
for(int i = 0; i < readCount; i++) {
|
||||
data.push_back(reader.ReadFloat());
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
return std::make_shared<SF64::HitboxData>(data, types);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../BaseFactory.h"
|
||||
|
||||
namespace SF64 {
|
||||
|
||||
class HitboxData : public IParsedData {
|
||||
public:
|
||||
std::vector<float> mData;
|
||||
std::vector<int> mTypes;
|
||||
|
||||
HitboxData(std::vector<float> data, std::vector<int> types);
|
||||
};
|
||||
|
||||
class HitboxHeaderExporter : public BaseExporter {
|
||||
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class HitboxBinaryExporter : public BaseExporter {
|
||||
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class HitboxCodeExporter : public BaseExporter {
|
||||
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class HitboxFactory : 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(Code, HitboxCodeExporter)
|
||||
REGISTER(Header, HitboxHeaderExporter)
|
||||
REGISTER(Binary, HitboxBinaryExporter)
|
||||
};
|
||||
}
|
||||
bool SupportModdedAssets() override { return false; }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user