From 5b522ddd1b6d7faef6d99a9f7d91765dbfe03b7b Mon Sep 17 00:00:00 2001 From: MikeIsAStar <99037623+MikeIsAStar@users.noreply.github.com> Date: Sat, 2 Mar 2024 23:55:00 -0500 Subject: [PATCH] [MKW] Avoid depending on the 'ItemDirector' class to assess the behaviour of items --- payload/import/mkw/item.hpp | 57 +++++++++++++++---------------------- payload/wwfcSecurity.cpp | 10 ------- 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/payload/import/mkw/item.hpp b/payload/import/mkw/item.hpp index 59bf2cc..79298f9 100644 --- a/payload/import/mkw/item.hpp +++ b/payload/import/mkw/item.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace mkw::Item { @@ -49,40 +49,30 @@ enum class ItemObject { NoObject = 0x10, }; -class ItemDirector -{ -public: - static ItemDirector* Instance() - { - return s_instance; - } - -private: - /* 0x000 */ u8 _000[0x430 - 0x000]; - - static ItemDirector* s_instance - AT(RMCXD_PORT(0x809C3618, 0x809BEE20, 0x809C2678, 0x809B1C58)); -}; - -static_assert(sizeof(ItemDirector) == 0x430); - -// https://github.com/SeekyCt/mkw-structures/blob/master/itembehaviour.h -struct ItemBehaviourEntry { +struct ItemBehaviour { enum class UseType { Use = 0, Throw = 1, + Trail = 2, + Circle = 3, }; - /* 0x00 */ u8 _00[0x14 - 0x00]; - /* 0x14 */ UseType useType; - /* 0x18 */ void (*useFunction)(void* kartItem); -}; - -static_assert(sizeof(ItemBehaviourEntry) == 0x1C); + static constexpr UseType s_useType[0x13] = { + UseType::Throw, UseType::Throw, UseType::Throw, UseType::Throw, + UseType::Use, UseType::Use, UseType::Throw, UseType::Throw, + UseType::Use, UseType::Use, UseType::Use, UseType::Use, + UseType::Use, UseType::Use, UseType::Use, UseType::Use, + UseType::Circle, UseType::Circle, UseType::Trail, + }; -extern ItemBehaviourEntry itemBehaviourTable[0x13] AT( - RMCXD_PORT(0x809C36A0, 0x809BEE98, 0x809C2700, 0x809B1CE0) -); + static constexpr bool s_hasUseFunction[0x13] = { + false, false, false, false, // + true, true, false, true, // + true, true, true, true, // + true, true, true, true, // + false, false, false, + }; +}; static bool IsItemValid(ItemBox item) { @@ -132,8 +122,7 @@ static bool CanUseItem(ItemBox item) u8 itemToUse = static_cast(item); - return itemBehaviourTable[itemToUse].useType == - ItemBehaviourEntry::UseType::Use; + return ItemBehaviour::s_useType[itemToUse] == ItemBehaviour::UseType::Use; } static bool CanThrowItem(ItemBox item) @@ -144,8 +133,8 @@ static bool CanThrowItem(ItemBox item) u8 itemToThrow = static_cast(item); - return itemBehaviourTable[itemToThrow].useType == - ItemBehaviourEntry::UseType::Throw; + return ItemBehaviour::s_useType[itemToThrow] == + ItemBehaviour::UseType::Throw; } static bool CanTrailItem(ItemBox item) @@ -156,7 +145,7 @@ static bool CanTrailItem(ItemBox item) u8 itemToTrail = static_cast(item); - return !itemBehaviourTable[itemToTrail].useFunction; + return !ItemBehaviour::s_hasUseFunction[itemToTrail]; } static bool CanHitItemObject(ItemObject itemObject) diff --git a/payload/wwfcSecurity.cpp b/payload/wwfcSecurity.cpp index 40db203..f2629a2 100644 --- a/payload/wwfcSecurity.cpp +++ b/payload/wwfcSecurity.cpp @@ -441,11 +441,6 @@ IsItemPacketDataValid(const void* packet, u8 packetSize, u8 /* playerAid */) if (!NetController::Instance()->inVanillaRaceScene()) { return true; } - // Ensure that the table which controls the behaviour of items is loaded - // into memory before attempting to use it. - if (!mkw::Item::ItemDirector::Instance()) { - return true; - } RaceConfig::Scenario* scenario = &RaceConfig::Instance()->raceScenario(); @@ -511,11 +506,6 @@ static bool IsEventPacketDataValid( ) != RKScene::SceneID::Race) { return true; } - // Ensure that the table which controls the behaviour of items is loaded - // into memory before attempting to use it. - if (!mkw::Item::ItemDirector::Instance()) { - return true; - } const EventHandler::Packet* eventPacket = reinterpret_cast(packet);