diff --git a/.gitignore b/.gitignore index ea727993..343c32e3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ main.elf perf.mData perf.mData.old .gdb_history + +.DS_Store +tools/aarch64-none-elf-objdump \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b1a20e67..fbc8550c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_executable(uking + src/Game/Action/actionSetInstEventFlag.cpp + src/Game/Action/actionSetInstEventFlag.h src/Game/Action/actionSetLinkTagBasic.cpp src/Game/Action/actionSetLinkTagBasic.h @@ -31,6 +33,8 @@ add_executable(uking src/KingSystem/ActorSystem/actAiParam.h src/KingSystem/ActorSystem/actBaseProc.cpp src/KingSystem/ActorSystem/actBaseProc.h + src/KingSystem/ActorSystem/actBaseProcHandle.cpp + src/KingSystem/ActorSystem/actBaseProcHandle.h src/KingSystem/ActorSystem/actBaseProcJob.cpp src/KingSystem/ActorSystem/actBaseProcJob.h src/KingSystem/ActorSystem/actBaseProcJobHandler.cpp diff --git a/data/uking_functions.csv b/data/uking_functions.csv index dded5f3a..43f1d3e7 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -15405,9 +15405,9 @@ 0x0000007100249614,AI_Action_SetInstantTemperture::loadParams,4, 0x0000007100249618,AI_Action_SetInstantTemperture::rtti1,288, 0x0000007100249738,AI_Action_SetInstantTemperture::rtti2,92, -0x0000007100249794,AI_Action_SetInstEventFlag::ctor,48, -0x00000071002497c4,AI_Action_SetInstEventFlag::dtor,20, -0x00000071002497d8,AI_Action_SetInstEventFlag::dtorDelete,52, +0x0000007100249794,AI_Action_SetInstEventFlag::ctor,48,_ZN5uking6action22SetInstEventFlagActionC1ERKN4ksys3act2ai8ClassArgE +0x00000071002497c4,AI_Action_SetInstEventFlag::dtor,20,_ZN5uking6action22SetInstEventFlagActionD1Ev +0x00000071002497d8,AI_Action_SetInstEventFlag::dtorDelete,52,_ZN5uking6action22SetInstEventFlagActionD0Ev 0x000000710024980c,AI_Action_SetInstEventFlag::init,8, 0x0000007100249814,AI_Action_SetInstEventFlag::oneShot,28, 0x0000007100249830,AI_Action_SetInstEventFlag::loadParams,4, @@ -89504,22 +89504,22 @@ 0x00000071011bb7f4,sub_71011BB7F4,52, 0x00000071011bb828,sub_71011BB828,92, 0x00000071011bb884,sub_71011BB884,32, -0x00000071011bb8a4,BaseProcHandle::ctor,12, -0x00000071011bb8b0,BaseProcHandle::actorReady,32, +0x00000071011bb8a4,BaseProcHandle::ctor,12,_ZN4ksys3act14BaseProcHandleC1Ev +0x00000071011bb8b0,BaseProcHandle::actorReady,32,_ZN4ksys3act14BaseProcHandle9procReadyEv 0x00000071011bb8d0,BaseProcHandle::hasActorAndFlags5,84, 0x00000071011bb924,BaseProcHandle::x,52, 0x00000071011bb958,BaseProcHandle::deleteActor,112, -0x00000071011bb9c8,BaseProcHandle::dtor,56, +0x00000071011bb9c8,BaseProcHandle::dtor,56,_ZN4ksys3act14BaseProcHandleD1Ev 0x00000071011bba00,BaseProcUnit::deleteActor,316, -0x00000071011bbb3c,BaseProcHandle::getActor,24, +0x00000071011bbb3c,BaseProcHandle::getActor,24,_ZN4ksys3act14BaseProcHandle7getProcEv 0x00000071011bbb54,BaseProcHandle::setProcStateFlag8000,184, 0x00000071011bbc0c,BaseProcHandle::wakeUpActorAndReleaseUnit,184, 0x00000071011bbcc4,BaseProcHandle::getBaseProcEvent,48, 0x00000071011bbcf4,BaseProcHandle::allocUnit,228, -0x00000071011bbdd8,BaseProcUnit::setActor,540, +0x00000071011bbdd8,BaseProcUnit::setActor,540,_ZN4ksys3act12BaseProcUnit7setProcEPNS0_8BaseProcE 0x00000071011bbff4,BaseProcUnit::cleanUp,512, 0x00000071011bc1f4,BaseProcUnit::unlinkActor,412, -0x00000071011bc390,BaseProcUnit::isParentHandleDefault,24, +0x00000071011bc390,BaseProcUnit::isParentHandleDefault,24,_ZNK4ksys3act12BaseProcUnit21isParentHandleDefaultEv 0x00000071011bc3a8,sub_71011BC3A8,132, 0x00000071011bc42c,sub_71011BC42C,56, 0x00000071011bc464,sinitBaseProcHandle,172, diff --git a/src/Game/Action/actionSetInstEventFlag.cpp b/src/Game/Action/actionSetInstEventFlag.cpp new file mode 100644 index 00000000..bc179765 --- /dev/null +++ b/src/Game/Action/actionSetInstEventFlag.cpp @@ -0,0 +1,11 @@ +#include "Game/Action/actionSetInstEventFlag.h" +#include "KingSystem/ActorSystem/actActor.h" + +namespace uking::action { + +SetInstEventFlagAction::SetInstEventFlagAction(const ksys::act::ai::ClassArg& arg) + : ksys::act::ai::Action(arg) {} + +SetInstEventFlagAction::~SetInstEventFlagAction() = default; + +} // namespace uking::action \ No newline at end of file diff --git a/src/Game/Action/actionSetInstEventFlag.h b/src/Game/Action/actionSetInstEventFlag.h new file mode 100644 index 00000000..7dac0a32 --- /dev/null +++ b/src/Game/Action/actionSetInstEventFlag.h @@ -0,0 +1,18 @@ +#pragma once + +#include "KingSystem/ActorSystem/actAiAction.h" +#include "KingSystem/ActorSystem/actAiParam.h" +#include "KingSystem/Utils/Types.h" + +namespace uking::action { + +class SetInstEventFlagAction : public ksys::act::ai::Action { +public: + SetInstEventFlagAction(const ksys::act::ai::ClassArg& arg); + ~SetInstEventFlagAction() override; + + void oneShot() override; +}; +KSYS_CHECK_SIZE_NX150(SetInstEventFlagAction, 0x20); + +} // namespace uking::action \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actAiAction.h b/src/KingSystem/ActorSystem/actAiAction.h index be96de6d..ba0bf61d 100644 --- a/src/KingSystem/ActorSystem/actAiAction.h +++ b/src/KingSystem/ActorSystem/actAiAction.h @@ -11,6 +11,8 @@ public: virtual void enter() {} virtual void loadParams() {} + + virtual void oneShot() {} }; KSYS_CHECK_SIZE_NX150(Action, 0x20); diff --git a/src/KingSystem/ActorSystem/actBaseProc.h b/src/KingSystem/ActorSystem/actBaseProc.h index 1c9aa7cc..c7636998 100644 --- a/src/KingSystem/ActorSystem/actBaseProc.h +++ b/src/KingSystem/ActorSystem/actBaseProc.h @@ -9,6 +9,7 @@ #include #include #include +#include "KingSystem/ActorSystem/actBaseProcHandle.h" #include "KingSystem/ActorSystem/actBaseProcJob.h" #include "KingSystem/ActorSystem/actBaseProcMap.h" #include "KingSystem/Utils/StrTreeMap.h" @@ -23,17 +24,7 @@ class BaseProc; class BaseProcLinkData; class BaseProcJobHandler; class BaseProcUnit; - -class BaseProcHandle { -public: - BaseProcHandle(); - ~BaseProcHandle(); - -private: - BaseProcUnit* mUnit; - u8 mFlag; -}; -KSYS_CHECK_SIZE_NX150(BaseProcHandle, 0x10); +class BaseProcHandle; /// Actor base class that encapsulates all the low-level actor lifetime logic. class BaseProc { @@ -100,6 +91,7 @@ public: return mState == State::Delete || mStateFlags.isOn(StateFlags::RequestDelete); } + bool isInitialized() const { return mFlags.isOn(Flags::Initialized); } /// For BaseProcLink or ActorLinkConstDataAccess. bool acquire(ActorLinkConstDataAccess& accessor); BaseProcLinkData* getBaseProcLinkData() const { return mBaseProcLinkData; } diff --git a/src/KingSystem/ActorSystem/actBaseProcHandle.cpp b/src/KingSystem/ActorSystem/actBaseProcHandle.cpp new file mode 100644 index 00000000..5603b5be --- /dev/null +++ b/src/KingSystem/ActorSystem/actBaseProcHandle.cpp @@ -0,0 +1,29 @@ +#include "KingSystem/ActorSystem/actBaseProcHandle.h" + +namespace ksys::act { + +BaseProcHandle::BaseProcHandle() { + mUnit = nullptr; + mFlag = 0; +} + +BaseProcHandle::~BaseProcHandle() { + if (mUnit) { + mUnit->deleteProc(0, this); + mUnit = nullptr; + } + mFlag = 0; +} + +bool BaseProcHandle::procReady() { + return mUnit && mUnit->isReady(); +} + +BaseProc* BaseProcHandle::getProc() { + if (mUnit) + return mUnit->getProc(); + + return nullptr; +} + +} // namespace ksys::act \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actBaseProcHandle.h b/src/KingSystem/ActorSystem/actBaseProcHandle.h new file mode 100644 index 00000000..c0a74ee0 --- /dev/null +++ b/src/KingSystem/ActorSystem/actBaseProcHandle.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include "KingSystem/ActorSystem/actBaseProc.h" +#include "KingSystem/ActorSystem/actBaseProcUnit.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::act { + +class BaseProcUnit; +class BaseProc; + +class BaseProcHandle { +public: + BaseProcHandle(); + ~BaseProcHandle(); + + bool procReady(); + + BaseProc* getProc(); + + static BaseProcHandle sDummyHandle; + +private: + BaseProcUnit* mUnit; + u8 mFlag; +}; +KSYS_CHECK_SIZE_NX150(BaseProcHandle, 0x10); + +} // namespace ksys::act \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actBaseProcUnit.cpp b/src/KingSystem/ActorSystem/actBaseProcUnit.cpp index e69de29b..09bd6c81 100644 --- a/src/KingSystem/ActorSystem/actBaseProcUnit.cpp +++ b/src/KingSystem/ActorSystem/actBaseProcUnit.cpp @@ -0,0 +1,58 @@ +#include "KingSystem/ActorSystem/actBaseProcUnit.h" +#include +#include +#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h" +#include "KingSystem/ActorSystem/actBaseProc.h" +#include "KingSystem/Utils/Debug.h" + +namespace ksys::act { + +// NON_MATCHING: Equivalent but branches are off. +bool BaseProcUnit::setProc(BaseProc* proc) { + bool ret; + static constexpr const char* sStateNames[] = {"Init", "Calc", "Sleep", "Delete"}; + + auto lock = sead::makeScopedLock(mCS); + if (mProc) + mProc = nullptr; + + if (mHandle == &BaseProcHandle::sDummyHandle) + return false; + + if (mHandle) { + if (mFlags != 1) { + sead::FixedSafeString<64> message; + + if (proc) + message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags, + proc->isInitialized(), sStateNames[u8(proc->getState())], this, + mHandle.load()); + else + message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load()); + + util::PrintDebug(message); + } + mProc = proc; + mFlags = 2; + ret = true; + } else { + sead::FixedSafeString<64> message; + + if (proc) + message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags, + proc->isInitialized(), sStateNames[u8(proc->getState())], this, + mHandle.load()); + else + message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load()); + + util::PrintDebug(message); + ret = false; + } + return ret; +} + +bool BaseProcUnit::isParentHandleDefault() const { + return mHandle == &BaseProcHandle::sDummyHandle; +} + +} // namespace ksys::act \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actBaseProcUnit.h b/src/KingSystem/ActorSystem/actBaseProcUnit.h index 7bfe7e28..f3ef3f34 100644 --- a/src/KingSystem/ActorSystem/actBaseProcUnit.h +++ b/src/KingSystem/ActorSystem/actBaseProcUnit.h @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include "KingSystem/ActorSystem/actBaseProcHandle.h" namespace ksys::act { @@ -10,15 +12,18 @@ class BaseProcHandle; class BaseProcUnit { public: - bool deleteProc(void*, BaseProcHandle* handle); + bool deleteProc(u32, BaseProcHandle* handle); bool setProc(BaseProc* proc); void unlinkProc(BaseProc* proc); void cleanUp(BaseProc* proc, bool set_flag_5); bool isParentHandleDefault() const; + BaseProc* getProc() const { return mProc; } + bool isReady() const { return mFlags == 2; } + private: u32 mFlags; - BaseProcHandle* mHandle; + sead::Atomic mHandle; BaseProc* mProc; // FIXME: // BaseProcRequest mRequest;