diff options
| m--------- | OTRExporter | 0 | ||||
| m--------- | libultraship | 0 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/BenMenuBar.cpp | 28 | ||||
| -rw-r--r-- | mm/2s2h/BenPort.cpp | 29 | ||||
| -rw-r--r-- | mm/2s2h/resource/importer/ArrayFactory.cpp | 64 | ||||
| -rw-r--r-- | mm/2s2h/resource/importer/ArrayFactory.h | 11 | ||||
| -rw-r--r-- | mm/2s2h/resource/type/2shResourceType.h | 1 | ||||
| -rw-r--r-- | mm/2s2h/resource/type/Array.cpp | 46 | ||||
| -rw-r--r-- | mm/2s2h/resource/type/Array.h | 85 | ||||
| -rw-r--r-- | mm/src/code/stubs.c | 2 |
10 files changed, 234 insertions, 32 deletions
diff --git a/OTRExporter b/OTRExporter -Subproject 287c79891882df5a0797cd9d39c0dcb97af9f00 +Subproject 375489d5f1f5fa4b9144ac9669c411e3b149f32 diff --git a/libultraship b/libultraship -Subproject 070eb35dde54f8dcbffad8fb3d97367bb792b6b +Subproject fccf181b449f82f3e6ae5cdc666319847f78e0a diff --git a/mm/2s2h/BenGui/BenMenuBar.cpp b/mm/2s2h/BenGui/BenMenuBar.cpp index 89bb3e009..764d2ea65 100644 --- a/mm/2s2h/BenGui/BenMenuBar.cpp +++ b/mm/2s2h/BenGui/BenMenuBar.cpp @@ -41,10 +41,9 @@ static const std::unordered_map<Ship::AudioBackend, const char*> audioBackendsMa }; static std::unordered_map<Ship::WindowBackend, const char*> windowBackendsMap = { - { Ship::WindowBackend::DX11, "DirectX" }, - { Ship::WindowBackend::SDL_OPENGL, "OpenGL" }, - { Ship::WindowBackend::SDL_METAL, "Metal" }, - { Ship::WindowBackend::GX2, "GX2" } + { Ship::WindowBackend::FAST3D_DXGI_DX11, "DirectX" }, + { Ship::WindowBackend::FAST3D_SDL_OPENGL, "OpenGL" }, + { Ship::WindowBackend::FAST3D_SDL_METAL, "Metal" }, }; static const std::unordered_map<int32_t, const char*> clockTypeOptions = { @@ -196,19 +195,21 @@ void DrawSettingsMenu() { { // FPS Slider constexpr unsigned int minFps = 20; static unsigned int maxFps; - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::DX11) { + if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == + Ship::WindowBackend::FAST3D_DXGI_DX11) { maxFps = 360; } else { maxFps = Ship::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(); } unsigned int currentFps = std::max(std::min(OTRGlobals::Instance->GetInterpolationFPS(), maxFps), minFps); - bool matchingRefreshRate = - CVarGetInteger("gMatchRefreshRate", 0) && - Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() != Ship::WindowBackend::DX11; + bool matchingRefreshRate = CVarGetInteger("gMatchRefreshRate", 0) && + Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() != + Ship::WindowBackend::FAST3D_DXGI_DX11; UIWidgets::CVarSliderInt((currentFps == 20) ? "FPS: Original (20)" : "FPS: %d", "gInterpolationFPS", minFps, maxFps, 20, { .disabled = matchingRefreshRate }); - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::DX11) { + if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == + Ship::WindowBackend::FAST3D_DXGI_DX11) { UIWidgets::Tooltip( "Uses Matrix Interpolation to create extra frames, resulting in smoother graphics. This is " "purely visual and does not impact game logic, execution of glitches etc.\n\n A higher target " @@ -220,7 +221,8 @@ void DrawSettingsMenu() { } } // END FPS Slider - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::DX11) { + if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == + Ship::WindowBackend::FAST3D_DXGI_DX11) { // UIWidgets::Spacer(0); if (ImGui::Button("Match Refresh Rate")) { int hz = Ship::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(); @@ -234,7 +236,8 @@ void DrawSettingsMenu() { } UIWidgets::Tooltip("Matches interpolation value to the current game's window refresh rate"); - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::DX11) { + if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == + Ship::WindowBackend::FAST3D_DXGI_DX11) { UIWidgets::CVarSliderInt(CVarGetInteger("gExtraLatencyThreshold", 80) == 0 ? "Jitter fix: Off" : "Jitter fix: >= %d FPS", "gExtraLatencyThreshold", 0, 360, 80); @@ -250,8 +253,7 @@ void DrawSettingsMenu() { Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend(); Ship::WindowBackend configWindowBackend; int32_t configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1); - if (configWindowBackendId != -1 && - configWindowBackendId < static_cast<int>(Ship::WindowBackend::BACKEND_COUNT)) { + if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) { configWindowBackend = static_cast<Ship::WindowBackend>(configWindowBackendId); } else { configWindowBackend = runningWindowBackend; diff --git a/mm/2s2h/BenPort.cpp b/mm/2s2h/BenPort.cpp index 15dc9ef65..5009eb2ce 100644 --- a/mm/2s2h/BenPort.cpp +++ b/mm/2s2h/BenPort.cpp @@ -20,7 +20,6 @@ #else #include <time.h> #endif -#include <Array.h> #include <AudioPlayer.h> #include "variables.h" #include "z64.h" @@ -57,7 +56,6 @@ CrowdControl* CrowdControl::Instance; #include "2s2h/SaveManager/SaveManager.h" // Resource Types/Factories -#include "resource/type/Array.h" #include "resource/type/Blob.h" #include "resource/type/DisplayList.h" #include "resource/type/Matrix.h" @@ -65,6 +63,7 @@ CrowdControl* CrowdControl::Instance; #include "resource/type/Vertex.h" #include "2s2h/resource/type/2shResourceType.h" #include "2s2h/resource/type/Animation.h" +#include "2s2h/resource/type/Array.h" #include "2s2h/resource/type/AudioSample.h" #include "2s2h/resource/type/AudioSequence.h" #include "2s2h/resource/type/AudioSoundFont.h" @@ -75,13 +74,13 @@ CrowdControl* CrowdControl::Instance; #include "2s2h/resource/type/Scene.h" #include "2s2h/resource/type/Skeleton.h" #include "2s2h/resource/type/SkeletonLimb.h" -#include "resource/factory/ArrayFactory.h" #include "resource/factory/BlobFactory.h" #include "resource/factory/DisplayListFactory.h" #include "resource/factory/MatrixFactory.h" #include "resource/factory/TextureFactory.h" #include "resource/factory/VertexFactory.h" #include "2s2h/resource/importer/AnimationFactory.h" +#include "2s2h/resource/importer/ArrayFactory.h" #include "2s2h/resource/importer/AudioSampleFactory.h" #include "2s2h/resource/importer/AudioSequenceFactory.h" #include "2s2h/resource/importer/AudioSoundFontFactory.h" @@ -179,10 +178,10 @@ OTRGlobals::OTRGlobals() { "DisplayList", static_cast<uint32_t>(LUS::ResourceType::DisplayList), 0); loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryMatrixV0>(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast<uint32_t>(LUS::ResourceType::Matrix), 0); - loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryArrayV0>(), RESOURCE_FORMAT_BINARY, - "Array", static_cast<uint32_t>(LUS::ResourceType::Array), 0); loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY, "Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0); + loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryArrayV0>(), RESOURCE_FORMAT_BINARY, + "Array", static_cast<uint32_t>(SOH::ResourceType::SOH_Array), 0); loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAnimationV0>(), RESOURCE_FORMAT_BINARY, "Animation", static_cast<uint32_t>(SOH::ResourceType::SOH_Animation), 0); loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryPlayerAnimationV0>(), @@ -292,7 +291,7 @@ bool OTRGlobals::HasOriginal() { } uint32_t OTRGlobals::GetInterpolationFPS() { - if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::DX11) { + if (Ship::Context::GetInstance()->GetWindow()->GetWindowBackend() == Ship::WindowBackend::FAST3D_DXGI_DX11) { return CVarGetInteger("gInterpolationFPS", 20); } @@ -309,9 +308,6 @@ struct ExtensionEntry { std::string ext; }; -extern uintptr_t clearMtx; -extern "C" Mtx gMtxClear; -extern "C" MtxF gMtxFClear; extern "C" void OTRMessage_Init(); extern "C" void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len); @@ -478,7 +474,6 @@ extern "C" void InitOTR() { GfxPatcher_ApplyNecessaryAuthenticPatches(); DebugConsole_Init(); - clearMtx = (uintptr_t)&gMtxClear; OTRMessage_Init(); OTRAudio_Init(); // OTRExtScanner(); @@ -949,8 +944,8 @@ extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) { if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::DisplayList)) return (char*)&((std::static_pointer_cast<LUS::DisplayList>(res))->Instructions[0]); - else if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::Array)) - return (char*)(std::static_pointer_cast<LUS::Array>(res))->Vertices.data(); + else if (res->GetInitData()->Type == static_cast<uint32_t>(SOH::ResourceType::SOH_Array)) + return (char*)(std::static_pointer_cast<SOH::Array>(res))->Vertices.data(); else { return (char*)ResourceGetDataByName(filePath); } @@ -1063,30 +1058,30 @@ extern "C" void ResourceMgr_UnpatchGfxByName(const char* path, const char* patch } extern "C" char* ResourceMgr_LoadVtxArrayByName(const char* path) { - auto res = std::static_pointer_cast<LUS::Array>(GetResourceByName(path)); + auto res = std::static_pointer_cast<SOH::Array>(GetResourceByName(path)); return (char*)res->Vertices.data(); } extern "C" size_t ResourceMgr_GetVtxArraySizeByName(const char* path) { - auto res = std::static_pointer_cast<LUS::Array>(GetResourceByName(path)); + auto res = std::static_pointer_cast<SOH::Array>(GetResourceByName(path)); return res->Vertices.size(); } extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { - auto res = std::static_pointer_cast<LUS::Array>(GetResourceByName(path)); + auto res = std::static_pointer_cast<SOH::Array>(GetResourceByName(path)); return (char*)res->Scalars.data(); } extern "C" size_t ResourceMgr_GetArraySizeByName(const char* path) { - auto res = std::static_pointer_cast<LUS::Array>(GetResourceByName(path)); + auto res = std::static_pointer_cast<SOH::Array>(GetResourceByName(path)); return res->Scalars.size(); } extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { - auto res = std::static_pointer_cast<LUS::Array>(GetResourceByName(path)); + auto res = std::static_pointer_cast<SOH::Array>(GetResourceByName(path)); // if (res->CachedGameAsset != nullptr) // return (char*)res->CachedGameAsset; diff --git a/mm/2s2h/resource/importer/ArrayFactory.cpp b/mm/2s2h/resource/importer/ArrayFactory.cpp new file mode 100644 index 000000000..9772da149 --- /dev/null +++ b/mm/2s2h/resource/importer/ArrayFactory.cpp @@ -0,0 +1,64 @@ +#include "2s2h/resource/importer/ArrayFactory.h" +#include "2s2h/resource/type/Array.h" +#include "spdlog/spdlog.h" +#include "graphic/Fast3D/lus_gbi.h" + +namespace SOH { +std::shared_ptr<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto array = std::make_shared<Array>(file->InitData); + auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader); + + array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); + array->ArrayCount = reader->ReadUInt32(); + + for (uint32_t i = 0; i < array->ArrayCount; i++) { + if (array->ArrayType == ArrayResourceType::Vertex) { + // OTRTODO: Implement Vertex arrays as just a vertex resource. + F3DVtx data; + data.v.ob[0] = reader->ReadInt16(); + data.v.ob[1] = reader->ReadInt16(); + data.v.ob[2] = reader->ReadInt16(); + data.v.flag = reader->ReadUInt16(); + data.v.tc[0] = reader->ReadInt16(); + data.v.tc[1] = reader->ReadInt16(); + data.v.cn[0] = reader->ReadUByte(); + data.v.cn[1] = reader->ReadUByte(); + data.v.cn[2] = reader->ReadUByte(); + data.v.cn[3] = reader->ReadUByte(); + array->Vertices.push_back(data); + } else { + array->ArrayScalarType = (ScalarType)reader->ReadUInt32(); + + int iter = 1; + + if (array->ArrayType == ArrayResourceType::Vector) { + iter = reader->ReadUInt32(); + } + + for (int k = 0; k < iter; k++) { + ScalarData data; + + switch (array->ArrayScalarType) { + case ScalarType::ZSCALAR_S16: + data.s16 = reader->ReadInt16(); + break; + case ScalarType::ZSCALAR_U16: + data.u16 = reader->ReadUInt16(); + break; + default: + // OTRTODO: IMPLEMENT OTHER TYPES! + break; + } + + array->Scalars.push_back(data); + } + } + } + + return array; +} +} // namespace SOH
\ No newline at end of file diff --git a/mm/2s2h/resource/importer/ArrayFactory.h b/mm/2s2h/resource/importer/ArrayFactory.h new file mode 100644 index 000000000..fcd307a4e --- /dev/null +++ b/mm/2s2h/resource/importer/ArrayFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SOH { +class ResourceFactoryBinaryArrayV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override; +}; +} // namespace SOH
\ No newline at end of file diff --git a/mm/2s2h/resource/type/2shResourceType.h b/mm/2s2h/resource/type/2shResourceType.h index 4524ba88c..418e9b82f 100644 --- a/mm/2s2h/resource/type/2shResourceType.h +++ b/mm/2s2h/resource/type/2shResourceType.h @@ -2,6 +2,7 @@ namespace SOH { enum class ResourceType { + SOH_Array = 0x4F415252, // OARR SOH_Animation = 0x4F414E4D, // OANM SOH_PlayerAnimation = 0x4F50414D, // OPAM SOH_Room = 0x4F524F4D, // OROM diff --git a/mm/2s2h/resource/type/Array.cpp b/mm/2s2h/resource/type/Array.cpp new file mode 100644 index 000000000..7a9e40dc1 --- /dev/null +++ b/mm/2s2h/resource/type/Array.cpp @@ -0,0 +1,46 @@ +#include "Array.h" +#include "graphic/Fast3D/lus_gbi.h" + +namespace SOH { +Array::Array() : Resource(std::shared_ptr<Ship::ResourceInitData>()) { +} + +void* Array::GetPointer() { + void* dataPointer = nullptr; + switch (ArrayType) { + case ArrayResourceType::Vertex: + dataPointer = Vertices.data(); + break; + case ArrayResourceType::Scalar: + default: + dataPointer = Scalars.data(); + break; + } + + return dataPointer; +} + +size_t Array::GetPointerSize() { + size_t typeSize = 0; + switch (ArrayType) { + case ArrayResourceType::Vertex: + typeSize = sizeof(F3DVtx); + break; + case ArrayResourceType::Scalar: + default: + switch (ArrayScalarType) { + case ScalarType::ZSCALAR_S16: + typeSize = sizeof(int16_t); + break; + case ScalarType::ZSCALAR_U16: + typeSize = sizeof(uint16_t); + break; + default: + // OTRTODO: IMPLEMENT OTHER TYPES! + break; + } + break; + } + return ArrayCount * typeSize; +} +} // namespace SOH
\ No newline at end of file diff --git a/mm/2s2h/resource/type/Array.h b/mm/2s2h/resource/type/Array.h new file mode 100644 index 000000000..656b11194 --- /dev/null +++ b/mm/2s2h/resource/type/Array.h @@ -0,0 +1,85 @@ +#pragma once + +#include "Resource.h" + +union F3DVtx; +namespace SOH { +typedef union ScalarData { + uint8_t u8; + int8_t s8; + uint16_t u16; + int16_t s16; + uint32_t u32; + int32_t s32; + uint64_t u64; + int64_t s64; + float f32; + double f64; +} ScalarData; + +enum class ScalarType { + ZSCALAR_NONE, + ZSCALAR_S8, + ZSCALAR_U8, + ZSCALAR_X8, + ZSCALAR_S16, + ZSCALAR_U16, + ZSCALAR_X16, + ZSCALAR_S32, + ZSCALAR_U32, + ZSCALAR_X32, + ZSCALAR_S64, + ZSCALAR_U64, + ZSCALAR_X64, + ZSCALAR_F32, + ZSCALAR_F64 +}; + +// OTRTODO: Replace this with something that can be shared between the exporter and importer... +enum class ArrayResourceType { + Error, + Animation, + Array, + AltHeader, + Background, + Blob, + CollisionHeader, + Cutscene, + DisplayList, + Limb, + LimbTable, + Mtx, + Path, + PlayerAnimationData, + Room, + RoomCommand, + Scalar, + Scene, + Skeleton, + String, + Symbol, + Texture, + TextureAnimation, + TextureAnimationParams, + Vector, + Vertex, + Audio +}; + +class Array : public Ship::Resource<void> { + public: + using Resource::Resource; + + Array(); + + void* GetPointer() override; + size_t GetPointerSize() override; + + ArrayResourceType ArrayType; + ScalarType ArrayScalarType; + size_t ArrayCount; + // OTRTODO: Should be a vector of resource pointers... + std::vector<ScalarData> Scalars; + std::vector<F3DVtx> Vertices; +}; +} // namespace SOH
\ No newline at end of file diff --git a/mm/src/code/stubs.c b/mm/src/code/stubs.c index 35de8a506..dea4cedb9 100644 --- a/mm/src/code/stubs.c +++ b/mm/src/code/stubs.c @@ -92,8 +92,6 @@ u64 rspbootTextEnd[1]; u64 njpgdspMainTextStart[1]; u64 njpgdspMainDataStart[1]; -Mtx gMtxClear; - u8 gPictoPhotoI8[PICTO_PHOTO_SIZE]; u8 D_80784600[0x56200]; |
