Implemented even more factories

This commit is contained in:
KiritoDv
2024-04-06 14:25:40 -06:00
parent 83cb18d9db
commit 5427fdb031
20 changed files with 370 additions and 2 deletions
+11 -1
View File
@@ -4,9 +4,14 @@
#include "libultraship/src/Context.h"
#include "resource/type/ResourceType.h"
#include "resource/importers/AnimFactory.h"
#include "resource/importers/EnvSettingsFactory.h"
#include "resource/importers/HitboxFactory.h"
#include "resource/importers/LimbFactory.h"
#include "resource/importers/MessageFactory.h"
#include "resource/importers/MessageLookupFactory.h"
#include "resource/importers/ObjectInitFactory.h"
#include "resource/importers/ScriptCommandFactory.h"
#include "resource/importers/ScriptFactory.h"
#include "resource/importers/SkeletonFactory.h"
#include <Fast3D/gfx_pc.h>
@@ -48,7 +53,12 @@ GameEngine::GameEngine() {
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinarySkeletonV0>(), RESOURCE_FORMAT_BINARY, "Skeleton", static_cast<uint32_t>(SF64::ResourceType::Skeleton), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryLimbV0>(), RESOURCE_FORMAT_BINARY, "Limb", static_cast<uint32_t>(SF64::ResourceType::Limb), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageV0>(), RESOURCE_FORMAT_BINARY, "Message", static_cast<uint32_t>(SF64::ResourceType::Message), 0);
loader->RegisterResourceFactory( std::make_shared<SF64::ResourceFactoryBinaryMessageLookupV0>(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast<uint32_t>(SF64::ResourceType::MessageTable), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageLookupV0>(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast<uint32_t>(SF64::ResourceType::MessageTable), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryEnvSettingsV0>(), RESOURCE_FORMAT_BINARY, "EnvSettings", static_cast<uint32_t>(SF64::ResourceType::EnvSettings), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryObjectInitV0>(), RESOURCE_FORMAT_BINARY, "ObjectInit", static_cast<uint32_t>(SF64::ResourceType::ObjectInit), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryHitboxV0>(), RESOURCE_FORMAT_BINARY, "Hitbox", static_cast<uint32_t>(SF64::ResourceType::Hitbox), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptV0>(), RESOURCE_FORMAT_BINARY, "Script", static_cast<uint32_t>(SF64::ResourceType::Script), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptCMDV0>(), RESOURCE_FORMAT_BINARY, "ScriptCMD", static_cast<uint32_t>(SF64::ResourceType::ScriptCmd), 0);
}
void GameEngine::Create(){
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#define LOAD_ASSET(path) (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path)
#define LOAD_ASSET(path) (path == NULL ? NULL : (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path))
#define LOAD_ASSET_RAW(path) ResourceGetDataByName((const char*) path)
#ifdef __cplusplus
@@ -0,0 +1,38 @@
#include "EnvSettingsFactory.h"
#include "Context.h"
#include "resourcebridge.h"
#include "../type/EnvSettings.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryEnvSettingsV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto env = std::make_shared<EnvSettings>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
env->mSettings.type = reader->ReadInt32();
env->mSettings.unk_04 = reader->ReadInt32();
env->mSettings.bgColor = reader->ReadUInt16();
env->mSettings.seqId = reader->ReadUInt16();
env->mSettings.fogR = reader->ReadInt32();
env->mSettings.fogG = reader->ReadInt32();
env->mSettings.fogB = reader->ReadInt32();
env->mSettings.fogN = reader->ReadInt32();
env->mSettings.fogF = reader->ReadInt32();
env->mSettings.unk_20.x = reader->ReadFloat();
env->mSettings.unk_20.y = reader->ReadFloat();
env->mSettings.unk_20.z = reader->ReadFloat();
env->mSettings.lightR = reader->ReadInt32();
env->mSettings.lightG = reader->ReadInt32();
env->mSettings.lightB = reader->ReadInt32();
env->mSettings.ambR = reader->ReadInt32();
env->mSettings.ambG = reader->ReadInt32();
env->mSettings.ambB = reader->ReadInt32();
return env;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryEnvSettingsV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,22 @@
#include "HitboxFactory.h"
#include "../type/Hitbox.h"
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryHitboxV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto hitbox = std::make_shared<Hitbox>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto count = reader->ReadUInt32();
for (uint32_t i = 0; i < count; i++) {
hitbox->mHitbox.push_back(reader->ReadFloat());
}
return hitbox;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryHitboxV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,33 @@
#include "ObjectInitFactory.h"
#include "Context.h"
#include "resourcebridge.h"
#include "../type/ObjectInit.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryObjectInitV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto obj = std::make_shared<ObjectInit>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto count = reader->ReadUInt32();
for(size_t i = 0; i < count; i++) {
ObjectInitData data;
data.zPos1 = reader->ReadFloat();
data.zPos2 = reader->ReadInt16();
data.xPos = reader->ReadInt16();
data.yPos = reader->ReadInt16();
data.rot.x = reader->ReadInt16();
data.rot.y = reader->ReadInt16();
data.rot.z = reader->ReadInt16();
data.id = reader->ReadInt16();
obj->mObjects.push_back(data);
}
return obj;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryObjectInitV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,23 @@
#include "ScriptCommandFactory.h"
#include "../type/Script.h"
#include "spdlog/spdlog.h"
#include "ResourceUtil.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryScriptCMDV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto cmds = std::make_shared<ScriptCMDs>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto size = reader->ReadUInt32();
for (uint32_t i = 0; i < size * 2; i++) {
cmds->mCommands.push_back(reader->ReadUInt16());
}
return cmds;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryScriptCMDV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS
@@ -0,0 +1,23 @@
#include "ScriptFactory.h"
#include "../type/Script.h"
#include "spdlog/spdlog.h"
#include "ResourceUtil.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryScriptV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto script = std::make_shared<Script>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto size = reader->ReadUInt32();
for (uint32_t i = 0; i < size; i++) {
script->mScripts.push_back(LoadChild<uint16_t*>(reader->ReadUInt64()));
}
return script;
}
} // namespace LUS
@@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryScriptV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS
+11
View File
@@ -0,0 +1,11 @@
#include "EnvSettings.h"
namespace SF64 {
EnvSettingsData* EnvSettings::GetPointer() {
return &mSettings;
}
size_t EnvSettings::GetPointerSize() {
return sizeof(EnvSettingsData);
}
}
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include "Limb.h"
#include <cstdint>
#include <Resource.h>
namespace SF64 {
struct EnvSettingsData {
/* 0x00 */ int32_t type;
/* 0x04 */ int32_t unk_04;
/* 0x08 */ uint16_t bgColor;
/* 0x0A */ uint16_t seqId;
/* 0x0C */ int32_t fogR;
/* 0x10 */ int32_t fogG;
/* 0x14 */ int32_t fogB;
/* 0x18 */ int32_t fogN;
/* 0x1C */ int32_t fogF;
/* 0x20 */ Vec3f unk_20;
/* 0x2C */ int32_t lightR;
/* 0x30 */ int32_t lightG;
/* 0x34 */ int32_t lightB;
/* 0x38 */ int32_t ambR;
/* 0x3C */ int32_t ambG;
/* 0x40 */ int32_t ambB;
};
class EnvSettings : public LUS::Resource<EnvSettingsData> {
public:
using Resource::Resource;
EnvSettings() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
EnvSettingsData* GetPointer();
size_t GetPointerSize();
EnvSettingsData mSettings{};
};
}
+11
View File
@@ -0,0 +1,11 @@
#include "Hitbox.h"
namespace SF64 {
float* Hitbox::GetPointer() {
return mHitbox.data();
}
size_t Hitbox::GetPointerSize() {
return sizeof(float) * mHitbox.size();
}
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <cstdint>
#include <Resource.h>
namespace SF64 {
class Hitbox : public LUS::Resource<float> {
public:
using Resource::Resource;
float* GetPointer() override;
size_t GetPointerSize() override;
std::vector<float> mHitbox;
};
}
+11
View File
@@ -0,0 +1,11 @@
#include "ObjectInit.h"
namespace SF64 {
ObjectInitData* ObjectInit::GetPointer() {
return mObjects.data();
}
size_t ObjectInit::GetPointerSize() {
return sizeof(ObjectInitData) * mObjects.size();
}
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include "Limb.h"
#include <cstdint>
#include <Resource.h>
namespace SF64 {
struct ObjectInitData {
/* 0x00 */ float zPos1;
/* 0x04 */ int16_t zPos2;
/* 0x06 */ int16_t xPos;
/* 0x08 */ int16_t yPos;
/* 0x0A */ Vec3s rot;
/* 0x10 */ int16_t id;
}; // size = 0x14
class ObjectInit : public LUS::Resource<ObjectInitData> {
public:
using Resource::Resource;
ObjectInit() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
ObjectInitData* GetPointer();
size_t GetPointerSize();
std::vector<ObjectInitData> mObjects;
};
}
+19
View File
@@ -0,0 +1,19 @@
#include "Script.h"
namespace SF64 {
uint16_t** Script::GetPointer() {
return mScripts.data();
}
size_t Script::GetPointerSize() {
return sizeof(uint16_t*) * mScripts.size();
}
uint16_t* ScriptCMDs::GetPointer() {
return mCommands.data();
}
size_t ScriptCMDs::GetPointerSize() {
return sizeof(uint16_t) * mCommands.size();
}
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
#include <Resource.h>
namespace SF64 {
class Script : public LUS::Resource<uint16_t*> {
public:
using Resource::Resource;
uint16_t** GetPointer() override;
size_t GetPointerSize() override;
std::vector<uint16_t*> mScripts;
};
class ScriptCMDs : public LUS::Resource<uint16_t> {
public:
using Resource::Resource;
uint16_t* GetPointer() override;
size_t GetPointerSize() override;
std::vector<uint16_t> mCommands;
};
}