diff --git a/Runtime/CBasics.hpp b/Runtime/CBasics.hpp index 27bf9fb9b..91efe2819 100644 --- a/Runtime/CBasics.hpp +++ b/Runtime/CBasics.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifndef _WIN32 #include #else @@ -62,6 +63,7 @@ public: static int RecursiveMakeDir(const char* dir); static void MakeDir(const char* dir); static int Stat(const char* path, Sstat* statOut); + static inline void ToLower(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), ::tolower); } }; } // namespace metaforce diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index dcf97d62a..2da53fce2 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -23,31 +23,16 @@ union BitsToDouble { double doub; }; -/** Word Bitmap reader/writer */ -void WordBitmap::read(athena::io::IStreamReader& reader, size_t bitCount) { - m_bitCount = bitCount; - size_t wordCount = (bitCount + 31) / 32; - m_words.clear(); - m_words.reserve(wordCount); - for (size_t w = 0; w < wordCount; ++w) - m_words.push_back(reader.readUint32Big()); -} -void WordBitmap::write(athena::io::IStreamWriter& writer) const { - for (atUint32 word : m_words) - writer.writeUint32Big(word); -} -void WordBitmap::binarySize(size_t& __isz) const { __isz += m_words.size() * 4; } - CScriptLayerManager::CScriptLayerManager(CInputStream& reader, const CWorldSaveGameInfo& saveWorld) { const u32 bitCount = reader.ReadBits(10); - x10_saveLayers.reserve(bitCount); + x10_saveLayers.Reserve(bitCount); for (u32 i = 0; i < bitCount; ++i) { const bool bit = reader.ReadBits(1) != 0; if (bit) { - x10_saveLayers.setBit(i); + x10_saveLayers.SetBit(i); } else { - x10_saveLayers.unsetBit(i); + x10_saveLayers.UnsetBit(i); } } } @@ -63,7 +48,7 @@ void CScriptLayerManager::PutTo(COutputStream& writer) const { for (size_t i = 0; i < x0_areaLayers.size(); ++i) { const u32 count = GetAreaLayerCount(s32(i)); for (u32 l = 1; l < count; ++l) { - writer.WriteBits(IsLayerActive(s32(i), s32(l)), 1); + writer.WriteBits(static_cast(IsLayerActive(s32(i), s32(l))), 1); } } } @@ -74,19 +59,20 @@ void CScriptLayerManager::InitializeWorldLayers(const std::vector(reader, saveWorld); xc_mapWorldInfo = std::make_shared(reader, saveWorld, mlvlId); x14_layerState = std::make_shared(reader, saveWorld); diff --git a/Runtime/CGameState.hpp b/Runtime/CGameState.hpp index aaea9f904..a28719484 100644 --- a/Runtime/CGameState.hpp +++ b/Runtime/CGameState.hpp @@ -4,54 +4,53 @@ #include #include +#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/CBasics.hpp" #include "Runtime/CGameOptions.hpp" #include "Runtime/CPlayerState.hpp" #include "Runtime/CScriptMailbox.hpp" -#include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/World/CWorld.hpp" #include "Runtime/World/CWorldTransManager.hpp" namespace metaforce { class CSaveWorldMemory; -// TODO: copied from DataSpec, should be reimplemented class WordBitmap { - std::vector m_words; - size_t m_bitCount = 0; + std::vector x0_words; + size_t x10_bitCount = 0; public: - void read(athena::io::IStreamReader& reader, size_t bitCount); - void write(athena::io::IStreamWriter& writer) const; - void reserve(size_t bitCount) { m_words.reserve((bitCount + 31) / 32); } - void binarySize(size_t& __isz) const; - size_t getBitCount() const { return m_bitCount; } - bool getBit(size_t idx) const { + void Reserve(size_t bitCount) { x0_words.reserve((bitCount + 31) / 32); } + [[nodiscard]] size_t GetBitCount() const { return x10_bitCount; } + [[nodiscard]] bool GetBit(size_t idx) const { size_t wordIdx = idx / 32; - if (wordIdx >= m_words.size()) + if (wordIdx >= x0_words.size()) { return false; + } size_t wordCur = idx % 32; - return (m_words[wordIdx] >> wordCur) & 0x1; + return ((x0_words[wordIdx] >> wordCur) & 0x1) != 0u; } - void setBit(size_t idx) { + void SetBit(size_t idx) { size_t wordIdx = idx / 32; - while (wordIdx >= m_words.size()) - m_words.push_back(0); + while (wordIdx >= x0_words.size()) { + x0_words.push_back(0); + } size_t wordCur = idx % 32; - m_words[wordIdx] |= (1 << wordCur); - m_bitCount = std::max(m_bitCount, idx + 1); + x0_words[wordIdx] |= (1 << wordCur); + x10_bitCount = std::max(x10_bitCount, idx + 1); } - void unsetBit(size_t idx) { + void UnsetBit(size_t idx) { size_t wordIdx = idx / 32; - while (wordIdx >= m_words.size()) - m_words.push_back(0); + while (wordIdx >= x0_words.size()) { + x0_words.push_back(0); + } size_t wordCur = idx % 32; - m_words[wordIdx] &= ~(1 << wordCur); - m_bitCount = std::max(m_bitCount, idx + 1); + x0_words[wordIdx] &= ~(1 << wordCur); + x10_bitCount = std::max(x10_bitCount, idx + 1); } - void clear() { - m_words.clear(); - m_bitCount = 0; + void Clear() { + x0_words.clear(); + x10_bitCount = 0; } class Iterator { @@ -71,11 +70,11 @@ public: ++m_idx; return *this; } - bool operator*() const { return m_bmp.getBit(m_idx); } + bool operator*() const { return m_bmp.GetBit(m_idx); } bool operator!=(const Iterator& other) const { return m_idx != other.m_idx; } }; - Iterator begin() const { return Iterator(*this, 0); } - Iterator end() const { return Iterator(*this, m_bitCount); } + [[nodiscard]] Iterator begin() const { return Iterator(*this, 0); } + [[nodiscard]] Iterator end() const { return Iterator(*this, x10_bitCount); } }; class CScriptLayerManager { @@ -87,19 +86,22 @@ public: CScriptLayerManager() = default; CScriptLayerManager(CInputStream& reader, const CWorldSaveGameInfo& saveWorld); - bool IsLayerActive(int areaIdx, int layerIdx) const { return ((x0_areaLayers[areaIdx].m_layerBits >> layerIdx) & 1); } + [[nodiscard]] bool IsLayerActive(int areaIdx, int layerIdx) const { + return ((x0_areaLayers[areaIdx].m_layerBits >> layerIdx) & 1) != 0u; + } void SetLayerActive(int areaIdx, int layerIdx, bool active) { - if (active) + if (active) { x0_areaLayers[areaIdx].m_layerBits |= uint64_t(1) << layerIdx; - else + } else { x0_areaLayers[areaIdx].m_layerBits &= ~(uint64_t(1) << layerIdx); + } } void InitializeWorldLayers(const std::vector& layers); - u32 GetAreaLayerCount(int areaIdx) const { return x0_areaLayers[areaIdx].m_layerCount; } - u32 GetAreaCount() const { return x0_areaLayers.size(); } + [[nodiscard]] u32 GetAreaLayerCount(int areaIdx) const { return x0_areaLayers[areaIdx].m_layerCount; } + [[nodiscard]] u32 GetAreaCount() const { return x0_areaLayers.size(); } void PutTo(COutputStream& writer) const; }; diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 1af4c70f2..67b358741 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -31,12 +31,6 @@ using namespace std::literals; -static logvisor::Module AthenaLog("Athena"); -static void AthenaExc(athena::error::Level level, const char* file, const char*, int line, fmt::string_view fmt, - fmt::format_args args) { - AthenaLog.vreport(logvisor::Level(level), fmt, args); -} - class Limiter { using delta_clock = std::chrono::high_resolution_clock; using duration_t = std::chrono::nanoseconds; @@ -567,7 +561,6 @@ static void SetupBasics(bool logging) { logvisor::RegisterStandardExceptions(); if (logging) logvisor::RegisterConsoleLogger(); - atSetExceptionHandler(AthenaExc); #if SENTRY_ENABLED FileStoreManager fileMgr{"sentry-native-metaforce"}; diff --git a/Runtime/CPlayerState.cpp b/Runtime/CPlayerState.cpp index 45313cc83..e19fd9d1d 100644 --- a/Runtime/CPlayerState.cpp +++ b/Runtime/CPlayerState.cpp @@ -437,7 +437,7 @@ CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) { }}; std::string lowName{name}; - athena::utility::tolower(lowName); + CBasics::ToLower(lowName); const auto iter = std::find_if(typeNameMap.cbegin(), typeNameMap.cend(), [&lowName](const auto& entry) { return entry.first == lowName; }); diff --git a/Runtime/Character/CCharLayoutInfo.cpp b/Runtime/Character/CCharLayoutInfo.cpp index 8fd511d3f..65163c595 100644 --- a/Runtime/Character/CCharLayoutInfo.cpp +++ b/Runtime/Character/CCharLayoutInfo.cpp @@ -52,9 +52,9 @@ CCharLayoutNode::CCharLayoutNode(CInputStream& in) : x0_boneMap(in.ReadLong()) { } CCharLayoutInfo::CCharLayoutInfo(CInputStream& in) : x0_node(std::make_shared(in)), x8_segIdList(in) { - const atUint32 mapCount = in.ReadLong(); + const u32 mapCount = in.ReadLong(); - for (atUint32 i = 0; i < mapCount; ++i) { + for (u32 i = 0; i < mapCount; ++i) { std::string key = in.Get(); x18_segIdMap.emplace(std::move(key), in); } diff --git a/Runtime/ConsoleVariables/CVar.cpp b/Runtime/ConsoleVariables/CVar.cpp index d5d8499a4..2125174cf 100644 --- a/Runtime/ConsoleVariables/CVar.cpp +++ b/Runtime/ConsoleVariables/CVar.cpp @@ -1,10 +1,63 @@ #include "Runtime/ConsoleVariables/CVar.hpp" +#include "Runtime/CBasics.hpp" + +#include #include #include "Runtime/ConsoleVariables/CVarManager.hpp" namespace metaforce { +namespace { +// TODO: Move these to CBasics? +inline bool parseBool(std::string_view boolean, bool* valid) { + std::string val(boolean); + // compare must be case insensitive + // This is the cleanest solution since I only need to do it once + CBasics::ToLower(val); + + // Check for true first + if (val == "true" || val == "1" || val == "yes" || val == "on") { + if (valid) + *valid = true; + + return true; + } + + // Now false + if (val == "false" || val == "0" || val == "no" || val == "off") { + if (valid) + *valid = true; + + return false; + } + + // Well that could've gone better + + if (valid) + *valid = false; + + return false; +} + +static std::vector& split(std::string_view s, char delim, std::vector& elems) { + std::string tmps(s); + std::stringstream ss(tmps); + std::string item; + + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + + return elems; +} + +std::vector split(std::string_view s, char delim) { + std::vector elems; + split(s, delim, elems); + return elems; +} +} extern CVar* com_developer; extern CVar* com_enableCheats; @@ -197,7 +250,7 @@ bool CVar::toBoolean(bool* isValid) const { return false; } - return athena::utility::parseBool(m_value, isValid); + return parseBool(m_value, isValid); } int32_t CVar::toSigned(bool* isValid) const { @@ -441,12 +494,12 @@ bool isReal(const std::vector& v) { } bool CVar::isValidInput(std::string_view input) const { - std::vector parts = athena::utility::split(input, ' '); + std::vector parts = split(input, ' '); char* p; switch (m_type) { case EType::Boolean: { bool valid = false; - athena::utility::parseBool(input, &valid); + parseBool(input, &valid); return valid; } case EType::Signed: diff --git a/Runtime/ConsoleVariables/CVar.hpp b/Runtime/ConsoleVariables/CVar.hpp index 4a8d6d762..215afd1a0 100644 --- a/Runtime/ConsoleVariables/CVar.hpp +++ b/Runtime/ConsoleVariables/CVar.hpp @@ -6,40 +6,6 @@ #include #include #include -#ifndef ENABLE_BITWISE_ENUM -#define ENABLE_BITWISE_ENUM(type) \ - constexpr type operator|(type a, type b) noexcept { \ - using T = std::underlying_type_t; \ - return type(static_cast(a) | static_cast(b)); \ - } \ - constexpr type operator&(type a, type b) noexcept { \ - using T = std::underlying_type_t; \ - return type(static_cast(a) & static_cast(b)); \ - } \ - constexpr type& operator|=(type& a, type b) noexcept { \ - using T = std::underlying_type_t; \ - a = type(static_cast(a) | static_cast(b)); \ - return a; \ - } \ - constexpr type& operator&=(type& a, type b) noexcept { \ - using T = std::underlying_type_t; \ - a = type(static_cast(a) & static_cast(b)); \ - return a; \ - } \ - constexpr type operator~(type key) noexcept { \ - using T = std::underlying_type_t; \ - return type(~static_cast(key)); \ - } \ - constexpr bool True(type key) noexcept { \ - using T = std::underlying_type_t; \ - return static_cast(key) != 0; \ - } \ - constexpr bool False(type key) noexcept { \ - using T = std::underlying_type_t; \ - return static_cast(key) == 0; \ - } -#endif - namespace metaforce { namespace StoreCVar { enum class EType : uint32_t { Boolean, Signed, Unsigned, Real, Literal, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d }; diff --git a/Runtime/ConsoleVariables/CVarManager.cpp b/Runtime/ConsoleVariables/CVarManager.cpp index 2d3033f58..a20daa10c 100644 --- a/Runtime/ConsoleVariables/CVarManager.cpp +++ b/Runtime/ConsoleVariables/CVarManager.cpp @@ -1,6 +1,7 @@ #include "Runtime/ConsoleVariables/CVarManager.hpp" #include "Runtime/ConsoleVariables/FileStoreManager.hpp" +#include "Runtime/CBasics.hpp" #include #include @@ -37,7 +38,7 @@ CVarManager::~CVarManager() {} CVar* CVarManager::registerCVar(std::unique_ptr&& cvar) { std::string tmp(cvar->name()); - athena::utility::tolower(tmp); + CBasics::ToLower(tmp); if (m_cvars.find(tmp) != m_cvars.end()) { return nullptr; @@ -50,7 +51,7 @@ CVar* CVarManager::registerCVar(std::unique_ptr&& cvar) { CVar* CVarManager::findCVar(std::string_view name) { std::string lower(name); - athena::utility::tolower(lower); + CBasics::ToLower(lower); auto search = m_cvars.find(lower); if (search == m_cvars.end()) return nullptr; @@ -85,7 +86,7 @@ void CVarManager::deserialize(CVar* cvar) { /* First let's check for a deferred value */ std::string lowName = cvar->name().data(); - athena::utility::tolower(lowName); + CBasics::ToLower(lowName); if (const auto iter = m_deferedCVars.find(lowName); iter != m_deferedCVars.end()) { std::string val = std::move(iter->second); m_deferedCVars.erase(lowName); @@ -175,7 +176,7 @@ void CVarManager::serialize() { container.cvars.push_back(*cvar); } } - container.cvarCount = atUint32(container.cvars.size()); + container.cvarCount = u32(container.cvars.size()); filename += ".bin"; athena::io::FileWriter writer(filename); @@ -233,7 +234,7 @@ bool CVarManager::restartRequired() const { void CVarManager::parseCommandLine(const std::vector& args) { bool oldDeveloper = suppressDeveloper(); std::string developerName(com_developer->name()); - athena::utility::tolower(developerName); + CBasics::ToLower(developerName); for (const std::string& arg : args) { if (arg[0] != '+') { continue; @@ -266,13 +267,13 @@ void CVarManager::parseCommandLine(const std::vector& args) { cv->fromLiteralToType(cvarValue); } cv->m_wasDeserialized = true; - athena::utility::tolower(cvarName); + CBasics::ToLower(cvarName); if (developerName == cvarName) /* Make sure we're not overriding developer mode when we restore */ oldDeveloper = com_developer->toBoolean(); } else { /* Unable to find an existing CVar, let's defer for the time being 8 */ - athena::utility::tolower(cvarName); + CBasics::ToLower(cvarName); m_deferedCVars.insert_or_assign(std::move(cvarName), std::move(cvarValue)); } } diff --git a/Runtime/GCNTypes.hpp b/Runtime/GCNTypes.hpp index 42233d831..b5cd945a9 100644 --- a/Runtime/GCNTypes.hpp +++ b/Runtime/GCNTypes.hpp @@ -11,3 +11,56 @@ using s32 = int32_t; using u32 = uint32_t; using s64 = int64_t; using u64 = uint64_t; + +#ifndef ROUND_UP_256 +#define ROUND_UP_256(val) (((val) + 255) & ~255) +#endif +#ifndef ROUND_UP_64 +#define ROUND_UP_64(val) (((val) + 63) & ~63) +#endif +#ifndef ROUND_UP_32 +#define ROUND_UP_32(val) (((val) + 31) & ~31) +#endif +#ifndef ROUND_UP_16 +#define ROUND_UP_16(val) (((val) + 15) & ~15) +#endif +#ifndef ROUND_UP_8 +#define ROUND_UP_8(val) (((val) + 7) & ~7) +#endif +#ifndef ROUND_UP_4 +#define ROUND_UP_4(val) (((val) + 3) & ~3) +#endif + +#ifndef ENABLE_BITWISE_ENUM +#define ENABLE_BITWISE_ENUM(type) \ + constexpr type operator|(type a, type b) noexcept { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) | static_cast(b)); \ + } \ + constexpr type operator&(type a, type b) noexcept { \ + using T = std::underlying_type_t; \ + return type(static_cast(a) & static_cast(b)); \ + } \ + constexpr type& operator|=(type& a, type b) noexcept { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) | static_cast(b)); \ + return a; \ + } \ + constexpr type& operator&=(type& a, type b) noexcept { \ + using T = std::underlying_type_t; \ + a = type(static_cast(a) & static_cast(b)); \ + return a; \ + } \ + constexpr type operator~(type key) noexcept { \ + using T = std::underlying_type_t; \ + return type(~static_cast(key)); \ + } \ + constexpr bool True(type key) noexcept { \ + using T = std::underlying_type_t; \ + return static_cast(key) != 0; \ + } \ + constexpr bool False(type key) noexcept { \ + using T = std::underlying_type_t; \ + return static_cast(key) == 0; \ + } +#endif \ No newline at end of file diff --git a/Runtime/ImGuiPlayerLoadouts.hpp b/Runtime/ImGuiPlayerLoadouts.hpp index 11e43d043..d76de2c58 100644 --- a/Runtime/ImGuiPlayerLoadouts.hpp +++ b/Runtime/ImGuiPlayerLoadouts.hpp @@ -9,15 +9,15 @@ struct ImGuiPlayerLoadouts : athena::io::DNA { struct Item : athena::io::DNA { AT_DECL_DNA_YAML String<-1> type; - Value amount; + Value amount; }; struct LoadOut : athena::io::DNA { AT_DECL_DNA_YAML String<-1> name; - Value itemCount; + Value itemCount; Vector items; }; - Value loadoutCount; + Value loadoutCount; Vector loadouts; }; } // namespace metaforce diff --git a/Runtime/Input/ControlMapper.cpp b/Runtime/Input/ControlMapper.cpp index 7d4bcf345..232612288 100644 --- a/Runtime/Input/ControlMapper.cpp +++ b/Runtime/Input/ControlMapper.cpp @@ -230,7 +230,7 @@ bool ControlMapper::GetPressInput(ECommands cmd, const CFinalInput& input) { } bool ret = false; - const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd))); + const auto func = EFunctionList(g_currentPlayerControl->GetMapping(u32(cmd))); if (func < EFunctionList::MAX) { if (BoolReturnFn fn = skPressFuncs[size_t(func)]) { ret = (input.*fn)(); @@ -257,7 +257,7 @@ bool ControlMapper::GetDigitalInput(ECommands cmd, const CFinalInput& input) { } bool ret = false; - const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd))); + const auto func = EFunctionList(g_currentPlayerControl->GetMapping(u32(cmd))); if (func < EFunctionList::MAX) { if (BoolReturnFn fn = skDigitalFuncs[size_t(func)]) ret = (input.*fn)(); @@ -333,7 +333,7 @@ float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) { } float ret = 0.f; - const auto func = EFunctionList(g_currentPlayerControl->GetMapping(atUint32(cmd))); + const auto func = EFunctionList(g_currentPlayerControl->GetMapping(u32(cmd))); if (func < EFunctionList::MAX) { if (FloatReturnFn fn = skAnalogFuncs[size_t(func)]) { ret = (input.*fn)(); diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 14389a183..e6179f152 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -686,7 +686,7 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, x164_archSupport = std::make_unique(*this, voiceEngine, backend); g_archSupport = x164_archSupport.get(); x164_archSupport->PreloadAudio(); - std::srand(static_cast(std::time(nullptr))); + std::srand(static_cast(CBasics::GetTime())); // g_TweakManager->ReadFromMemoryCard("AudioTweaks"); } diff --git a/Runtime/MP1/Tweaks/CTweakPlayerControl.hpp b/Runtime/MP1/Tweaks/CTweakPlayerControl.hpp index b6160ebf7..e08a12f6b 100644 --- a/Runtime/MP1/Tweaks/CTweakPlayerControl.hpp +++ b/Runtime/MP1/Tweaks/CTweakPlayerControl.hpp @@ -5,7 +5,7 @@ namespace metaforce::MP1 { struct CTweakPlayerControl final : Tweaks::ITweakPlayerControl { std::array m_mappings; - [[nodiscard]] ControlMapper::EFunctionList GetMapping(atUint32 command) const override { return m_mappings[command]; } + [[nodiscard]] ControlMapper::EFunctionList GetMapping(u32 command) const override { return m_mappings[command]; } CTweakPlayerControl() = default; CTweakPlayerControl(CInputStream& reader); }; diff --git a/Runtime/MP1/Tweaks/CTweakPlayerGun.hpp b/Runtime/MP1/Tweaks/CTweakPlayerGun.hpp index 97e809efc..bafbd29d8 100644 --- a/Runtime/MP1/Tweaks/CTweakPlayerGun.hpp +++ b/Runtime/MP1/Tweaks/CTweakPlayerGun.hpp @@ -54,7 +54,7 @@ struct CTweakPlayerGun final : Tweaks::ITweakPlayerGun { float GetGunExtendDistance() const override { return x48_gunExtendDistance; } const zeus::CVector3f& GetGunPosition() const override { return x4c_gunPosition; } const zeus::CVector3f& GetGrapplingArmPosition() const override { return x64_grapplingArmPosition; } - float GetRichochetDamage(atUint32 type) const override { + float GetRichochetDamage(u32 type) const override { switch (type) { case 0: // Power return x280_ricochetData[0]; @@ -82,14 +82,14 @@ struct CTweakPlayerGun final : Tweaks::ITweakPlayerGun { } } - const SWeaponInfo& GetBeamInfo(atInt32 beam) const override { + const SWeaponInfo& GetBeamInfo(s32 beam) const override { if (beam < 0 || beam >= 5) { return xa8_beams[0]; } return xa8_beams[beam]; } - const SComboShotParam& GetComboShotInfo(atInt32 beam) const override { + const SComboShotParam& GetComboShotInfo(s32 beam) const override { if (beam < 0 || beam >= 5) { return x1f0_combos[0]; } diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index 8d4736080..94307fd38 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -88,10 +88,10 @@ constexpr uint64_t SBig(uint64_t val) noexcept { return bswap64(val); } constexpr float SBig(float val) noexcept { union { float f; - atInt32 i; + u32 i; } uval1 = {val}; union { - atInt32 i; + u32 i; float f; } uval2 = {bswap32(uval1.i)}; return uval2.f; @@ -99,10 +99,10 @@ constexpr float SBig(float val) noexcept { constexpr double SBig(double val) noexcept { union { double f; - atInt64 i; + u32 i; } uval1 = {val}; union { - atInt64 i; + u32 i; double f; } uval2 = {bswap64(uval1.i)}; return uval2.f; diff --git a/Runtime/Streams/CMemoryInStream.hpp b/Runtime/Streams/CMemoryInStream.hpp index 7eda43ab1..607bdc899 100644 --- a/Runtime/Streams/CMemoryInStream.hpp +++ b/Runtime/Streams/CMemoryInStream.hpp @@ -1,5 +1,5 @@ #pragma once -#include "CInputStream.hpp" +#include "Runtime/Streams/CInputStream.hpp" namespace metaforce { class CMemoryInStream final : public CInputStream { diff --git a/Runtime/Streams/IOStreams.cpp b/Runtime/Streams/IOStreams.cpp index b5f7233ba..78f96e8c8 100644 --- a/Runtime/Streams/IOStreams.cpp +++ b/Runtime/Streams/IOStreams.cpp @@ -70,7 +70,7 @@ zeus::CTransform cinput_stream_helper(CInputStream& in) { auto r0 = in.Get(); auto r1 = in.Get(); auto r2 = in.Get(); - ret.basis = zeus::CMatrix3f(r0, r1, r2); + ret.basis = zeus::CMatrix3f(r0.toVec3f(), r1.toVec3f(), r2.toVec3f()); ret.basis.transpose(); ret.origin = zeus::CVector3f(r0.w(), r1.w(), r2.w()); return ret; diff --git a/Runtime/Tweaks/ITweakGui.hpp b/Runtime/Tweaks/ITweakGui.hpp index 0a3f5916e..a34bf40af 100644 --- a/Runtime/Tweaks/ITweakGui.hpp +++ b/Runtime/Tweaks/ITweakGui.hpp @@ -5,9 +5,9 @@ namespace metaforce::Tweaks { struct ITweakGui : ITweak { - enum class EHudVisMode : atUint32 { Zero, One, Two, Three }; + enum class EHudVisMode : u32 { Zero, One, Two, Three }; - enum class EHelmetVisMode : atUint32 { ReducedUpdate, NotVisible, Deco, HelmetDeco, GlowHelmetDeco, HelmetOnly }; + enum class EHelmetVisMode : u32 { ReducedUpdate, NotVisible, Deco, HelmetDeco, GlowHelmetDeco, HelmetOnly }; virtual float GetMapAlphaInterpolant() const = 0; virtual float GetPauseBlurFactor() const = 0; diff --git a/Runtime/Tweaks/ITweakPlayerControl.hpp b/Runtime/Tweaks/ITweakPlayerControl.hpp index 9f55d6083..26d5570cd 100644 --- a/Runtime/Tweaks/ITweakPlayerControl.hpp +++ b/Runtime/Tweaks/ITweakPlayerControl.hpp @@ -6,7 +6,7 @@ namespace metaforce::Tweaks { struct ITweakPlayerControl : ITweak { - [[nodiscard]] virtual ControlMapper::EFunctionList GetMapping(atUint32) const = 0; + [[nodiscard]] virtual ControlMapper::EFunctionList GetMapping(u32) const = 0; }; } // namespace DataSpec diff --git a/Runtime/Tweaks/ITweakPlayerGun.hpp b/Runtime/Tweaks/ITweakPlayerGun.hpp index ac0e384ba..ba433f8f4 100644 --- a/Runtime/Tweaks/ITweakPlayerGun.hpp +++ b/Runtime/Tweaks/ITweakPlayerGun.hpp @@ -5,7 +5,7 @@ namespace metaforce { /* Same as CDamageInfo */ struct SShotParam { - atInt32 x0_weaponType = -1; + u32 x0_weaponType = -1; bool x4_24_charged : 1; bool x4_25_combo : 1; bool x4_26_instaKill : 1; @@ -63,9 +63,9 @@ struct ITweakPlayerGun : ITweak { virtual float GetGunExtendDistance() const = 0; virtual const zeus::CVector3f& GetGunPosition() const = 0; virtual const zeus::CVector3f& GetGrapplingArmPosition() const = 0; - virtual float GetRichochetDamage(atUint32) const = 0; - virtual const SWeaponInfo& GetBeamInfo(atInt32 beam) const = 0; - virtual const SComboShotParam& GetComboShotInfo(atInt32 beam) const = 0; + virtual float GetRichochetDamage(u32) const = 0; + virtual const SWeaponInfo& GetBeamInfo(s32 beam) const = 0; + virtual const SComboShotParam& GetComboShotInfo(s32 beam) const = 0; virtual const SShotParam& GetBombInfo() const = 0; virtual const SShotParam& GetPowerBombInfo() const = 0; }; diff --git a/Runtime/Tweaks/ITweakTargeting.hpp b/Runtime/Tweaks/ITweakTargeting.hpp index 03510f9a0..daaae8bcf 100644 --- a/Runtime/Tweaks/ITweakTargeting.hpp +++ b/Runtime/Tweaks/ITweakTargeting.hpp @@ -4,7 +4,7 @@ namespace metaforce::Tweaks { struct ITweakTargeting : public ITweak { - virtual atUint32 GetTargetRadiusMode() const = 0; + virtual u32 GetTargetRadiusMode() const = 0; virtual float GetCurrLockOnExitDuration() const = 0; virtual float GetCurrLockOnEnterDuration() const = 0; virtual float GetCurrLockOnSwitchDuration() const = 0; @@ -40,7 +40,7 @@ struct ITweakTargeting : public ITweak { virtual float GetChargeGaugeAngle(int i) const = 0; virtual float GetChargeGaugeScale() const = 0; virtual const zeus::CColor& GetChargeGaugeNonFullColor() const = 0; - virtual atUint32 GetChargeTickCount() const = 0; + virtual u32 GetChargeTickCount() const = 0; virtual float GetChargeTickAnglePitch() const = 0; virtual float GetLockFireScale() const = 0; virtual float GetLockFireDuration() const = 0; diff --git a/hecl/bintoc/bintoc.c b/hecl/bintoc/bintoc.c index fc81b906e..aebfb17a7 100644 --- a/hecl/bintoc/bintoc.c +++ b/hecl/bintoc/bintoc.c @@ -47,7 +47,7 @@ int main(int argc, char** argv) { if (compress) { size_t compressedSz = 0; z_stream strm = {.zalloc = Z_NULL, .zfree = Z_NULL, .opaque = Z_NULL}; - int ret = deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS | 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); + int ret = deflateInit(&strm, Z_BEST_COMPRESSION); if (ret != Z_OK) { fprintf(stderr, "zlib initialization failed %d\n", ret); return 1; diff --git a/imgui/CMakeLists.txt b/imgui/CMakeLists.txt index cd8f1c542..90d1fdd90 100644 --- a/imgui/CMakeLists.txt +++ b/imgui/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(imgui NotoMono.cpp MetaforceIcon.cpp ) -target_include_directories(imgui PUBLIC ${CMAKE_SOURCE_DIR}/extern/imgui ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(imgui PUBLIC ${CMAKE_SOURCE_DIR}/extern/imgui ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}) target_compile_definitions(imgui PUBLIC IMGUI_USER_CONFIG="imconfig_user.h") # IMGUI_USE_WCHAR32 if (CMAKE_COMPILER_IS_GNUCXX) # currently explicitly ignored for clang in imgui code, but not gcc (yet) diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index e674aa9a0..820bb7cbe 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -2,7 +2,8 @@ #include -#include "athena/Compression.hpp" +#include "Runtime/Streams/CMemoryInStream.hpp" +#include "Runtime/Streams/CZipInputStream.hpp" #define STBI_NO_STDIO #define STB_IMAGE_STATIC @@ -30,8 +31,10 @@ void ImGuiEngine_Initialize(float scale) { ImGuiIO& io = ImGui::GetIO(); auto* fontData = new uint8_t[NOTO_MONO_FONT_DECOMPRESSED_SZ]; - athena::io::Compression::decompressZlib(static_cast(NOTO_MONO_FONT), atUint32(NOTO_MONO_FONT_SZ), - fontData, NOTO_MONO_FONT_DECOMPRESSED_SZ); + metaforce::CMemoryInStream memStream(static_cast(NOTO_MONO_FONT), NOTO_MONO_FONT_SZ, + metaforce::CMemoryInStream::EOwnerShip::NotOwned); + metaforce::CZipInputStream zipInputStream(std::make_unique(memStream)); + zipInputStream.Get(fontData, NOTO_MONO_FONT_DECOMPRESSED_SZ); ImFontConfig fontConfig{}; fontConfig.FontData = fontData;