From 729a6291b6d1ee2fa5bf7394d555f1c48d74b880 Mon Sep 17 00:00:00 2001 From: ecumber Date: Sat, 19 Nov 2022 11:41:58 -0800 Subject: [PATCH] Add NXArgs --- data/uking_functions.csv | 8 +-- lib/NintendoSDK | 2 +- src/KingSystem/System/CMakeLists.txt | 2 + src/KingSystem/System/NXArgs.cpp | 78 ++++++++++++++++++++++ src/KingSystem/System/NXArgs.h | 99 ++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 src/KingSystem/System/NXArgs.cpp create mode 100644 src/KingSystem/System/NXArgs.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 728be7ce..ba833e2f 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -54193,12 +54193,12 @@ Address,Quality,Size,Name 0x0000007100901a90,U,000068, 0x0000007100901ad4,U,000100, 0x0000007100901b38,U,000108, -0x0000007100901ba4,U,000164,nxargs::createInstance +0x0000007100901ba4,O,000164,_ZN4ksys6nxargs14createInstanceEPN4sead4HeapE 0x0000007100901c48,U,000152,nxargs::dtor 0x0000007100901ce0,U,000148,nxargs::dtorDelete -0x0000007100901d74,U,000804,nxargs::init -0x0000007100902098,U,000632,nxargs::allocEntries -0x0000007100902310,U,003168,nxargs::handleArgs +0x0000007100901d74,O,000804,_ZN4ksys6nxargs4initEPN4sead4HeapE +0x0000007100902098,O,000632,_ZN4ksys6nxargs12allocEntriesEPN4sead4HeapEPKh +0x0000007100902310,W,003168,_ZN4ksys6nxargs10handleArgsEv 0x0000007100902f70,U,000004,j__ZdlPv_410 0x0000007100902f74,U,000240,_ZN4sead15FixedSafeStringILi37EEaSERKNS_14SafeStringBaseIcEE 0x0000007100903064,U,000004,j__ZdlPv_411 diff --git a/lib/NintendoSDK b/lib/NintendoSDK index 3077c49a..00bb399f 160000 --- a/lib/NintendoSDK +++ b/lib/NintendoSDK @@ -1 +1 @@ -Subproject commit 3077c49affa2770c5336764ca062ed50e7444b5b +Subproject commit 00bb399f3c0169d77044f857f39ba9e04a896fde diff --git a/src/KingSystem/System/CMakeLists.txt b/src/KingSystem/System/CMakeLists.txt index 644a2875..1a53e941 100644 --- a/src/KingSystem/System/CMakeLists.txt +++ b/src/KingSystem/System/CMakeLists.txt @@ -23,6 +23,8 @@ target_sources(uking PRIVATE MemoryProfiler.h MessageCapture.cpp MessageCapture.h + NXArgs.cpp + NXArgs.h OcclusionQueryCylinder.cpp OcclusionQueryCylinder.h OverlayArena.cpp diff --git a/src/KingSystem/System/NXArgs.cpp b/src/KingSystem/System/NXArgs.cpp new file mode 100644 index 00000000..46df7f39 --- /dev/null +++ b/src/KingSystem/System/NXArgs.cpp @@ -0,0 +1,78 @@ +#include "KingSystem/System/NXArgs.h" + +namespace ksys { + +SEAD_SINGLETON_DISPOSER_IMPL(nxargs) + +void nxargs::init(sead::Heap* heap) { + sead::Heap* nxargsheap = sead::ExpHeap::create( + 0x13E8, "nxargsHeap", heap, 8, sead::ExpHeap::HeapDirection::cHeapDirection_Reverse, false); + auto* data = new (nxargsheap) u8[0x1000]; + size_t unknown; + + while (nn::oe::TryPopLaunchParameter(&unknown, data, 0x1000)) { + { + sead::FixedSafeString<5> inputmagic(""); + inputmagic.format("%s", reinterpret_cast(data)); + if (inputmagic != "BotW") + continue; + } + using sead::BitUtil::bitCastPtr; + mResField4 = bitCastPtr(data, 4); + mResField6 = bitCastPtr(data, 6); + mType = bitCastPtr(data, 7); + if (mType == ArgsType::CreateActors) { + mNumEntries = bitCastPtr(data, 0xC); + nxargs::allocEntries(heap, data); + } else { + mType = ArgsType::None; + } + break; + } + nxargsheap->destroy(); +} + +void nxargs::allocEntries(sead::Heap* heap, const u8* data) { + const s32 size = mNumEntries; + + if (mNumEntries == 0) + return; + mEntries.allocBufferAssert(size, heap); + + using sead::BitUtil::bitCastPtr; + u32 offset = 0x10; + for (u8 i = 0; i < mNumEntries; i++) { + LaunchParamEntry* currEntry = &mEntries[i]; + currEntry->actorNameHash = bitCastPtr(data, offset + 0); + currEntry->dropActorNameHash = bitCastPtr(data, offset + 4); + currEntry->positionOffset.x = bitCastPtr(data, offset + 8); + currEntry->positionOffset.y = bitCastPtr(data, offset + 0xc); + currEntry->positionOffset.z = bitCastPtr(data, offset + 0x10); + currEntry->rotation.x = bitCastPtr(data, offset + 0x14); + currEntry->rotation.y = bitCastPtr(data, offset + 0x18); + currEntry->rotation.z = bitCastPtr(data, offset + 0x1c); + currEntry->velocity.x = bitCastPtr(data, offset + 0x20); + currEntry->velocity.y = bitCastPtr(data, offset + 0x24); + currEntry->velocity.z = bitCastPtr(data, offset + 0x28); + currEntry->flags = bitCastPtr(data, offset + 0x2c); + s64 numConditions = bitCastPtr(data, offset + 0x2d); + currEntry->numConditions = numConditions; + offset += 0x30; + + if (numConditions > 0) { + currEntry->conditions.allocBufferAssert(numConditions, heap); + for (u8 j = 0; j < currEntry->numConditions; j++) { + LaunchParamEntryCondition* currCondition = &currEntry->conditions[j]; + currCondition->flagNameHash = bitCastPtr(data, offset); + currCondition->flagDataType = + bitCastPtr(data, offset + 4); + currCondition->operation = + bitCastPtr(data, offset + 5); + currCondition->rhsValue = bitCastPtr(data, offset + 8); + offset += 0xc; + } + } + } +} + +} // namespace ksys \ No newline at end of file diff --git a/src/KingSystem/System/NXArgs.h b/src/KingSystem/System/NXArgs.h new file mode 100644 index 00000000..6ba6696e --- /dev/null +++ b/src/KingSystem/System/NXArgs.h @@ -0,0 +1,99 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include "KingSystem/Utils/Types.h" + +namespace ksys { + +class nxargs { + SEAD_SINGLETON_DISPOSER(nxargs) + nxargs() : mResField4{0}, mResField6{0}, mType{ArgsType::None}, mNumEntries{0} {} + virtual ~nxargs(); + +public: + enum class LaunchParamFlag : u8 { + None = 0, + HasDropActor = 1, + _2 = 2, + }; + + struct LaunchParamEntrySpawnCondition { + u32 resfield0; + u32 resfield8; + u8 resfield4; + u8 resfield5; + }; + + enum class LaunchParamEntryConditionDataType : u8 { + None = 0, + Bool = 1, + S32 = 2, + F32 = 3, + }; + + enum class ActorEntryConditionOperation : u8 { + None = 0, + Eq = 1, + NotEq = 2, + Gt = 3, + Gte = 4, + Lt = 5, + Lte = 6, + }; + + struct LaunchParamEntryCondition { + s32 flagNameHash; + f32 rhsValue; + LaunchParamEntryConditionDataType flagDataType; + ActorEntryConditionOperation operation; + }; + + struct LaunchParamEntry { + u32 actorNameHash; + u32 dropActorNameHash; + sead::Vector3f positionOffset; + sead::Vector3f rotation; + sead::Vector3f velocity; + LaunchParamFlag flags{}; + u8 numConditions; + sead::Buffer conditions; + }; + + KSYS_CHECK_SIZE_NX150(LaunchParamEntry, 0x40); + + enum class ArgsType : u8 { + None = 0, + CreateActors = 1, + }; + + struct ResLaunchParamDataHeader { + char magic[4]; + u16 _4; + u8 _6; + ArgsType type; + u32 padding; + u8 numEntries; + u8 padding2[3]; + }; + + void init(sead::Heap* heap); + void allocEntries(sead::Heap* heap, const u8* data); + void handleArgs(); + +private: + u16 mResField4; + u8 mResField6; + ArgsType mType; + u8 mNumEntries; + sead::Buffer mEntries; + bool mHasHandledArgs = false; +}; +KSYS_CHECK_SIZE_NX150(nxargs, 0x48); + +} // namespace ksys \ No newline at end of file