From dad72499274a690329b7e06ecc6b75d2934b5c07 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 17 Feb 2022 23:37:54 -0800 Subject: [PATCH] RE COutput/InputStream and friends and migrate over This branch is probably still horribly broken, but it's a good first step to migrating away from having hecl embedded in the runtime --- DataSpec/DNACommon/AROTBuilder.hpp | 2 +- DataSpec/DNACommon/CMDL.cpp | 3 +- DataSpec/DNACommon/PATH.cpp | 1 + DataSpec/SpecMP1.cpp | 2 + Runtime/Audio/CAudioGroupSet.cpp | 8 +- Runtime/Audio/CMidiManager.cpp | 14 +- Runtime/Audio/CSfxManager.cpp | 5 +- Runtime/AutoMapper/CMapArea.cpp | 90 +- Runtime/AutoMapper/CMapUniverse.cpp | 18 +- Runtime/AutoMapper/CMapWorld.cpp | 8 +- Runtime/AutoMapper/CMapWorldInfo.cpp | 24 +- Runtime/AutoMapper/CMapWorldInfo.hpp | 4 +- Runtime/AutoMapper/CMappableObject.cpp | 12 +- Runtime/CBasics.hpp | 8 + Runtime/CBasicsPC.cpp | 59 + Runtime/CDependencyGroup.cpp | 2 +- Runtime/CFactoryMgr.cpp | 16 +- Runtime/CGameHintInfo.cpp | 26 +- Runtime/CGameOptions.cpp | 132 +- Runtime/CGameOptions.hpp | 12 +- Runtime/CGameState.cpp | 76 +- Runtime/CGameState.hpp | 14 +- Runtime/CInputStream.cpp | 278 +++ Runtime/CInputStream.hpp | 83 + Runtime/CMakeLists.txt | 9 +- Runtime/CMayaSpline.cpp | 33 +- Runtime/CMemoryCardSys.cpp | 22 +- Runtime/CMemoryCardSys.hpp | 21 +- Runtime/CMemoryInStream.hpp | 19 + Runtime/CMemoryStreamOut.cpp | 22 + Runtime/CMemoryStreamOut.hpp | 25 + Runtime/COutputStream.cpp | 209 ++ Runtime/COutputStream.hpp | 88 + Runtime/CPakFile.cpp | 30 +- Runtime/CPakFile.hpp | 2 +- Runtime/CPlayerState.cpp | 42 +- Runtime/CPlayerState.hpp | 4 +- Runtime/CResLoader.cpp | 13 +- Runtime/CScannableObjectInfo.cpp | 30 +- Runtime/CScriptMailbox.cpp | 8 +- Runtime/CScriptMailbox.hpp | 4 +- Runtime/CStateManager.cpp | 206 +- Runtime/CStringExtras.cpp | 21 + Runtime/CStringExtras.hpp | 4 +- Runtime/CTextureCache.cpp | 4 +- Runtime/CTextureCache.hpp | 14 +- Runtime/CWorldSaveGameInfo.cpp | 30 +- Runtime/CZipInputStream.cpp | 34 + Runtime/CZipInputStream.hpp | 21 + Runtime/Camera/CCameraShakeData.cpp | 40 +- Runtime/Camera/CCameraShakeData.hpp | 1 + Runtime/Character/CAdditiveAnimPlayback.hpp | 5 +- Runtime/Character/CAllFormatsAnimSource.cpp | 2 +- Runtime/Character/CAnimCharacterSet.cpp | 2 +- Runtime/Character/CAnimPOIData.cpp | 10 +- Runtime/Character/CAnimSource.cpp | 16 +- Runtime/Character/CAnimation.cpp | 2 +- Runtime/Character/CAnimationSet.cpp | 18 +- Runtime/Character/CBoolPOINode.cpp | 2 +- Runtime/Character/CCharAnimTime.hpp | 2 +- Runtime/Character/CCharLayoutInfo.cpp | 12 +- Runtime/Character/CCharacterInfo.cpp | 57 +- Runtime/Character/CCharacterSet.cpp | 6 +- Runtime/Character/CEffectComponent.cpp | 12 +- Runtime/Character/CFBStreamedCompression.cpp | 38 +- Runtime/Character/CFBStreamedCompression.hpp | 18 +- Runtime/Character/CHalfTransition.cpp | 2 +- Runtime/Character/CInt32POINode.cpp | 2 +- Runtime/Character/CMetaAnimBlend.cpp | 4 +- Runtime/Character/CMetaAnimFactory.cpp | 2 +- Runtime/Character/CMetaAnimPhaseBlend.cpp | 4 +- Runtime/Character/CMetaAnimRandom.cpp | 4 +- Runtime/Character/CMetaAnimSequence.cpp | 2 +- Runtime/Character/CMetaTransFactory.cpp | 2 +- Runtime/Character/CMetaTransPhaseTrans.cpp | 6 +- Runtime/Character/CMetaTransTrans.cpp | 8 +- Runtime/Character/CPASAnimState.cpp | 18 +- Runtime/Character/CPASDatabase.cpp | 6 +- Runtime/Character/CPASParmInfo.cpp | 28 +- Runtime/Character/CPOINode.cpp | 16 +- Runtime/Character/CParticleData.cpp | 8 +- Runtime/Character/CPrimitive.cpp | 6 +- Runtime/Character/CSegId.hpp | 2 +- Runtime/Character/CSegIdList.cpp | 2 +- Runtime/Character/CSkinBank.cpp | 2 +- Runtime/Character/CSkinRules.cpp | 17 +- Runtime/Character/CSkinRules.hpp | 2 +- Runtime/Character/CSoundPOINode.cpp | 2 +- Runtime/Character/CTransition.cpp | 6 +- Runtime/Collision/CAreaOctTree.cpp | 15 +- Runtime/Collision/CCollidableOBBTreeGroup.cpp | 2 +- Runtime/Collision/CCollisionEdge.cpp | 5 +- Runtime/Collision/CCollisionResponseData.cpp | 2 +- Runtime/Collision/COBBTree.cpp | 40 +- Runtime/Graphics/CCubeModel.cpp | 18 +- Runtime/Graphics/CGraphicsPalette.hpp | 6 +- Runtime/Graphics/CPVSAreaSet.cpp | 16 +- Runtime/Graphics/CPVSVisOctree.cpp | 10 +- Runtime/Graphics/CTextureBoo.cpp | 42 +- Runtime/GuiSys/CAuiEnergyBarT01.cpp | 2 +- Runtime/GuiSys/CAuiImagePane.cpp | 14 +- Runtime/GuiSys/CAuiMeter.cpp | 8 +- Runtime/GuiSys/CGuiCamera.cpp | 22 +- Runtime/GuiSys/CGuiFrame.cpp | 14 +- Runtime/GuiSys/CGuiGroup.cpp | 4 +- Runtime/GuiSys/CGuiLight.cpp | 18 +- Runtime/GuiSys/CGuiModel.cpp | 6 +- Runtime/GuiSys/CGuiPane.cpp | 4 +- Runtime/GuiSys/CGuiSliderGroup.cpp | 8 +- Runtime/GuiSys/CGuiTableGroup.cpp | 30 +- Runtime/GuiSys/CGuiTextPane.cpp | 24 +- Runtime/GuiSys/CGuiWidget.cpp | 31 +- Runtime/GuiSys/CRasterFont.cpp | 76 +- Runtime/GuiSys/CStringTable.cpp | 36 +- Runtime/GuiSys/CStringTable.hpp | 2 +- Runtime/IOStreams.cpp | 204 +- Runtime/IOStreams.hpp | 107 +- Runtime/MP1/CMemoryCardDriver.cpp | 28 +- Runtime/MP1/CMemoryCardDriver.hpp | 8 +- Runtime/MP1/CTweaks.cpp | 46 +- Runtime/MP1/MP1.cpp | 9 +- Runtime/MP1/MP1.hpp | 4 +- Runtime/MP1/World/CBabygoth.cpp | 22 +- Runtime/MP1/World/CBouncyGrenade.hpp | 2 +- Runtime/MP1/World/CChozoGhost.cpp | 16 +- Runtime/MP1/World/CElitePirate.cpp | 34 +- Runtime/MP1/World/CFlaahgra.cpp | 14 +- Runtime/MP1/World/CFlyingPirate.cpp | 40 +- Runtime/MP1/World/CGrenadeLauncher.hpp | 8 +- Runtime/MP1/World/CIceSheegoth.cpp | 30 +- Runtime/MP1/World/CMetroid.cpp | 14 +- Runtime/MP1/World/CMetroidBeta.cpp | 20 +- Runtime/MP1/World/CMetroidPrimeExo.cpp | 53 +- Runtime/MP1/World/CMetroidPrimeProjectile.cpp | 20 +- Runtime/MP1/World/CRidley.cpp | 26 +- Runtime/MP1/World/CSpacePirate.cpp | 50 +- Runtime/Particle/CColorElement.cpp | 16 +- Runtime/Particle/CDecalDataFactory.cpp | 2 +- Runtime/Particle/CIntElement.cpp | 16 +- Runtime/Particle/CParticleDataFactory.cpp | 26 +- .../Particle/CParticleElectricDataFactory.cpp | 2 +- .../Particle/CParticleSwooshDataFactory.cpp | 2 +- .../Particle/CProjectileWeaponDataFactory.cpp | 2 +- Runtime/Particle/CRealElement.cpp | 16 +- Runtime/Particle/CSpawnSystemKeyframeData.cpp | 22 +- Runtime/Particle/CVectorElement.cpp | 16 +- Runtime/RetroTypes.cpp | 44 +- Runtime/RetroTypes.hpp | 20 +- Runtime/Weapon/CBeamInfo.hpp | 34 +- Runtime/Weapon/CFlameInfo.cpp | 12 +- Runtime/Weapon/CPlasmaProjectile.hpp | 2 +- Runtime/World/CAnimationParameters.hpp | 3 +- Runtime/World/CDamageInfo.hpp | 10 +- Runtime/World/CDamageVulnerability.cpp | 24 +- Runtime/World/CGameArea.cpp | 174 +- Runtime/World/CHUDMemoParms.hpp | 4 +- Runtime/World/CHealthInfo.cpp | 7 +- Runtime/World/CPathFindArea.cpp | 34 +- Runtime/World/CPathFindRegion.cpp | 34 +- Runtime/World/CPatternedInfo.cpp | 66 +- Runtime/World/CPlayerCameraBob.cpp | 31 +- Runtime/World/CScriptGunTurret.cpp | 70 +- Runtime/World/CScriptMazeNode.cpp | 2 +- Runtime/World/CScriptSpindleCamera.cpp | 10 +- Runtime/World/CStateMachine.cpp | 31 +- Runtime/World/CTeamAiMgr.cpp | 18 +- Runtime/World/CVisorFlare.cpp | 10 +- Runtime/World/CWorld.cpp | 84 +- Runtime/World/CWorld.hpp | 4 +- Runtime/World/CWorldLight.cpp | 23 +- Runtime/World/IGameArea.cpp | 12 +- Runtime/World/ScriptLoader.cpp | 2110 ++++++++--------- 172 files changed, 3629 insertions(+), 2780 deletions(-) create mode 100644 Runtime/CInputStream.cpp create mode 100644 Runtime/CInputStream.hpp create mode 100644 Runtime/CMemoryInStream.hpp create mode 100644 Runtime/CMemoryStreamOut.cpp create mode 100644 Runtime/CMemoryStreamOut.hpp create mode 100644 Runtime/COutputStream.cpp create mode 100644 Runtime/COutputStream.hpp create mode 100644 Runtime/CStringExtras.cpp create mode 100644 Runtime/CZipInputStream.cpp create mode 100644 Runtime/CZipInputStream.hpp diff --git a/DataSpec/DNACommon/AROTBuilder.hpp b/DataSpec/DNACommon/AROTBuilder.hpp index 9e32b23b9..df42876a7 100644 --- a/DataSpec/DNACommon/AROTBuilder.hpp +++ b/DataSpec/DNACommon/AROTBuilder.hpp @@ -4,7 +4,7 @@ #include "DeafBabe.hpp" #include "zeus/CAABox.hpp" #include "CMDL.hpp" -#include "IOStreams.hpp" +#include #include namespace DataSpec { diff --git a/DataSpec/DNACommon/CMDL.cpp b/DataSpec/DNACommon/CMDL.cpp index 2af280e61..1baa4d90b 100644 --- a/DataSpec/DNACommon/CMDL.cpp +++ b/DataSpec/DNACommon/CMDL.cpp @@ -9,8 +9,9 @@ #include "DataSpec/DNAMP2/CSKR.hpp" #include "DataSpec/DNAMP3/CMDLMaterials.hpp" #include "DataSpec/DNAMP3/CSKR.hpp" -#include "IOStreams.hpp" +#include +#include #include #include #include diff --git a/DataSpec/DNACommon/PATH.cpp b/DataSpec/DNACommon/PATH.cpp index dff277911..9ef5325fb 100644 --- a/DataSpec/DNACommon/PATH.cpp +++ b/DataSpec/DNACommon/PATH.cpp @@ -2,6 +2,7 @@ #include "hecl/Blender/Connection.hpp" #include "zeus/CAABox.hpp" #include "DataSpec/DNACommon/AROTBuilder.hpp" +#include namespace DataSpec::DNAPATH { diff --git a/DataSpec/SpecMP1.cpp b/DataSpec/SpecMP1.cpp index a6a7fa1f1..8fa336584 100644 --- a/DataSpec/SpecMP1.cpp +++ b/DataSpec/SpecMP1.cpp @@ -52,6 +52,8 @@ #include "hecl/Blender/Connection.hpp" #include "hecl/Blender/SDNARead.hpp" #include "nod/nod.hpp" +#include +#include namespace DataSpec { diff --git a/Runtime/Audio/CAudioGroupSet.cpp b/Runtime/Audio/CAudioGroupSet.cpp index d24e2c62f..1249e9a42 100644 --- a/Runtime/Audio/CAudioGroupSet.cpp +++ b/Runtime/Audio/CAudioGroupSet.cpp @@ -11,11 +11,11 @@ amuse::AudioGroupData CAudioGroupSet::LoadData() { return SBig(value); }; - athena::io::MemoryReader r(m_buffer.get(), INT32_MAX); - x10_baseName = r.readString(); - x20_name = r.readString(); + CMemoryInStream r(m_buffer.get(), INT32_MAX, CMemoryInStream::EOwnerShip::NotOwned); + x10_baseName = r.Get(); + x20_name = r.Get(); - u8* buf = m_buffer.get() + r.position(); + u8* buf = m_buffer.get() + r.GetReadPosition(); const uint32_t poolLen = readU32(buf); unsigned char* pool = buf + 4; buf += poolLen + 4; diff --git a/Runtime/Audio/CMidiManager.cpp b/Runtime/Audio/CMidiManager.cpp index 14332d621..e996c957c 100644 --- a/Runtime/Audio/CMidiManager.cpp +++ b/Runtime/Audio/CMidiManager.cpp @@ -1,5 +1,7 @@ #include "Runtime/Audio/CMidiManager.hpp" +#include "Runtime/CInputStream.hpp" + namespace metaforce { std::unordered_set CMidiManager::m_MidiWrappers = {}; @@ -35,13 +37,13 @@ CMidiHandle CMidiManager::Play(const CMidiData& data, float fadeTime, bool stopE } CMidiManager::CMidiData::CMidiData(CInputStream& in) { - in.readUint32Big(); - x0_setupId = in.readUint32Big(); - x2_groupId = in.readUint32Big(); - x4_agscId = in.readUint32Big(); - u32 length = in.readUint32Big(); + in.ReadLong(); + x0_setupId = in.ReadLong(); + x2_groupId = in.ReadLong(); + x4_agscId = in.ReadLong(); + u32 length = in.ReadLong(); x8_arrData.reset(new u8[length]); - in.readUBytesToBuf(x8_arrData.get(), length); + in.ReadBytes(reinterpret_cast(x8_arrData.get()), length); } CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& parms, diff --git a/Runtime/Audio/CSfxManager.cpp b/Runtime/Audio/CSfxManager.cpp index 8394782d4..c6d94329d 100644 --- a/Runtime/Audio/CSfxManager.cpp +++ b/Runtime/Audio/CSfxManager.cpp @@ -1,4 +1,5 @@ #include "Runtime/Audio/CSfxManager.hpp" +#include "Runtime/CInputStream.hpp" #include "Runtime/CSimplePool.hpp" @@ -19,10 +20,10 @@ static amuse::EffectDelay* s_DelayState = nullptr; CFactoryFnReturn FAudioTranslationTableFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CObjectReference* selfRef) { std::unique_ptr> obj = std::make_unique>(); - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); obj->reserve(count); for (u32 i = 0; i < count; ++i) - obj->push_back(in.readUint16Big()); + obj->push_back(in.ReadShort()); return TToken>::GetIObjObjectFor(std::move(obj)); } diff --git a/Runtime/AutoMapper/CMapArea.cpp b/Runtime/AutoMapper/CMapArea.cpp index f434a189d..ea017cd14 100644 --- a/Runtime/AutoMapper/CMapArea.cpp +++ b/Runtime/AutoMapper/CMapArea.cpp @@ -3,10 +3,11 @@ #include #include +#include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/CToken.hpp" #include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/World/CWorld.hpp" +#include "Runtime/CBasics.hpp" namespace metaforce { constexpr std::array MinesPostTransforms{{ @@ -61,17 +62,17 @@ constexpr std::array MinesPostTransformIndices{ }; CMapArea::CMapArea(CInputStream& in, u32 size) -: x0_magic(in.readUint32()) -, x4_version(in.readUint32Big()) -, x8_(in.readUint32Big()) -, xc_visibilityMode(EVisMode(in.readUint32Big())) -, x10_box(zeus::CAABox::ReadBoundingBoxBig(in)) -, x28_mappableObjCount(in.readUint32Big()) -, x2c_vertexCount(in.readUint32Big()) -, x30_surfaceCount(in.readUint32Big()) +: x0_magic(in.ReadLong()) +, x4_version(in.ReadLong()) +, x8_(in.ReadLong()) +, xc_visibilityMode(EVisMode(in.ReadLong())) +, x10_box(in.Get()) +, x28_mappableObjCount(in.ReadLong()) +, x2c_vertexCount(in.ReadLong()) +, x30_surfaceCount(in.ReadLong()) , x34_size(size - 52) { x44_buf.reset(new u8[x34_size]); - in.readUBytesToBuf(x44_buf.get(), x34_size); + in.ReadBytes(x44_buf.get(), x34_size); PostConstruct(); } @@ -120,14 +121,14 @@ void CMapArea::PostConstruct() { // CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo); // // athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX); -// u32 outlineCount = r.readUint32Big(); +// u32 outlineCount = r.ReadLong(); // // std::vector& linePrims = instance.m_linePrims; // linePrims.reserve(outlineCount * 2); // for (u32 j = 0; j < 2; ++j) { // r.seek(4, athena::SeekOrigin::Begin); // for (u32 k = 0; k < outlineCount; ++k) { -// const u32 count = r.readUint32Big(); +// const u32 count = r.ReadLong(); // r.seek(count); // r.seekAlign4(); // linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true); @@ -179,11 +180,11 @@ const zeus::CVector3f& CMapArea::GetAreaPostTranslate(const IWorld& world, TArea } CMapArea::CMapAreaSurface::CMapAreaSurface(const void* surfBuf) { - athena::io::MemoryReader r(surfBuf, 32); - x0_normal = r.readVec3fBig(); - xc_centroid = r.readVec3fBig(); - x18_surfOffset = reinterpret_cast(uintptr_t(r.readUint32Big())); - x1c_outlineOffset = reinterpret_cast(uintptr_t(r.readUint32Big())); + CMemoryInStream r(surfBuf, 32, CMemoryInStream::EOwnerShip::NotOwned); + x0_normal = r.Get(); + xc_centroid = r.Get(); + x18_surfOffset = reinterpret_cast(uintptr_t(r.ReadLong())); + x1c_outlineOffset = reinterpret_cast(uintptr_t(r.ReadLong())); } void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& index) { @@ -193,24 +194,24 @@ void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& i m_primStart = index.size(); bool start = true; { - athena::io::MemoryReader r(x18_surfOffset, INT_MAX); - u32 primCount = r.readUint32Big(); + CMemoryInStream r(x18_surfOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); + u32 primCount = r.ReadLong(); for (u32 i = 0; i < primCount; ++i) { - GX::Primitive prim = GX::Primitive(r.readUint32Big()); - u32 count = r.readUint32Big(); + GX::Primitive prim = GX::Primitive(r.ReadLong()); + u32 count = r.ReadLong(); switch (prim) { case GX::Primitive::TRIANGLES: { for (u32 v = 0; v < count; v += 3) { if (!start) { index.push_back(index.back()); - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); index.push_back(index.back()); } else { - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); start = false; } - index.push_back(r.readUByte()); - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); + index.push_back(r.ReadUint8()); index.push_back(index.back()); } break; @@ -218,38 +219,41 @@ void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& i case GX::Primitive::TRIANGLESTRIP: { if (!start) { index.push_back(index.back()); - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); index.push_back(index.back()); } else { - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); start = false; } for (u32 v = 1; v < count; ++v) - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); if (count & 1) index.push_back(index.back()); break; } case GX::Primitive::TRIANGLEFAN: { - u8 firstVert = r.readUByte(); + u8 firstVert = r.ReadUint8(); if (!start) { index.push_back(index.back()); - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); } else { - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); index.push_back(index.back()); start = false; } for (u32 v = 1; v < count; ++v) { index.push_back(firstVert); - index.push_back(r.readUByte()); + index.push_back(r.ReadUint8()); } break; } default: break; } - r.seekAlign4(); + u32 pos = r.GetReadPosition(); + while (r.GetReadPosition() != ROUND_UP_4(pos)) { + r.ReadUint8(); + } } } m_primCount = index.size() - m_primStart; @@ -269,8 +273,11 @@ void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::C if (lineColor.a()) { bool draw2 = lineWidth > 1.f; - athena::io::MemoryReader r(x1c_outlineOffset, INT_MAX); - u32 outlineCount = r.readUint32Big(); + u32 outlineCount = *reinterpret_cast(&x1c_outlineOffset); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + outlineCount = CBasics::SwapBytes(outlineCount); +#endif + std::vector& linePrims = instance.m_linePrims; zeus::CColor color = lineColor; @@ -280,16 +287,21 @@ void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::C auto primIt = linePrims.begin(); for (u32 j = 0; j <= u32(draw2); ++j) { - r.seek(4, athena::SeekOrigin::Begin); + CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); + r.ReadLong(); for (u32 i = 0; i < outlineCount; ++i) { CLineRenderer& prim = *primIt++; prim.Reset(); - u32 count = r.readUint32Big(); + u32 count = r.ReadLong(); for (u32 v = 0; v < count; ++v) { - u8 idx = r.readUByte(); + u8 idx = r.ReadUint8(); prim.AddVertex(verts[idx], color, width); } - r.seekAlign4(); + + u32 pos = r.GetReadPosition(); + while (r.GetReadPosition() != ROUND_UP_4(pos)) { + r.ReadUint8(); + } prim.Render(); } width -= 1.f; diff --git a/Runtime/AutoMapper/CMapUniverse.cpp b/Runtime/AutoMapper/CMapUniverse.cpp index 84f68f034..f1673f1a4 100644 --- a/Runtime/AutoMapper/CMapUniverse.cpp +++ b/Runtime/AutoMapper/CMapUniverse.cpp @@ -6,25 +6,25 @@ namespace metaforce { -CMapUniverse::CMapUniverse(CInputStream& in, u32 version) : x0_hexagonId(in.readUint32Big()) { +CMapUniverse::CMapUniverse(CInputStream& in, u32 version) : x0_hexagonId(in.Get()) { x4_hexagonToken = g_SimplePool->GetObj({FOURCC('MAPA'), x0_hexagonId}); - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x10_worldDatas.reserve(count); for (u32 i = 0; i < count; ++i) x10_worldDatas.emplace_back(in, version); } CMapUniverse::CMapWorldData::CMapWorldData(CInputStream& in, u32 version) -: x0_label(in.readString()), x10_worldAssetId(in.readUint32Big()) { - x14_transform.read34RowMajor(in); - const u32 worldCount = in.readUint32Big(); +: x0_label(in.Get()), x10_worldAssetId(in.ReadLong()) { + x14_transform = in.Get(); + const u32 worldCount = in.ReadLong(); x44_hexagonXfs.reserve(worldCount); for (u32 i = 0; i < worldCount; ++i) { - x44_hexagonXfs.emplace_back().read34RowMajor(in); + x44_hexagonXfs.emplace_back() = in.Get(); } if (version != 0) - x54_surfColorSelected.readRGBABig(in); + x54_surfColorSelected = in.Get(); else x54_surfColorSelected.fromRGBA32(255 | (u32(x10_worldAssetId.Value()) & 0xFFFFFF00)); @@ -115,8 +115,8 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3 } CFactoryFnReturn FMapUniverseFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&, CObjectReference*) { - in.readUint32Big(); - u32 version = in.readUint32Big(); + in.ReadLong(); + u32 version = in.ReadLong(); return TToken::GetIObjObjectFor(std::make_unique(in, version)); } diff --git a/Runtime/AutoMapper/CMapWorld.cpp b/Runtime/AutoMapper/CMapWorld.cpp index 2b3711bcd..9ccede18d 100644 --- a/Runtime/AutoMapper/CMapWorld.cpp +++ b/Runtime/AutoMapper/CMapWorld.cpp @@ -274,13 +274,13 @@ CMapWorld::CMapAreaData::CMapAreaData(CAssetId areaRes, EMapAreaList list, CMapA CMapWorld::CMapWorld(CInputStream& in) { x10_listHeads.resize(3); - in.readUint32Big(); - in.readUint32Big(); - u32 areaCount = in.readUint32Big(); + in.ReadLong(); + in.ReadLong(); + u32 areaCount = in.ReadLong(); x0_areas.reserve(areaCount); x20_traversed.resize(areaCount); for (u32 i = 0; i < areaCount; ++i) { - CAssetId mapaId = in.readUint32Big(); + CAssetId mapaId = in.ReadLong(); x0_areas.emplace_back(mapaId, EMapAreaList::Unloaded, x0_areas.empty() ? nullptr : &x0_areas.back()); } x10_listHeads[2] = &x0_areas.back(); diff --git a/Runtime/AutoMapper/CMapWorldInfo.cpp b/Runtime/AutoMapper/CMapWorldInfo.cpp index 926259c6a..dfc4b5b2f 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.cpp +++ b/Runtime/AutoMapper/CMapWorldInfo.cpp @@ -5,52 +5,52 @@ namespace metaforce { -CMapWorldInfo::CMapWorldInfo(CBitStreamReader& reader, const CWorldSaveGameInfo& savw, CAssetId mlvlId) { +CMapWorldInfo::CMapWorldInfo(CInputStream& reader, const CWorldSaveGameInfo& savw, CAssetId mlvlId) { const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId); x4_visitedAreas.reserve((worldMem.GetAreaCount() + 31) / 32); for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) { - const bool visited = reader.ReadEncoded(1) != 0; + const bool visited = reader.ReadBits(1) != 0; SetAreaVisited(i, visited); } x18_mappedAreas.reserve((worldMem.GetAreaCount() + 31) / 32); for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) { - const bool mapped = reader.ReadEncoded(1) != 0; + const bool mapped = reader.ReadBits(1) != 0; SetIsMapped(i, mapped); } for (const auto& doorId : savw.GetDoors()) { - SetDoorVisited(doorId, reader.ReadEncoded(1) != 0); + SetDoorVisited(doorId, reader.ReadBits(1) != 0); } - x38_mapStationUsed = reader.ReadEncoded(1) != 0; + x38_mapStationUsed = reader.ReadBits(1) != 0; } -void CMapWorldInfo::PutTo(CBitStreamWriter& writer, const CWorldSaveGameInfo& savw, CAssetId mlvlId) const { +void CMapWorldInfo::PutTo(COutputStream& writer, const CWorldSaveGameInfo& savw, CAssetId mlvlId) const { const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId); for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) { if (i < x0_visitedAreasAllocated) { - writer.WriteEncoded(u32(IsAreaVisited(i)), 1); + writer.WriteBits(u32(IsAreaVisited(i)), 1); } else { - writer.WriteEncoded(0, 1); + writer.WriteBits(0, 1); } } for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) { if (i < x14_mappedAreasAllocated) { - writer.WriteEncoded(u32(IsMapped(i)), 1); + writer.WriteBits(u32(IsMapped(i)), 1); } else { - writer.WriteEncoded(0, 1); + writer.WriteBits(0, 1); } } for (const auto& doorId : savw.GetDoors()) { - writer.WriteEncoded(u32(IsDoorVisited(doorId)), 1); + writer.WriteBits(u32(IsDoorVisited(doorId)), 1); } - writer.WriteEncoded(u32(x38_mapStationUsed), 1); + writer.WriteBits(u32(x38_mapStationUsed), 1); } void CMapWorldInfo::SetDoorVisited(TEditorId eid, bool visited) { x28_visitedDoors[eid] = visited; } diff --git a/Runtime/AutoMapper/CMapWorldInfo.hpp b/Runtime/AutoMapper/CMapWorldInfo.hpp index 14474e8fc..642dfef99 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.hpp +++ b/Runtime/AutoMapper/CMapWorldInfo.hpp @@ -19,8 +19,8 @@ class CMapWorldInfo { public: CMapWorldInfo() = default; - explicit CMapWorldInfo(CBitStreamReader& reader, const CWorldSaveGameInfo& saveWorld, CAssetId mlvlId); - void PutTo(CBitStreamWriter& writer, const CWorldSaveGameInfo& savw, CAssetId mlvlId) const; + explicit CMapWorldInfo(CInputStream& reader, const CWorldSaveGameInfo& saveWorld, CAssetId mlvlId); + void PutTo(COutputStream& writer, const CWorldSaveGameInfo& savw, CAssetId mlvlId) const; bool IsMapped(TAreaId aid) const; void SetIsMapped(TAreaId aid, bool mapped); void SetDoorVisited(TEditorId eid, bool val); diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index 5c57d7530..f4edeafd9 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -15,12 +15,12 @@ std::array CMappableObject::skDoorIndices{ }; CMappableObject::CMappableObject(const void* buf) { - athena::io::MemoryReader r(buf, 64); - x0_type = EMappableObjectType(r.readUint32Big()); - x4_visibilityMode = EVisMode(r.readUint32Big()); - x8_objId = r.readUint32Big(); - xc_ = r.readUint32Big(); - x10_transform.read34RowMajor(r); + CMemoryInStream r(buf, 64); + x0_type = EMappableObjectType(r.ReadLong()); + x4_visibilityMode = EVisMode(r.ReadLong()); + x8_objId = r.ReadLong(); + xc_ = r.ReadLong(); + x10_transform = r.Get(); } zeus::CTransform CMappableObject::AdjustTransformForType() const { diff --git a/Runtime/CBasics.hpp b/Runtime/CBasics.hpp index 7e761fea0..b760f00bf 100644 --- a/Runtime/CBasics.hpp +++ b/Runtime/CBasics.hpp @@ -40,6 +40,14 @@ public: static OSCalendarTime ToCalendarTime(OSTime time) { return ToCalendarTime(FromWiiTime(time)); } static OSCalendarTime ToCalendarTime(std::chrono::system_clock::time_point time); + static u16 SwapBytes(u16 v); + static u32 SwapBytes(u32 v); + static u64 SwapBytes(u64 v); + static float SwapBytes(float v); + static double SwapBytes(double s); + static void Swap2Bytes(u8* v); + static void Swap4Bytes(u8* v); + static void Swap8Bytes(u8* v); }; } // namespace metaforce diff --git a/Runtime/CBasicsPC.cpp b/Runtime/CBasicsPC.cpp index 36262e260..868006163 100644 --- a/Runtime/CBasicsPC.cpp +++ b/Runtime/CBasicsPC.cpp @@ -136,4 +136,63 @@ OSCalendarTime CBasics::ToCalendarTime(std::chrono::system_clock::time_point tim return ret; } +u16 CBasics::SwapBytes(u16 v) { + Swap2Bytes(reinterpret_cast(&v)); + return v; +} +u32 CBasics::SwapBytes(u32 v) { + Swap4Bytes(reinterpret_cast(&v)); + return v; +} + +u64 CBasics::SwapBytes(u64 v) { + Swap8Bytes(reinterpret_cast(&v)); + return v; +} +float CBasics::SwapBytes(float v) { + Swap4Bytes(reinterpret_cast(&v)); + return v; +} +double CBasics::SwapBytes(double v) { + Swap8Bytes(reinterpret_cast(&v)); + return v; +} + +void CBasics::Swap2Bytes(u8* v) { + u16* val = reinterpret_cast(v); +#if __GNUC__ + *val = __builtin_bswap16(*val); +#elif _WIN32 + *val = _byteswap_ushort(*val); +#else + *val = (*val << 8) | ((*val >> 8) & 0xFF); +#endif +} + +void CBasics::Swap4Bytes(u8* v) { + u32* val = reinterpret_cast(v); +#if __GNUC__ + *val = __builtin_bswap32(*val); +#elif _WIN32 + *val = _byteswap_ulong(*val); +#else + *val = ((*val & 0x0000FFFF) << 16) | ((*val & 0xFFFF0000) >> 16) | ((*val & 0x00FF00FF) << 8) | + ((*val & 0xFF00FF00) >> 8); +#endif +} + +void CBasics::Swap8Bytes(u8* v) { + u64* val = reinterpret_cast(v); +#if __GNUC__ + *val = __builtin_bswap64(*val); +#elif _WIN32 + *val = _byteswap_uint64(val); +#else + *val = ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) | + ((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) | + ((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) | + ((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56); +#endif +} + } // namespace metaforce diff --git a/Runtime/CDependencyGroup.cpp b/Runtime/CDependencyGroup.cpp index bc6064eae..ae1391b86 100644 --- a/Runtime/CDependencyGroup.cpp +++ b/Runtime/CDependencyGroup.cpp @@ -5,7 +5,7 @@ namespace metaforce { CDependencyGroup::CDependencyGroup(CInputStream& in) { ReadFromStream(in); } void CDependencyGroup::ReadFromStream(CInputStream& in) { - u32 depCount = in.readUint32Big(); + u32 depCount = in.ReadLong(); x0_objectTags.reserve(depCount); for (u32 i = 0; i < depCount; i++) x0_objectTags.emplace_back(in); diff --git a/Runtime/CFactoryMgr.cpp b/Runtime/CFactoryMgr.cpp index 72fda9658..c391f9eb1 100644 --- a/Runtime/CFactoryMgr.cpp +++ b/Runtime/CFactoryMgr.cpp @@ -42,10 +42,12 @@ CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::u const auto memFactoryIter = m_memFactories.find(tag.type); if (memFactoryIter != m_memFactories.cend()) { if (compressed) { - std::unique_ptr compRead = std::make_unique(localBuf.get(), size); - const u32 decompLen = compRead->readUint32Big(); + std::unique_ptr compRead = + std::make_unique(localBuf.get(), size, CMemoryInStream::EOwnerShip::NotOwned); + const u32 decompLen = compRead->ReadLong(); CZipInputStream r(std::move(compRead)); - std::unique_ptr decompBuf = r.readUBytes(decompLen); + std::unique_ptr decompBuf(new u8[decompLen]); + r.Get(decompBuf.get(), decompLen); return memFactoryIter->second(tag, std::move(decompBuf), decompLen, paramXfer, selfRef); } else { return memFactoryIter->second(tag, std::move(localBuf), size, paramXfer, selfRef); @@ -57,12 +59,14 @@ CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::u } if (compressed) { - std::unique_ptr compRead = std::make_unique(localBuf.get(), size); - compRead->readUint32Big(); + std::unique_ptr compRead = + std::make_unique(localBuf.get(), size, CMemoryInStream::EOwnerShip::NotOwned); + + compRead->ReadLong(); CZipInputStream r(std::move(compRead)); return factoryIter->second(tag, r, paramXfer, selfRef); } else { - CMemoryInStream r(localBuf.get(), size); + CMemoryInStream r(localBuf.get(), size, CMemoryInStream::EOwnerShip::NotOwned); return factoryIter->second(tag, r, paramXfer, selfRef); } } diff --git a/Runtime/CGameHintInfo.cpp b/Runtime/CGameHintInfo.cpp index be625c576..02172e1fa 100644 --- a/Runtime/CGameHintInfo.cpp +++ b/Runtime/CGameHintInfo.cpp @@ -7,29 +7,29 @@ namespace metaforce { CGameHintInfo::CGameHintInfo(CInputStream& in, s32 version) { - u32 hintCount = in.readUint32Big(); + u32 hintCount = in.ReadLong(); x0_hints.reserve(hintCount); for (u32 i = 0; i < hintCount; ++i) x0_hints.emplace_back(in, version); } CGameHintInfo::CGameHint::CGameHint(CInputStream& in, s32 version) -: x0_name(in.readString()) -, x10_immediateTime(in.readFloatBig()) -, x14_normalTime(in.readFloatBig()) -, x18_stringId(in.readUint32Big()) -, x1c_textTime(3.f * float(version <= 0 ? 1 : in.readUint32Big())) { - u32 locationCount = in.readUint32Big(); +: x0_name(in.Get()) +, x10_immediateTime(in.ReadFloat()) +, x14_normalTime(in.ReadFloat()) +, x18_stringId(in.ReadLong()) +, x1c_textTime(3.f * float(version <= 0 ? 1 : in.ReadLong())) { + u32 locationCount = in.ReadLong(); x20_locations.reserve(locationCount); for (u32 i = 0; i < locationCount; ++i) x20_locations.emplace_back(in, version); } CGameHintInfo::SHintLocation::SHintLocation(CInputStream& in, s32) -: x0_mlvlId(in.readUint32Big()) -, x4_mreaId(in.readUint32Big()) -, x8_areaId(in.readUint32Big()) -, xc_stringId(in.readUint32Big()) {} +: x0_mlvlId(in.ReadLong()) +, x4_mreaId(in.ReadLong()) +, x8_areaId(in.ReadLong()) +, xc_stringId(in.ReadLong()) {} int CGameHintInfo::FindHintIndex(std::string_view str) { const std::vector& gameHints = g_MemoryCardSys->GetHints(); @@ -40,8 +40,8 @@ int CGameHintInfo::FindHintIndex(std::string_view str) { } CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&, CObjectReference*) { - in.readUint32Big(); - s32 version = in.readInt32Big(); + in.ReadLong(); + s32 version = in.ReadInt32(); return TToken::GetIObjObjectFor(std::make_unique(in, version)); } diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index d03ef368b..e7a366479 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -96,26 +96,26 @@ constexpr std::array, 5> GameOptionsRegist {0, nullptr}, }}; -CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) { +CPersistentOptions::CPersistentOptions(CInputStream& stream) { for (u8& entry : x0_nesState) { - entry = stream.ReadEncoded(8); + entry = stream.ReadBits(8); } for (bool& entry : x68_) { - entry = stream.ReadEncoded(8) != 0; + entry = stream.ReadBits(8) != 0; } - xc0_frozenFpsCount = stream.ReadEncoded(2); - xc4_frozenBallCount = stream.ReadEncoded(2); - xc8_powerBombAmmoCount = stream.ReadEncoded(1); - xcc_logScanPercent = stream.ReadEncoded(7); - xd0_24_fusionLinked = stream.ReadEncoded(1) != 0; - xd0_25_normalModeBeat = stream.ReadEncoded(1) != 0; - xd0_26_hardModeBeat = stream.ReadEncoded(1) != 0; - xd0_27_fusionBeat = stream.ReadEncoded(1) != 0; + xc0_frozenFpsCount = stream.ReadBits(2); + xc4_frozenBallCount = stream.ReadBits(2); + xc8_powerBombAmmoCount = stream.ReadBits(1); + xcc_logScanPercent = stream.ReadBits(7); + xd0_24_fusionLinked = stream.ReadBits(1) != 0; + xd0_25_normalModeBeat = stream.ReadBits(1) != 0; + xd0_26_hardModeBeat = stream.ReadBits(1) != 0; + xd0_27_fusionBeat = stream.ReadBits(1) != 0; xd0_28_fusionSuitActive = false; - xd0_29_allItemsCollected = stream.ReadEncoded(1) != 0; - xbc_autoMapperKeyState = stream.ReadEncoded(2); + xd0_29_allItemsCollected = stream.ReadBits(1) != 0; + xbc_autoMapperKeyState = stream.ReadBits(2); const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); size_t cinematicCount = 0; @@ -128,7 +128,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) { std::vector cinematicStates; cinematicStates.reserve(cinematicCount); for (size_t i = 0; i < cinematicCount; ++i) { - cinematicStates.push_back(stream.ReadEncoded(1) != 0); + cinematicStates.push_back(stream.ReadBits(1) != 0); } for (const auto& world : memWorlds) { @@ -142,25 +142,25 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) { } } -void CPersistentOptions::PutTo(CBitStreamWriter& w) const { +void CPersistentOptions::PutTo(COutputStream& w) const { for (const u8 entry : x0_nesState) { - w.WriteEncoded(entry, 8); + w.WriteBits(entry, 8); } for (const bool entry : x68_) { - w.WriteEncoded(u32(entry), 8); + w.WriteBits(u32(entry), 8); } - w.WriteEncoded(xc0_frozenFpsCount, 2); - w.WriteEncoded(xc4_frozenBallCount, 2); - w.WriteEncoded(xc8_powerBombAmmoCount, 1); - w.WriteEncoded(xcc_logScanPercent, 7); - w.WriteEncoded(xd0_24_fusionLinked, 1); - w.WriteEncoded(xd0_25_normalModeBeat, 1); - w.WriteEncoded(xd0_26_hardModeBeat, 1); - w.WriteEncoded(xd0_27_fusionBeat, 1); - w.WriteEncoded(xd0_29_allItemsCollected, 1); - w.WriteEncoded(xbc_autoMapperKeyState, 2); + w.WriteBits(xc0_frozenFpsCount, 2); + w.WriteBits(xc4_frozenBallCount, 2); + w.WriteBits(xc8_powerBombAmmoCount, 1); + w.WriteBits(xcc_logScanPercent, 7); + w.WriteBits(xd0_24_fusionLinked, 1); + w.WriteBits(xd0_25_normalModeBeat, 1); + w.WriteBits(xd0_26_hardModeBeat, 1); + w.WriteBits(xd0_27_fusionBeat, 1); + w.WriteBits(xd0_29_allItemsCollected, 1); + w.WriteBits(xbc_autoMapperKeyState, 2); const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); for (const auto& world : memWorlds) { @@ -168,7 +168,7 @@ void CPersistentOptions::PutTo(CBitStreamWriter& w) const { g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), world.second.GetSaveWorldAssetId()}); for (const auto& cineId : saveWorld->GetCinematics()) { - w.WriteEncoded(u32(GetCinematicState(world.first, cineId)), 1); + w.WriteBits(u32(GetCinematicState(world.first, cineId)), 1); } } } @@ -194,26 +194,26 @@ void CPersistentOptions::SetCinematicState(CAssetId mlvlId, TEditorId cineId, bo xac_cinematicStates.erase(existing); } -CGameOptions::CGameOptions(CBitStreamReader& stream) { +CGameOptions::CGameOptions(CInputStream& stream) { for (u8& entry : x0_) - entry = stream.ReadEncoded(8); + entry = stream.ReadBits(8); - x44_soundMode = CAudioSys::ESurroundModes(stream.ReadEncoded(2)); - x48_screenBrightness = stream.ReadEncoded(4); + x44_soundMode = CAudioSys::ESurroundModes(stream.ReadBits(2)); + x48_screenBrightness = stream.ReadBits(4); - x4c_screenXOffset = stream.ReadEncoded(6) - 30; - x50_screenYOffset = stream.ReadEncoded(6) - 30; - x54_screenStretch = stream.ReadEncoded(5) - 10; - x58_sfxVol = stream.ReadEncoded(7); - x5c_musicVol = stream.ReadEncoded(7); - x60_hudAlpha = stream.ReadEncoded(8); - x64_helmetAlpha = stream.ReadEncoded(8); + x4c_screenXOffset = stream.ReadBits(6) - 30; + x50_screenYOffset = stream.ReadBits(6) - 30; + x54_screenStretch = stream.ReadBits(5) - 10; + x58_sfxVol = stream.ReadBits(7); + x5c_musicVol = stream.ReadBits(7); + x60_hudAlpha = stream.ReadBits(8); + x64_helmetAlpha = stream.ReadBits(8); - x68_24_hudLag = stream.ReadEncoded(1) != 0; - x68_28_hintSystem = stream.ReadEncoded(1) != 0; - x68_25_invertY = stream.ReadEncoded(1) != 0; - x68_26_rumble = stream.ReadEncoded(1) != 0; - x68_27_swapBeamsControls = stream.ReadEncoded(1) != 0; + x68_24_hudLag = stream.ReadBits(1) != 0; + x68_28_hintSystem = stream.ReadBits(1) != 0; + x68_25_invertY = stream.ReadBits(1) != 0; + x68_26_rumble = stream.ReadBits(1) != 0; + x68_27_swapBeamsControls = stream.ReadBits(1) != 0; } void CGameOptions::ResetToDefaults() { @@ -235,26 +235,26 @@ void CGameOptions::ResetToDefaults() { EnsureSettings(); } -void CGameOptions::PutTo(CBitStreamWriter& writer) const { +void CGameOptions::PutTo(COutputStream& writer) const { for (const u8 entry : x0_) - writer.WriteEncoded(entry, 8); + writer.WriteBits(entry, 8); - writer.WriteEncoded(u32(x44_soundMode), 2); - writer.WriteEncoded(x48_screenBrightness, 4); + writer.WriteBits(u32(x44_soundMode), 2); + writer.WriteBits(x48_screenBrightness, 4); - writer.WriteEncoded(x4c_screenXOffset + 30, 6); - writer.WriteEncoded(x50_screenYOffset + 30, 6); - writer.WriteEncoded(x54_screenStretch + 10, 5); - writer.WriteEncoded(x58_sfxVol, 7); - writer.WriteEncoded(x5c_musicVol, 7); - writer.WriteEncoded(x60_hudAlpha, 8); - writer.WriteEncoded(x64_helmetAlpha, 8); + writer.WriteBits(x4c_screenXOffset + 30, 6); + writer.WriteBits(x50_screenYOffset + 30, 6); + writer.WriteBits(x54_screenStretch + 10, 5); + writer.WriteBits(x58_sfxVol, 7); + writer.WriteBits(x5c_musicVol, 7); + writer.WriteBits(x60_hudAlpha, 8); + writer.WriteBits(x64_helmetAlpha, 8); - writer.WriteEncoded(x68_24_hudLag, 1); - writer.WriteEncoded(x68_28_hintSystem, 1); - writer.WriteEncoded(x68_25_invertY, 1); - writer.WriteEncoded(x68_26_rumble, 1); - writer.WriteEncoded(x68_27_swapBeamsControls, 1); + writer.WriteBits(x68_24_hudLag, 1); + writer.WriteBits(x68_28_hintSystem, 1); + writer.WriteBits(x68_25_invertY, 1); + writer.WriteBits(x68_26_rumble, 1); + writer.WriteBits(x68_27_swapBeamsControls, 1); } CGameOptions::CGameOptions() @@ -579,14 +579,14 @@ int CGameOptions::GetOption(EGameOption option) { return 0; } -CHintOptions::CHintOptions(CBitStreamReader& stream) { +CHintOptions::CHintOptions(CInputStream& stream) { const auto& hints = g_MemoryCardSys->GetHints(); x0_hintStates.reserve(hints.size()); u32 hintIdx = 0; for ([[maybe_unused]] const auto& hint : hints) { - const auto state = EHintState(stream.ReadEncoded(2)); - const s32 timeBits = stream.ReadEncoded(32); + const auto state = EHintState(stream.ReadBits(2)); + const s32 timeBits = stream.ReadBits(32); float time; std::memcpy(&time, &timeBits, sizeof(s32)); if (state == EHintState::Zero) { @@ -602,14 +602,14 @@ CHintOptions::CHintOptions(CBitStreamReader& stream) { } } -void CHintOptions::PutTo(CBitStreamWriter& writer) const { +void CHintOptions::PutTo(COutputStream& writer) const { for (const SHintState& hint : x0_hintStates) { - writer.WriteEncoded(u32(hint.x0_state), 2); + writer.WriteBits(u32(hint.x0_state), 2); u32 timeBits; std::memcpy(&timeBits, &hint.x4_time, sizeof(timeBits)); - writer.WriteEncoded(timeBits, 32); + writer.WriteBits(timeBits, 32); } } diff --git a/Runtime/CGameOptions.hpp b/Runtime/CGameOptions.hpp index 84b7b2b07..c30ce87d3 100644 --- a/Runtime/CGameOptions.hpp +++ b/Runtime/CGameOptions.hpp @@ -66,7 +66,7 @@ class CPersistentOptions { public: CPersistentOptions() = default; - explicit CPersistentOptions(CBitStreamReader& stream); + explicit CPersistentOptions(CInputStream& stream); bool GetCinematicState(CAssetId mlvlId, TEditorId cineId) const; void SetCinematicState(CAssetId mlvlId, TEditorId cineId, bool state); @@ -93,7 +93,7 @@ public: bool GetShowPowerBombAmmoMessage() const { return xc8_powerBombAmmoCount != 1; } void IncrementPowerBombAmmoCount() { xc8_powerBombAmmoCount = std::min(1, xc8_powerBombAmmoCount + 1); } - void PutTo(CBitStreamWriter& w) const; + void PutTo(COutputStream& w) const; u8* GetNESState() { return x0_nesState.data(); } const u8* GetNESState() const { return x0_nesState.data(); } @@ -122,11 +122,11 @@ class CGameOptions { public: CGameOptions(); - explicit CGameOptions(CBitStreamReader& stream); + explicit CGameOptions(CInputStream& stream); void ResetToDefaults(); void InitSoundMode(); void EnsureSettings(); - void PutTo(CBitStreamWriter& writer) const; + void PutTo(COutputStream& writer) const; float TuneScreenBrightness() const; void SetScreenBrightness(s32 value, bool apply); @@ -189,8 +189,8 @@ private: public: CHintOptions() = default; - explicit CHintOptions(CBitStreamReader& stream); - void PutTo(CBitStreamWriter& writer) const; + explicit CHintOptions(CInputStream& stream); + void PutTo(COutputStream& writer) const; void SetNextHintTime(); void InitializeMemoryState(); const SHintState* GetCurrentDisplayedHint() const; diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index ccfbc9a6c..012b679a3 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -23,12 +23,12 @@ union BitsToDouble { double doub; }; -CScriptLayerManager::CScriptLayerManager(CBitStreamReader& reader, const CWorldSaveGameInfo& saveWorld) { - const u32 bitCount = reader.ReadEncoded(10); +CScriptLayerManager::CScriptLayerManager(CInputStream& reader, const CWorldSaveGameInfo& saveWorld) { + const u32 bitCount = reader.ReadBits(10); x10_saveLayers.reserve(bitCount); for (u32 i = 0; i < bitCount; ++i) { - const bool bit = reader.ReadEncoded(1) != 0; + const bool bit = reader.ReadBits(1) != 0; if (bit) { x10_saveLayers.setBit(i); } else { @@ -37,18 +37,18 @@ CScriptLayerManager::CScriptLayerManager(CBitStreamReader& reader, const CWorldS } } -void CScriptLayerManager::PutTo(CBitStreamWriter& writer) const { +void CScriptLayerManager::PutTo(COutputStream& writer) const { u32 totalLayerCount = 0; for (size_t i = 0; i < x0_areaLayers.size(); ++i) { totalLayerCount += GetAreaLayerCount(s32(i)) - 1; } - writer.WriteEncoded(totalLayerCount, 10); + writer.WriteBits(totalLayerCount, 10); for (size_t i = 0; i < x0_areaLayers.size(); ++i) { const u32 count = GetAreaLayerCount(s32(i)); for (u32 l = 1; l < count; ++l) { - writer.WriteEncoded(IsLayerActive(s32(i), s32(l)), 1); + writer.WriteBits(IsLayerActive(s32(i), s32(l)), 1); } } } @@ -81,40 +81,40 @@ CWorldState::CWorldState(CAssetId id) : x0_mlvlId(id), x4_areaId(0) { x14_layerState = std::make_shared(); } -CWorldState::CWorldState(CBitStreamReader& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld) +CWorldState::CWorldState(CInputStream& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld) : x0_mlvlId(mlvlId) { - x4_areaId = TAreaId(reader.ReadEncoded(32)); - x10_desiredAreaAssetId = u32(reader.ReadEncoded(32)); + x4_areaId = TAreaId(reader.ReadBits(32)); + x10_desiredAreaAssetId = u32(reader.ReadBits(32)); x8_mailbox = std::make_shared(reader, saveWorld); xc_mapWorldInfo = std::make_shared(reader, saveWorld, mlvlId); x14_layerState = std::make_shared(reader, saveWorld); } -void CWorldState::PutTo(CBitStreamWriter& writer, const CWorldSaveGameInfo& savw) const { - writer.WriteEncoded(x4_areaId, 32); - writer.WriteEncoded(u32(x10_desiredAreaAssetId.Value()), 32); +void CWorldState::PutTo(COutputStream& writer, const CWorldSaveGameInfo& savw) const { + writer.WriteBits(x4_areaId, 32); + writer.WriteBits(u32(x10_desiredAreaAssetId.Value()), 32); x8_mailbox->PutTo(writer, savw); xc_mapWorldInfo->PutTo(writer, savw, x0_mlvlId); x14_layerState->PutTo(writer); } CGameState::GameFileStateInfo CGameState::LoadGameFileState(const u8* data) { - CBitStreamReader stream(data, 4096); + CMemoryInStream stream(data, 4096, CMemoryInStream::EOwnerShip::NotOwned); GameFileStateInfo ret; for (u32 i = 0; i < 128; i++) { - stream.ReadEncoded(8); + stream.ReadBits(8); } - ret.x14_timestamp = stream.ReadEncoded(32); + ret.x14_timestamp = stream.ReadBits(32); - ret.x20_hardMode = stream.ReadEncoded(1) != 0; - stream.ReadEncoded(1); - const CAssetId origMLVL = u32(stream.ReadEncoded(32)); + ret.x20_hardMode = stream.ReadBits(1) != 0; + stream.ReadBits(1); + const CAssetId origMLVL = u32(stream.ReadBits(32)); ret.x8_mlvlId = origMLVL; BitsToDouble conv; - conv.low = stream.ReadEncoded(32); - conv.high = stream.ReadEncoded(32); + conv.low = stream.ReadBits(32); + conv.high = stream.ReadBits(32); ret.x0_playTime = conv.doub; CPlayerState playerState(stream); @@ -148,24 +148,24 @@ CGameState::CGameState() { } } -CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx) : x20c_saveFileIdx(saveIdx) { +CGameState::CGameState(CInputStream& stream, u32 saveIdx) : x20c_saveFileIdx(saveIdx) { x9c_transManager = std::make_shared(); x228_24_hardMode = false; x228_25_initPowerupsAtFirstSpawn = true; for (bool& value : x0_) { - value = stream.ReadEncoded(8) != 0; + value = stream.ReadBits(8) != 0; } - stream.ReadEncoded(32); + stream.ReadBits(32); - x228_24_hardMode = stream.ReadEncoded(1) != 0; - x228_25_initPowerupsAtFirstSpawn = stream.ReadEncoded(1) != 0; - x84_mlvlId = u32(stream.ReadEncoded(32)); + x228_24_hardMode = stream.ReadBits(1) != 0; + x228_25_initPowerupsAtFirstSpawn = stream.ReadBits(1) != 0; + x84_mlvlId = u32(stream.ReadBits(32)); MP1::CMain::EnsureWorldPakReady(x84_mlvlId); BitsToDouble conv; - conv.low = stream.ReadEncoded(32); - conv.high = stream.ReadEncoded(32); + conv.low = stream.ReadBits(32); + conv.high = stream.ReadBits(32); xa0_playTime = conv.doub; x98_playerState = std::make_shared(stream); @@ -185,7 +185,7 @@ CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx) : x20c_saveFileIdx WriteBackupBuf(); } -void CGameState::ReadPersistentOptions(CBitStreamReader& r) { xa8_systemOptions = CPersistentOptions(r); } +void CGameState::ReadPersistentOptions(CInputStream& r) { xa8_systemOptions = r.Get(); } void CGameState::ImportPersistentOptions(const CPersistentOptions& opts) { if (opts.xd0_24_fusionLinked) @@ -212,24 +212,24 @@ void CGameState::ExportPersistentOptions(CPersistentOptions& opts) const { void CGameState::WriteBackupBuf() { x218_backupBuf.resize(940); - CBitStreamWriter w(x218_backupBuf.data(), 940); + CMemoryStreamOut w(x218_backupBuf.data(), 940); PutTo(w); } -void CGameState::PutTo(CBitStreamWriter& writer) { +void CGameState::PutTo(COutputStream& writer) { for (const bool value : x0_) { - writer.WriteEncoded(u32(value), 8); + writer.WriteBits(u32(value), 8); } - writer.WriteEncoded(CBasics::GetTime() / CBasics::TICKS_PER_SECOND, 32); - writer.WriteEncoded(x228_24_hardMode, 1); - writer.WriteEncoded(x228_25_initPowerupsAtFirstSpawn, 1); - writer.WriteEncoded(u32(x84_mlvlId.Value()), 32); + writer.WriteBits(CBasics::GetTime() / CBasics::TICKS_PER_SECOND, 32); + writer.WriteBits(x228_24_hardMode, 1); + writer.WriteBits(x228_25_initPowerupsAtFirstSpawn, 1); + writer.WriteBits(u32(x84_mlvlId.Value()), 32); BitsToDouble conv; conv.doub = xa0_playTime; - writer.WriteEncoded(conv.low, 32); - writer.WriteEncoded(conv.high, 32); + writer.WriteBits(conv.low, 32); + writer.WriteBits(conv.high, 32); x98_playerState->PutTo(writer); x17c_gameOptions.PutTo(writer); diff --git a/Runtime/CGameState.hpp b/Runtime/CGameState.hpp index 86bf1df80..0c411b1ce 100644 --- a/Runtime/CGameState.hpp +++ b/Runtime/CGameState.hpp @@ -24,7 +24,7 @@ class CScriptLayerManager { public: CScriptLayerManager() = default; - CScriptLayerManager(CBitStreamReader& reader, const CWorldSaveGameInfo& saveWorld); + CScriptLayerManager(CInputStream& reader, const CWorldSaveGameInfo& saveWorld); bool IsLayerActive(int areaIdx, int layerIdx) const { return ((x0_areaLayers[areaIdx].m_layerBits >> layerIdx) & 1); } @@ -40,7 +40,7 @@ public: u32 GetAreaLayerCount(int areaIdx) const { return x0_areaLayers[areaIdx].m_layerCount; } u32 GetAreaCount() const { return x0_areaLayers.size(); } - void PutTo(CBitStreamWriter& writer) const; + void PutTo(COutputStream& writer) const; }; class CWorldState { @@ -53,7 +53,7 @@ class CWorldState { public: explicit CWorldState(CAssetId id); - CWorldState(CBitStreamReader& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld); + CWorldState(CInputStream& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld); CAssetId GetWorldAssetId() const { return x0_mlvlId; } void SetAreaId(TAreaId aid) { x4_areaId = aid; } TAreaId GetCurrentAreaId() const { return x4_areaId; } @@ -62,7 +62,7 @@ public: const std::shared_ptr& Mailbox() const { return x8_mailbox; } const std::shared_ptr& MapWorldInfo() const { return xc_mapWorldInfo; } const std::shared_ptr& GetLayerState() const { return x14_layerState; } - void PutTo(CBitStreamWriter& writer, const CWorldSaveGameInfo& savw) const; + void PutTo(COutputStream& writer, const CWorldSaveGameInfo& savw) const; }; class CGameState { @@ -86,7 +86,7 @@ class CGameState { public: CGameState(); - CGameState(CBitStreamReader& stream, u32 saveIdx); + CGameState(CInputStream& stream, u32 saveIdx); void SetCurrentWorldId(CAssetId id); std::shared_ptr GetPlayerState() const { return x98_playerState; } std::shared_ptr GetWorldTransitionManager() const { return x9c_transManager; } @@ -100,7 +100,7 @@ public: CAssetId CurrentWorldAssetId() const { return x84_mlvlId; } void SetHardMode(bool v) { x228_24_hardMode = v; } bool GetHardMode() const { return x228_24_hardMode; } - void ReadPersistentOptions(CBitStreamReader& r); + void ReadPersistentOptions(CInputStream& r); void SetPersistentOptions(const CPersistentOptions& opts) { xa8_systemOptions = opts; } void ImportPersistentOptions(const CPersistentOptions& opts); void ExportPersistentOptions(CPersistentOptions& opts) const; @@ -111,7 +111,7 @@ public: void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; } void SetCardSerial(u64 serial) { x210_cardSerial = serial; } u64 GetCardSerial() const { return x210_cardSerial; } - void PutTo(CBitStreamWriter& writer); + void PutTo(COutputStream& writer); float GetHardModeDamageMultiplier() const; float GetHardModeWeaponMultiplier() const; void InitializeMemoryWorlds(); diff --git a/Runtime/CInputStream.cpp b/Runtime/CInputStream.cpp new file mode 100644 index 000000000..1113bc7c8 --- /dev/null +++ b/Runtime/CInputStream.cpp @@ -0,0 +1,278 @@ +#include "CInputStream.hpp" +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ +#include "Runtime/CBasics.hpp" +#endif + +#include + +namespace metaforce { +static u32 min_containing_bytes(u32 v) { + v = 32 - v; + v = (v >> 3) - ((s32) - (v & 7) >> 31); + return v; +} + +CInputStream::CInputStream(s32 len) : xc_len(len), x10_ptr(new u8[len]), x14_owned(true) {} +CInputStream::CInputStream(const void* ptr, u32 len, bool owned) +: x8_blockLen(len), xc_len(len), x10_ptr(reinterpret_cast(ptr)), x14_owned(owned) {} + +CInputStream::~CInputStream() { + if (x14_owned) { + delete[] x10_ptr; + } +} + +bool CInputStream::InternalReadNext() { + x8_blockLen = Read(const_cast(x10_ptr), xc_len); + x4_blockOffset = 0; + return x8_blockLen != 0; +} + +bool CInputStream::GrabAnotherBlock() { return InternalReadNext(); } + +void CInputStream::Get(u8* dest, u32 len) { + x20_bitOffset = 0; + u32 offset = 0; + while (len != 0) { + u32 blockLen = x8_blockLen - x4_blockOffset; + if (len < blockLen) { + blockLen = len; + } + + if (blockLen == 0) { + if (len <= 256) { + GrabAnotherBlock(); + } else { + u32 readLen = Read(dest + offset, len); + len -= readLen; + offset += readLen; + } + } else { + memcpy(dest + offset, x10_ptr + x4_blockOffset, blockLen); + len -= blockLen; + x4_blockOffset += blockLen; + } + } + + x18_readPosition += offset; +} + +u32 CInputStream::ReadBytes(void* dest, u32 len) { + if (len == 0) { + return 0; + } + + if (x4_blockOffset == x8_blockLen) { + GrabAnotherBlock(); + } + + u32 curReadLen = 0; + u32 curLen = len; + + do { + while (true) { + if (len <= curReadLen) { + x18_readPosition += curReadLen; + return curReadLen; + } + + u32 readCount = x8_blockLen - x4_blockOffset; + if (readCount == 0) { + break; + } + + if (curLen < readCount) { + readCount = curLen; + } + + memcpy(reinterpret_cast(dest) + curReadLen, x10_ptr + x4_blockOffset, readCount); + curReadLen += readCount; + curLen -= readCount; + } + } while (InternalReadNext()); + + return curReadLen; +} + +u32 CInputStream::ReadBits(u32 bitCount) { + u32 ret = x20_bitOffset; + if (ret < bitCount) { + const u32 shiftAmt = bitCount - x20_bitOffset; + const u32 mask = ret == 32 ? -1 : (1 << x20_bitOffset) - 1; + + u32 uVar2 = x1c_bitWord; + x20_bitOffset = 0; + u32 len = min_containing_bytes(shiftAmt); + Get(reinterpret_cast(&x1c_bitWord), len); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + x1c_bitWord = CBasics::SwapBytes(x1c_bitWord); +#endif + + const u32 retMask = shiftAmt == 32 ? -1 : (1 << shiftAmt) - 1; + const u32 tmpOffset = x20_bitOffset; + x20_bitOffset = len * 8; + ret = ((mask & uVar2) >> (32 - ret) << shiftAmt) | (retMask & (x1c_bitWord >> (32 - shiftAmt))) << tmpOffset; + x20_bitOffset -= shiftAmt; + x1c_bitWord <<= shiftAmt; + } else { + x20_bitOffset -= bitCount; + ret = bitCount == 32 ? -1 : (1 << bitCount) - 1; + ret &= x1c_bitWord >> (32 - bitCount); + x1c_bitWord <<= bitCount; + } + return ret; +} + +char CInputStream::ReadChar() { + u8 tmp = 0; + Get(&tmp, sizeof(tmp)); + return static_cast(tmp); +} + +bool CInputStream::ReadBool() { return Get(); } + +s16 CInputStream::ReadInt16() { + s16 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap2Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +u16 CInputStream::ReadUint16() { + u16 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap2Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +s32 CInputStream::ReadInt32() { + s32 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap4Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +u32 CInputStream::ReadUint32() { + u32 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap4Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +s64 CInputStream::ReadInt64() { + s64 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap8Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +u64 CInputStream::ReadUint64() { + u64 tmp = 0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap8Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +float CInputStream::ReadFloat() { + float tmp = 0.f; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap4Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +float CInputStream::ReadReal32() { return Get(); } + +double CInputStream::ReadDouble() { + double tmp = 0.0; + Get(reinterpret_cast(&tmp), sizeof(tmp)); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + CBasics::Swap8Bytes(reinterpret_cast(&tmp)); +#endif + return tmp; +} + +double CInputStream::ReadReal64() { return Get(); } + +template <> +bool cinput_stream_helper(CInputStream& in) { + return in.ReadChar() != 0; +} + +template <> +s8 cinput_stream_helper(CInputStream& in) { + return in.ReadChar(); +} +template <> +u8 cinput_stream_helper(CInputStream& in) { + return in.ReadChar(); +} + +template <> +s16 cinput_stream_helper(CInputStream& in) { + return in.ReadInt16(); +} + +template <> +s32 cinput_stream_helper(CInputStream& in) { + return in.ReadInt32(); +} + +template <> +u32 cinput_stream_helper(CInputStream& in) { + return in.ReadUint32(); +} + +template <> +s64 cinput_stream_helper(CInputStream& in) { + return in.ReadInt64(); +} + +template <> +u64 cinput_stream_helper(CInputStream& in) { + return in.ReadUint64(); +} + +template <> +float cinput_stream_helper(CInputStream& in) { + return in.ReadFloat(); +} + +template <> +double cinput_stream_helper(CInputStream& in) { + return in.ReadDouble(); +} + +template <> +std::string cinput_stream_helper(CInputStream& in) { + std::string ret; + auto chr = in.ReadChar(); + while (chr != '\0') { + ret += chr; + chr = in.ReadChar(); + } + + return ret; +} + +u32 CInputStream::GetBitCount(u32 val) { + int bits = 0; + for (; val != 0; val >>= 1) { + bits += 1; + } + return bits; +} +} // namespace metaforce diff --git a/Runtime/CInputStream.hpp b/Runtime/CInputStream.hpp new file mode 100644 index 000000000..21298e33a --- /dev/null +++ b/Runtime/CInputStream.hpp @@ -0,0 +1,83 @@ +#pragma once +#include "Runtime/GCNTypes.hpp" +#include + +namespace metaforce { +class CInputStream { + u32 x4_blockOffset = 0; + u32 x8_blockLen = 0; + u32 xc_len = 0; + const u8* x10_ptr = nullptr; + bool x14_owned = false; + u32 x18_readPosition = 0; + u32 x1c_bitWord = 0; + u32 x20_bitOffset = 0; + + bool InternalReadNext(); + bool GrabAnotherBlock(); + +public: + explicit CInputStream(s32 len); + CInputStream(const void* ptr, u32 len, bool owned); + virtual ~CInputStream(); + + virtual u32 Read(void* dest, u32 len) = 0; + + u32 GetReadPosition() const { return x18_readPosition; } + u32 ReadBits(u32 bitCount); + u32 ReadBytes(void* dest, u32 len); + s8 ReadInt8() { return Get(); } + u8 ReadUint8() { return Get(); } + char ReadChar(); + bool ReadBool(); + s16 ReadInt16(); + s16 ReadShort() { return Get(); } + u16 ReadUint16(); + s32 ReadInt32(); + s32 ReadLong() { return Get(); } + u32 ReadUint32(); + s64 ReadInt64(); + s64 ReadLongLong() { return Get(); } + u64 ReadUint64(); + + float ReadReal32(); + float ReadFloat(); + double ReadReal64(); + double ReadDouble(); + + void Get(u8* dest, u32 len); + template + T Get() { + return cinput_stream_helper(*this); + } + + static u32 GetBitCount(u32 val); +}; + +template +T cinput_stream_helper(CInputStream& in) { + return T(in); +} +template <> +bool cinput_stream_helper(CInputStream& in); +template <> +s8 cinput_stream_helper(CInputStream& in); +template <> +u8 cinput_stream_helper(CInputStream& in); +template <> +s16 cinput_stream_helper(CInputStream& in); +template <> +s32 cinput_stream_helper(CInputStream& in); +template <> +u32 cinput_stream_helper(CInputStream& in); +template <> +s64 cinput_stream_helper(CInputStream& in); +template <> +u64 cinput_stream_helper(CInputStream& in); +template <> +float cinput_stream_helper(CInputStream& in); +template <> +double cinput_stream_helper(CInputStream& in); +template <> +std::string cinput_stream_helper(CInputStream& in); +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 7c3042c65..1a85d9f78 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -73,6 +73,11 @@ set(RUNTIME_SOURCES_B ITweak.hpp IMain.hpp CStopwatch.hpp + CMemoryStreamOut.hpp CMemoryStreamOut.cpp + CInputStream.hpp CInputStream.cpp + COutputStream.hpp COutputStream.cpp + CMemoryInStream.hpp + CZipInputStream.hpp CZipInputStream.cpp CGameAllocator.hpp CGameAllocator.cpp CMemoryCardSys.hpp CMemoryCardSys.cpp CScannableObjectInfo.hpp CScannableObjectInfo.cpp @@ -109,7 +114,7 @@ set(RUNTIME_SOURCES_B CToken.hpp CToken.cpp CFactoryMgr.hpp CFactoryMgr.cpp CPakFile.hpp CPakFile.cpp - CStringExtras.hpp + CStringExtras.hpp CStringExtras.cpp IOStreams.hpp IOStreams.cpp CMainFlowBase.hpp CMainFlowBase.cpp CMFGameBase.hpp @@ -125,6 +130,7 @@ set(RUNTIME_SOURCES_B function(add_runtime_common_library name) add_library(${name} ${ARGN}) + target_compile_definitions(${name} PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__") if (COMMAND add_sanitizers) add_sanitizers(${name}) endif () @@ -209,6 +215,7 @@ add_executable(metaforce CMain.cpp ${PLAT_SRCS} ImGuiConsole.hpp ImGuiConsole.cp # target_atdna(metaforce atdna_ImGuiPlayerLoadouts.cpp ImGuiPlayerLoadouts.hpp) # RUNTIME_LIBRARIES repeated here for link ordering target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS}) +target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__") if (COMMAND add_sanitizers) add_sanitizers(metaforce) diff --git a/Runtime/CMayaSpline.cpp b/Runtime/CMayaSpline.cpp index 1802c2edc..ce42e11aa 100644 --- a/Runtime/CMayaSpline.cpp +++ b/Runtime/CMayaSpline.cpp @@ -1,6 +1,6 @@ -#include "CMayaSpline.hpp" +#include "Runtime/CMayaSpline.hpp" -namespace rstl {} // namespace rstl +#include "Runtime/CInputStream.hpp" namespace metaforce { void ValidateTangent(zeus::CVector2f& tangent) { @@ -21,19 +21,19 @@ void ValidateTangent(zeus::CVector2f& tangent) { } CMayaSplineKnot::CMayaSplineKnot(CInputStream& in) { - x0_time = in.readFloatBig(); - x4_amplitude = in.readFloatBig(); - x8_ = in.readByte(); - x9_ = in.readByte(); + x0_time = in.ReadFloat(); + x4_amplitude = in.ReadFloat(); + x8_ = in.ReadInt8(); + x9_ = in.ReadInt8(); if (x8_ == 5) { - float x = in.readFloatBig(); - float y = in.readFloatBig(); + float x = in.ReadFloat(); + float y = in.ReadFloat(); xc_cachedTangentA = {x, y}; } if (x9_ == 5) { - float x = in.readFloatBig(); - float y = in.readFloatBig(); + float x = in.ReadFloat(); + float y = in.ReadFloat(); x14_cachedTangentB = {x, y}; } } @@ -166,17 +166,16 @@ void CMayaSplineKnot::CalculateTangents(CMayaSplineKnot* prev, CMayaSplineKnot* ValidateTangent(x14_cachedTangentB); } -CMayaSpline::CMayaSpline(CInputStream& in, s32 count) { - x0_preInfinity = in.readByte(); - x4_postInfinity = in.readByte(); - u32 knotCount = in.readUint32Big(); +CMayaSpline::CMayaSpline(CInputStream& in, s32 count) : x0_preInfinity(in.ReadInt8()), x4_postInfinity(in.ReadInt8()) { + + u32 knotCount = in.ReadLong(); x8_knots.reserve(knotCount); for (size_t i = 0; i < knotCount; ++i) { x8_knots.emplace_back(in); } - x18_clampMode = in.readByte(); - x1c_minAmplitudeTime = in.readFloatBig(); - x20_maxAmplitudeTime = in.readFloatBig(); + x18_clampMode = in.ReadInt8(); + x1c_minAmplitudeTime = in.ReadFloat(); + x20_maxAmplitudeTime = in.ReadFloat(); } float CMayaSpline::GetMinTime() const { return x8_knots.empty() ? 0.f : x8_knots[0].GetTime(); } diff --git a/Runtime/CMemoryCardSys.cpp b/Runtime/CMemoryCardSys.cpp index 9ae7656d1..31a49efff 100644 --- a/Runtime/CMemoryCardSys.cpp +++ b/Runtime/CMemoryCardSys.cpp @@ -215,12 +215,12 @@ void CMemoryCardSys::CCardFileInfo::BuildCardBuffer() { u32 bannerSz = CalculateBannerDataSize(); x104_cardBuffer.resize((bannerSz + xf4_saveBuffer.size() + 8191) & ~8191); - CMemoryOutStream w(x104_cardBuffer.data(), x104_cardBuffer.size()); - w.writeUint32Big(0); + CMemoryStreamOut w(x104_cardBuffer.data(), x104_cardBuffer.size(), CMemoryStreamOut::EOwnerShip::NotOwned); + w.WriteLong(0); char comment[64]; std::memset(comment, 0, std::size(comment)); std::strncpy(comment, x28_comment.data(), std::size(comment) - 1); - w.writeBytes(comment, 64); + w.Write(reinterpret_cast(comment), 64); WriteBannerData(w); WriteIconData(w); memmove(x104_cardBuffer.data() + bannerSz, xf4_saveBuffer.data(), xf4_saveBuffer.size()); @@ -230,7 +230,7 @@ void CMemoryCardSys::CCardFileInfo::BuildCardBuffer() { xf4_saveBuffer.clear(); } -void CMemoryCardSys::CCardFileInfo::WriteBannerData(CMemoryOutStream& out) const { +void CMemoryCardSys::CCardFileInfo::WriteBannerData(COutputStream& out) const { if (x3c_bannerTex.IsValid()) { const TLockedToken& tex = *x40_bannerTok; u32 bufSz; @@ -239,16 +239,16 @@ void CMemoryCardSys::CCardFileInfo::WriteBannerData(CMemoryOutStream& out) const std::unique_ptr texels = tex->BuildMemoryCardTex(bufSz, fmt, palette); if (fmt == ETexelFormat::RGB5A3) - out.writeBytes(texels.get(), 6144); + out.Write(texels.get(), 6144); else - out.writeBytes(texels.get(), 3072); + out.Write(texels.get(), 3072); if (fmt == ETexelFormat::C8) - out.writeBytes(palette.get(), 512); + out.Write(palette.get(), 512); } } -void CMemoryCardSys::CCardFileInfo::WriteIconData(CMemoryOutStream& out) const { +void CMemoryCardSys::CCardFileInfo::WriteIconData(COutputStream& out) const { std::unique_ptr palette; for (const Icon& icon : x50_iconToks) { u32 bufSz; @@ -256,12 +256,12 @@ void CMemoryCardSys::CCardFileInfo::WriteIconData(CMemoryOutStream& out) const { std::unique_ptr texels = icon.x8_tex->BuildMemoryCardTex(bufSz, fmt, palette); if (fmt == ETexelFormat::RGB5A3) - out.writeBytes(texels.get(), 2048); + out.Write(texels.get(), 2048); else - out.writeBytes(texels.get(), 1024); + out.Write(texels.get(), 1024); } if (palette) - out.writeBytes(palette.get(), 512); + out.Write(palette.get(), 512); } ECardResult CMemoryCardSys::CCardFileInfo::PumpCardTransfer() { diff --git a/Runtime/CMemoryCardSys.hpp b/Runtime/CMemoryCardSys.hpp index 6c99bf540..eec4cec22 100644 --- a/Runtime/CMemoryCardSys.hpp +++ b/Runtime/CMemoryCardSys.hpp @@ -6,11 +6,12 @@ #include #include "Runtime/CGameHintInfo.hpp" -#include "Runtime/CWorldSaveGameInfo.hpp" +#include "Runtime/CMemoryStreamOut.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/rstl.hpp" +#include "Runtime/CWorldSaveGameInfo.hpp" #include "Runtime/GuiSys/CStringTable.hpp" #include "Runtime/World/CWorld.hpp" +#include "Runtime/rstl.hpp" #include @@ -137,13 +138,13 @@ public: void LockBannerToken(CAssetId bannerTxtr, CSimplePool& sp); void LockIconToken(CAssetId iconTxtr, kabufuda::EAnimationSpeed speed, CSimplePool& sp); - kabufuda::ECardSlot GetCardPort() const { return m_handle.slot; } - int GetFileNo() const { return m_handle.getFileNo(); } - u32 CalculateBannerDataSize() const; - u32 CalculateTotalDataSize() const; + [[nodiscard]] kabufuda::ECardSlot GetCardPort() const { return m_handle.slot; } + [[nodiscard]] int GetFileNo() const { return m_handle.getFileNo(); } + [[nodiscard]] u32 CalculateBannerDataSize() const; + [[nodiscard]] u32 CalculateTotalDataSize() const; void BuildCardBuffer(); - void WriteBannerData(CMemoryOutStream& out) const; - void WriteIconData(CMemoryOutStream& out) const; + void WriteBannerData(COutputStream& out) const; + void WriteIconData(COutputStream& out) const; void SetComment(const std::string& c) { x28_comment = c; } ECardResult PumpCardTransfer(); ECardResult GetStatus(CardStat& stat) const; @@ -151,9 +152,9 @@ public: ECardResult WriteFile(); ECardResult CloseFile(); - CMemoryOutStream BeginMemoryOut(u32 sz) { + CMemoryStreamOut BeginMemoryOut(u32 sz) { xf4_saveBuffer.resize(sz); - return CMemoryOutStream(xf4_saveBuffer.data(), sz); + return CMemoryStreamOut(xf4_saveBuffer.data(), sz, CMemoryStreamOut::EOwnerShip::NotOwned, sz); } }; diff --git a/Runtime/CMemoryInStream.hpp b/Runtime/CMemoryInStream.hpp new file mode 100644 index 000000000..3bb0e7ef1 --- /dev/null +++ b/Runtime/CMemoryInStream.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "../../metaforce/Runtime/CInputStream.hpp" + +namespace metaforce { +class CMemoryInStream final : public CInputStream { +public: + enum class EOwnerShip { + NotOwned, + Owned, + }; + +public: + CMemoryInStream(const void* ptr, u32 len) : CInputStream(ptr, len, false) {} + CMemoryInStream(const void* ptr, u32 len, EOwnerShip ownership) + : CInputStream(ptr, len, ownership == EOwnerShip::Owned) {} + u32 Read(void* dest, u32 len) override { return 0; } +}; + +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/CMemoryStreamOut.cpp b/Runtime/CMemoryStreamOut.cpp new file mode 100644 index 000000000..e20580dfc --- /dev/null +++ b/Runtime/CMemoryStreamOut.cpp @@ -0,0 +1,22 @@ +#include "CMemoryStreamOut.hpp" +#include + +namespace metaforce { +CMemoryStreamOut::~CMemoryStreamOut() { + Flush(); + + if (x88_owned) { + delete[] x7c_ptr; + } +} +void CMemoryStreamOut::Write(const u8* ptr, u32 len) { + const auto offset = (x80_len - x84_position); + if (offset < len) { + len = offset; + } + + if (len != 0) { + memcpy(x7c_ptr + x84_position, ptr, len); + } +} +} \ No newline at end of file diff --git a/Runtime/CMemoryStreamOut.hpp b/Runtime/CMemoryStreamOut.hpp new file mode 100644 index 000000000..88ef2d20a --- /dev/null +++ b/Runtime/CMemoryStreamOut.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "Runtime/COutputStream.hpp" + +namespace metaforce { +class CMemoryStreamOut final : public COutputStream { +public: + enum class EOwnerShip { + NotOwned, + Owned, + }; +private: + u8* x7c_ptr = nullptr; + u32 x80_len = 0; + u32 x84_position = 0; + bool x88_owned; + +public: + CMemoryStreamOut(u8* workBuf, u32 len, EOwnerShip ownership = EOwnerShip::NotOwned, s32 unk = 4096) + : COutputStream(workBuf, unk), x7c_ptr(workBuf), x80_len(len), x88_owned(ownership == EOwnerShip::Owned) {} + + ~CMemoryStreamOut() override; + + void Write(const u8* ptr, u32 len) override; +}; +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/COutputStream.cpp b/Runtime/COutputStream.cpp new file mode 100644 index 000000000..d1fe0798e --- /dev/null +++ b/Runtime/COutputStream.cpp @@ -0,0 +1,209 @@ +#include "COutputStream.hpp" + +#include "Runtime/CBasics.hpp" + +#include + +namespace metaforce { +static u32 min_containing_bytes(u32 v) { + v = 32 - v; + v = (v >> 3) - ((s32) - (v & 7) >> 31); + return v; +} + +COutputStream::COutputStream(u8* ptr, s32 len) : x8_bufLen(len) { + xc_ptr = len <= 64 ? reinterpret_cast(((reinterpret_cast(x1c_scratch) + 7) & ~7) + 6) : new u8[len]; +} + +COutputStream::~COutputStream() { + if (x8_bufLen < 64) { + delete[] xc_ptr; + } +} + +void COutputStream::DoFlush() { + if (x4_position != 0) { + Write(xc_ptr, x4_position); + x4_position = 0; + } +} + +void COutputStream::DoPut(const u8* ptr, u32 len) { + if (len == 0) { + return; + } + + x10_numWrites += len; + u32 offset = x4_position; + u32 curLen = len; + if (x8_bufLen < len + offset) { + while (curLen != 0) { + offset = x4_position; + u32 count = x8_bufLen - offset; + if (curLen < count) { + count = curLen; + } + if (count == 0) { + DoFlush(); + } else { + memcpy(xc_ptr + offset, ptr + (len - curLen), count); + curLen -= count; + } + } + } else { + memcpy(xc_ptr + offset, ptr, len); + x4_position += len; + } +} + +void COutputStream::FlushShiftRegister() { + if (x18_shiftRegisterOffset < 32) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + x14_shiftRegister = CBasics::SwapBytes(x14_shiftRegister); +#endif + DoPut(reinterpret_cast(&x14_shiftRegister), min_containing_bytes(x18_shiftRegisterOffset)); + x14_shiftRegister = 0; + x18_shiftRegisterOffset = 32; + } +} + +void COutputStream::Flush() { + FlushShiftRegister(); + DoFlush(); +} + +void COutputStream::Put(const u8* ptr, u32 len) { + FlushShiftRegister(); + DoPut(ptr, len); +} + +void COutputStream::WriteBits(u32 val, u32 bitCount) { + const u32 bitOffset = x18_shiftRegisterOffset; + if (x18_shiftRegisterOffset < bitCount) { + /* OR remaining bits to cached value */ + const u32 shiftAmt = (bitCount - x18_shiftRegisterOffset); + const u32 mask = bitOffset == 32 ? -1 : (1 << bitOffset) - 1; + + /* Write out 32-bits */ + x14_shiftRegister |= (val >> shiftAmt) & mask; + x18_shiftRegisterOffset = 0; + FlushShiftRegister(); + + /* Cache remaining bits */ + x14_shiftRegister = (val & (shiftAmt == 32 ? -1 : (1 << shiftAmt) - 1)) << (32 - shiftAmt); + x18_shiftRegisterOffset -= shiftAmt; + } else { + /* OR bits to cached value */ + const u32 mask = bitOffset == 0x20 ? -1 : (1 << bitOffset) - 1; + x14_shiftRegister |= (val & mask) << (bitOffset - bitCount); + /* New bit offset */ + x18_shiftRegisterOffset -= bitCount; + } +} + +void COutputStream::WriteChar(u8 c) { + FlushShiftRegister(); + if (x8_bufLen <= x4_position) { + DoFlush(); + } + ++x10_numWrites; + *reinterpret_cast(xc_ptr + x4_position) = c; + ++x4_position; +} +void COutputStream::WriteShort(u16 s) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + s = CBasics::SwapBytes(s); +#endif + Put(reinterpret_cast(&s), sizeof(s)); +} +void COutputStream::WriteLong(u32 l) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + l = CBasics::SwapBytes(l); +#endif + Put(reinterpret_cast(&l), sizeof(l)); +} +void COutputStream::WriteLongLong(u64 ll) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + ll = CBasics::SwapBytes(ll); +#endif + Put(reinterpret_cast(&ll), sizeof(ll)); +} +void COutputStream::WriteFloat(float f) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + f = CBasics::SwapBytes(f); +#endif + Put(reinterpret_cast(&f), sizeof(f)); +} + +void COutputStream::WriteDouble(double d) { +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ + d = CBasics::SwapBytes(d); +#endif + Put(reinterpret_cast(&d), sizeof(d)); +} + +/* Default Stream Helpers */ +template <> +void coutput_stream_helper(const bool& t, COutputStream& out) { + out.WriteChar(static_cast(t)); +} +template <> +void coutput_stream_helper(const char& t, COutputStream& out) { + out.WriteChar(static_cast(t)); +} +template <> +void coutput_stream_helper(const s8& t, COutputStream& out) { + out.WriteChar(t); +} +template <> +void coutput_stream_helper(const u8& t, COutputStream& out) { + out.WriteChar(t); +} +template <> +void coutput_stream_helper(const s16& t, COutputStream& out) { + out.WriteShort(t); +} +template <> +void coutput_stream_helper(const u16& t, COutputStream& out) { + out.WriteShort(t); +} +template <> +void coutput_stream_helper(const s32& t, COutputStream& out) { + out.WriteLong(t); +} +template <> +void coutput_stream_helper(const u32& t, COutputStream& out) { + out.WriteLong(t); +} +template <> +void coutput_stream_helper(const s64& t, COutputStream& out) { + out.WriteLongLong(t); +} +template <> +void coutput_stream_helper(const u64& t, COutputStream& out) { + out.WriteLongLong(t); +} +template <> +void coutput_stream_helper(const float& t, COutputStream& out) { + out.WriteFloat(t); +} +template <> +void coutput_stream_helper(const double& t, COutputStream& out) { + out.WriteDouble(t); +} +template <> +void coutput_stream_helper(const std::string& t, COutputStream& out) { + for (size_t i = 0; i < t.size() + 1; ++i) { + out.FlushShiftRegister(); + out.Put(t[i]); + } +} + +u32 COutputStream::GetBitCount(u32 val) { + int bits = 0; + for (; val != 0; val >>= 1) { + bits += 1; + } + return bits; +} +} // namespace metaforce diff --git a/Runtime/COutputStream.hpp b/Runtime/COutputStream.hpp new file mode 100644 index 000000000..47dbb9026 --- /dev/null +++ b/Runtime/COutputStream.hpp @@ -0,0 +1,88 @@ +#pragma once +#include "Runtime/GCNTypes.hpp" + +#include +#include + +namespace metaforce { +class COutputStream { + friend class coutput_stream_helper; + u32 x4_position = 0; + u32 x8_bufLen = 0; + u8* xc_ptr = nullptr; + u32 x10_numWrites = 0; + u32 x14_shiftRegister = 0; + u32 x18_shiftRegisterOffset = 32; + u8 x1c_scratch[96]{}; + +protected: + + void DoFlush(); + void DoPut(const u8* ptr, u32 len); +public: + COutputStream(u8* ptr, s32 unk); + virtual ~COutputStream(); + virtual void Write(const u8* ptr, u32 len) = 0; + + void WriteBits(u32 val, u32 bitCount); + void WriteChar(u8 c); + void WriteShort(u16 s); + void WriteLong(u32 l); + void WriteLongLong(u64 ll); + void WriteFloat(float f); + void WriteDouble(double d); + + void WriteInt8(s8 c) { Put(c); } + void WriteUint8(u8 c) { Put(c); } + void WriteInt16(s16 s) { Put(s); } + void WriteUint16(u16 s) { Put(s); } + void WriteInt32(s32 l) { Put(l); } + void WriteUint32(u32 l) { Put(l); } + void WriteInt64(u64 ll) { Put(ll); } + void WriteUint64(u64 ll) { Put(ll); } + void WriteReal32(float f) { Put(f); } + void WriteReal64(double d) { Put(d); } + + void FlushShiftRegister(); + void Flush(); + void Put(const u8* ptr, u32 len); + template + void Put(const T& t) { + coutput_stream_helper(t, *this); + } + + static u32 GetBitCount(u32 val); +}; + +template +void coutput_stream_helper(const T& t, COutputStream& out) { + t.PutTo(out); +} + +template <> +void coutput_stream_helper(const bool& t, COutputStream& out); +template <> +void coutput_stream_helper(const char& t, COutputStream& out); +template <> +void coutput_stream_helper(const s8& t, COutputStream& out); +template <> +void coutput_stream_helper(const u8& t, COutputStream& out); +template <> +void coutput_stream_helper(const s16& t, COutputStream& out); +template <> +void coutput_stream_helper(const u16& t, COutputStream& out); +template <> +void coutput_stream_helper(const s32& t, COutputStream& out); +template <> +void coutput_stream_helper(const u32& t, COutputStream& out); +template <> +void coutput_stream_helper(const s64& t, COutputStream& out); +template <> +void coutput_stream_helper(const u64& t, COutputStream& out); +template <> +void coutput_stream_helper(const float& t, COutputStream& out); +template <> +void coutput_stream_helper(const double& t, COutputStream& out); +template <> +void coutput_stream_helper(const std::string& t, COutputStream& out); +} diff --git a/Runtime/CPakFile.cpp b/Runtime/CPakFile.cpp index 3555ceffa..068d804df 100644 --- a/Runtime/CPakFile.cpp +++ b/Runtime/CPakFile.cpp @@ -26,19 +26,19 @@ const SObjectTag* CPakFile::GetResIdByName(std::string_view name) const { return nullptr; } -void CPakFile::LoadResourceTable(athena::io::MemoryReader& r) { +void CPakFile::LoadResourceTable(CInputStream& r) { x74_resList.reserve( std::max(size_t(64), size_t(ROUND_UP_32(x4c_resTableCount * sizeof(SResInfo)) + sizeof(SResInfo) - 1)) / sizeof(SResInfo)); if (x28_24_buildDepList) x64_depList.reserve(x4c_resTableCount); for (u32 i = 0; i < x4c_resTableCount; ++i) { - u32 flags = r.readUint32Big(); + u32 flags = r.ReadLong(); FourCC fcc; - r.readBytesToBuf(&fcc, 4); - CAssetId id = r.readUint32Big(); - u32 size = r.readUint32Big(); - u32 offset = r.readUint32Big(); + r.ReadBytes(reinterpret_cast(&fcc), 4); + CAssetId id = r.ReadLong(); + u32 size = r.ReadLong(); + u32 offset = r.ReadLong(); if (fcc == FOURCC('MLVL')) m_mlvlId = id; x74_resList.emplace_back(id, fcc, offset, size, flags); @@ -50,7 +50,8 @@ void CPakFile::LoadResourceTable(athena::io::MemoryReader& r) { void CPakFile::DataLoad() { x30_dvdReq.reset(); - athena::io::MemoryReader r(x38_headerData.data() + x48_resTableOffset, x38_headerData.size() - x48_resTableOffset); + CMemoryInStream r(x38_headerData.data() + x48_resTableOffset, x38_headerData.size() - x48_resTableOffset, + CMemoryInStream::EOwnerShip::NotOwned); LoadResourceTable(r); x2c_asyncLoadPhase = EAsyncPhase::Loaded; if (x28_26_worldPak) { @@ -60,9 +61,9 @@ void CPakFile::DataLoad() { } void CPakFile::InitialHeaderLoad() { - athena::io::MemoryReader r(x38_headerData.data(), x38_headerData.size()); + CMemoryInStream r(x38_headerData.data(), x38_headerData.size(), CMemoryInStream::EOwnerShip::NotOwned); x30_dvdReq.reset(); - u32 version = r.readUint32Big(); + u32 version = r.ReadLong(); if (version != 0x00030005) { Log.report(logvisor::Fatal, FMT_STRING("{}: Incompatible pak file version -- Current version is {:08X}, you're using {:08X}"), @@ -70,18 +71,17 @@ void CPakFile::InitialHeaderLoad() { return; } - r.readUint32Big(); - u32 nameCount = r.readUint32Big(); + r.ReadLong(); + u32 nameCount = r.ReadLong(); x54_nameList.reserve(nameCount); for (u32 i = 0; i < nameCount; ++i) { SObjectTag tag(r); - u32 nameLen = r.readUint32Big(); - auto name = r.readString(nameLen); + auto name = CStringExtras::ReadString(r); x54_nameList.emplace_back(name, tag); } - x4c_resTableCount = r.readUint32Big(); - x48_resTableOffset = u32(r.position()); + x4c_resTableCount = r.ReadLong(); + x48_resTableOffset = u32(r.GetReadPosition()); x2c_asyncLoadPhase = EAsyncPhase::DataLoad; u32 newSize = ROUND_UP_32(x4c_resTableCount * 20 + x48_resTableOffset); u32 origSize = u32(x38_headerData.size()); diff --git a/Runtime/CPakFile.hpp b/Runtime/CPakFile.hpp index a0804e076..01119b1d7 100644 --- a/Runtime/CPakFile.hpp +++ b/Runtime/CPakFile.hpp @@ -57,7 +57,7 @@ private: std::vector x74_resList; mutable s32 x84_currentSeek = -1; CAssetId m_mlvlId; - void LoadResourceTable(athena::io::MemoryReader& r); + void LoadResourceTable(CInputStream& r); void DataLoad(); void InitialHeaderLoad(); void Warmup(); diff --git a/Runtime/CPlayerState.cpp b/Runtime/CPlayerState.cpp index 2f263e1d6..667e470e6 100644 --- a/Runtime/CPlayerState.cpp +++ b/Runtime/CPlayerState.cpp @@ -76,63 +76,63 @@ constexpr std::array ComboAmmoPeriods{ CPlayerState::CPlayerState() { x24_powerups.resize(41); } -CPlayerState::CPlayerState(CBitStreamReader& stream) { - x4_enabledItems = u32(stream.ReadEncoded(32)); +CPlayerState::CPlayerState(CInputStream& stream) { + x4_enabledItems = u32(stream.ReadBits(32)); - const u32 integralHP = u32(stream.ReadEncoded(32)); + const u32 integralHP = u32(stream.ReadBits(32)); float realHP; std::memcpy(&realHP, &integralHP, sizeof(float)); xc_health.SetHP(realHP); - x8_currentBeam = EBeamId(stream.ReadEncoded(CBitStreamReader::GetBitCount(5))); - x20_currentSuit = EPlayerSuit(stream.ReadEncoded(CBitStreamReader::GetBitCount(4))); + x8_currentBeam = EBeamId(stream.ReadBits(CInputStream::GetBitCount(5))); + x20_currentSuit = EPlayerSuit(stream.ReadBits(CInputStream::GetBitCount(4))); x24_powerups.resize(41); for (size_t i = 0; i < x24_powerups.size(); ++i) { if (PowerUpMaxValues[i] == 0) { continue; } - const u32 a = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i]))); - const u32 b = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(PowerUpMaxValues[i]))); + const u32 a = u32(stream.ReadBits(CInputStream::GetBitCount(PowerUpMaxValues[i]))); + const u32 b = u32(stream.ReadBits(CInputStream::GetBitCount(PowerUpMaxValues[i]))); x24_powerups[i] = CPowerUp(a, b); } const auto& scanStates = g_MemoryCardSys->GetScanStates(); x170_scanTimes.reserve(scanStates.size()); for (const auto& state : scanStates) { - float time = stream.ReadEncoded(1) ? 1.f : 0.f; + float time = stream.ReadBits(1) ? 1.f : 0.f; x170_scanTimes.emplace_back(state.first, time); } - x180_scanCompletionRate.first = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(0x100u))); - x180_scanCompletionRate.second = u32(stream.ReadEncoded(CBitStreamReader::GetBitCount(0x100u))); + x180_scanCompletionRate.first = u32(stream.ReadBits(CInputStream::GetBitCount(0x100u))); + x180_scanCompletionRate.second = u32(stream.ReadBits(CInputStream::GetBitCount(0x100u))); } -void CPlayerState::PutTo(CBitStreamWriter& stream) { - stream.WriteEncoded(x4_enabledItems, 32); +void CPlayerState::PutTo(COutputStream& stream) { + stream.WriteBits(x4_enabledItems, 32); const float realHP = xc_health.GetHP(); u32 integralHP; std::memcpy(&integralHP, &realHP, sizeof(u32)); - stream.WriteEncoded(integralHP, 32); - stream.WriteEncoded(u32(x8_currentBeam), CBitStreamWriter::GetBitCount(5)); - stream.WriteEncoded(u32(x20_currentSuit), CBitStreamWriter::GetBitCount(4)); + stream.WriteBits(integralHP, 32); + stream.WriteBits(u32(x8_currentBeam), COutputStream::GetBitCount(5)); + stream.WriteBits(u32(x20_currentSuit), COutputStream::GetBitCount(4)); for (size_t i = 0; i < x24_powerups.size(); ++i) { const CPowerUp& pup = x24_powerups[i]; - stream.WriteEncoded(pup.x0_amount, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i])); - stream.WriteEncoded(pup.x4_capacity, CBitStreamWriter::GetBitCount(PowerUpMaxValues[i])); + stream.WriteBits(pup.x0_amount, COutputStream::GetBitCount(PowerUpMaxValues[i])); + stream.WriteBits(pup.x4_capacity, COutputStream::GetBitCount(PowerUpMaxValues[i])); } for (const auto& scanTime : x170_scanTimes) { if (scanTime.second >= 1.f) - stream.WriteEncoded(true, 1); + stream.WriteBits(true, 1); else - stream.WriteEncoded(false, 1); + stream.WriteBits(false, 1); } - stream.WriteEncoded(x180_scanCompletionRate.first, CBitStreamWriter::GetBitCount(0x100)); - stream.WriteEncoded(x180_scanCompletionRate.second, CBitStreamWriter::GetBitCount(0x100)); + stream.WriteBits(x180_scanCompletionRate.first, COutputStream::GetBitCount(0x100)); + stream.WriteBits(x180_scanCompletionRate.second, COutputStream::GetBitCount(0x100)); } u32 CPlayerState::GetMissileCostForAltAttack() const { return costs[size_t(x8_currentBeam)]; } diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index 72ae5b136..db9ce26b1 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -164,8 +164,8 @@ public: CStaticInterference& GetStaticInterference() { return x188_staticIntf; } const std::vector>& GetScanTimes() const { return x170_scanTimes; } CPlayerState(); - explicit CPlayerState(CBitStreamReader& stream); - void PutTo(CBitStreamWriter& stream); + explicit CPlayerState(CInputStream& stream); + void PutTo(COutputStream& stream); static u32 GetPowerUpMaxValue(EItemType type); static EItemType ItemNameToType(std::string_view name); static std::string_view ItemTypeToName(EItemType type); diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp index 3a30bee4a..99a1b1d9d 100644 --- a/Runtime/CResLoader.cpp +++ b/Runtime/CResLoader.cpp @@ -44,7 +44,8 @@ std::unique_ptr CResLoader::LoadNewResourcePartSync(const SObjectT CPakFile* const file = FindResourceForLoad(tag); file->SyncSeekRead(buf, length, ESeekOrigin::Begin, x50_cachedResInfo->GetOffset() + offset); - return std::make_unique(buf, length, !extBuf); + return std::make_unique( + buf, length, extBuf == nullptr ? CMemoryInStream::EOwnerShip::Owned : CMemoryInStream::EOwnerShip::NotOwned); } void CResLoader::LoadMemResourceSync(const SObjectTag& tag, std::unique_ptr& bufOut, int* sizeOut) { @@ -57,9 +58,10 @@ void CResLoader::LoadMemResourceSync(const SObjectTag& tag, std::unique_ptr CResLoader::LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf) { FindResourceForLoad(tag); - std::unique_ptr newStrm = std::make_unique(buf, x50_cachedResInfo->GetSize()); + std::unique_ptr newStrm = + std::make_unique(buf, x50_cachedResInfo->GetSize(), CMemoryInStream::EOwnerShip::NotOwned); if (x50_cachedResInfo->IsCompressed()) { - newStrm->readUint32Big(); + newStrm->ReadLong(); newStrm = std::make_unique(std::move(newStrm)); } return newStrm; @@ -77,9 +79,10 @@ std::unique_ptr CResLoader::LoadNewResourceSync(const SObjectTag& file->SyncSeekRead(buf, resSz, ESeekOrigin::Begin, x50_cachedResInfo->GetOffset()); const bool takeOwnership = extBuf == nullptr; - std::unique_ptr newStrm = std::make_unique(buf, resSz, takeOwnership); + std::unique_ptr newStrm = std::make_unique( + buf, resSz, takeOwnership ? CMemoryInStream::EOwnerShip::Owned : CMemoryInStream::EOwnerShip::NotOwned); if (x50_cachedResInfo->IsCompressed()) { - newStrm->readUint32Big(); + newStrm->ReadLong(); newStrm = std::make_unique(std::move(newStrm)); } diff --git a/Runtime/CScannableObjectInfo.cpp b/Runtime/CScannableObjectInfo.cpp index d950522fc..838fe5a48 100644 --- a/Runtime/CScannableObjectInfo.cpp +++ b/Runtime/CScannableObjectInfo.cpp @@ -4,7 +4,7 @@ namespace metaforce { CScannableObjectInfo::CScannableObjectInfo(CInputStream& in, CAssetId resId) : x0_scannableObjectId(resId) { - const u32 version = in.readUint32Big(); + const u32 version = in.ReadLong(); Load(in, version); for (auto& bucket : x14_buckets) { @@ -33,18 +33,18 @@ CScannableObjectInfo::CScannableObjectInfo(CInputStream& in, CAssetId resId) : x } void CScannableObjectInfo::Load(CInputStream& in, u32 version) { - in.readUint32Big(); - in.readUint32Big(); - x4_stringId = in.readUint32Big(); + in.ReadLong(); + in.ReadLong(); + x4_stringId = in.ReadLong(); if (version < 4) { - x8_totalDownloadTime = in.readFloatBig(); + x8_totalDownloadTime = in.ReadFloat(); } else { - const u32 scanSpeed = in.readUint32Big(); + const u32 scanSpeed = in.ReadLong(); x8_totalDownloadTime = g_tweakGui->GetScanSpeed(scanSpeed); } - xc_category = in.readUint32Big(); + xc_category = in.ReadLong(); if (version > 4) { - x10_important = in.readBool(); + x10_important = in.ReadBool(); } for (size_t i = 0; i < x14_buckets.capacity(); i++) { @@ -53,15 +53,15 @@ void CScannableObjectInfo::Load(CInputStream& in, u32 version) { } CScannableObjectInfo::SBucket::SBucket(CInputStream& in, u32 version) { - x0_texture = in.readUint32Big(); - x4_appearanceRange = in.readFloatBig(); - x8_imagePos = in.readUint32Big(); + x0_texture = in.ReadLong(); + x4_appearanceRange = in.ReadFloat(); + x8_imagePos = in.ReadLong(); if (version > 1) { - xc_size.x = in.readUint32Big(); - xc_size.y = in.readUint32Big(); - x14_interval = in.readFloatBig(); + xc_size.x = in.ReadLong(); + xc_size.y = in.ReadLong(); + x14_interval = in.ReadFloat(); if (version >= 3) - x18_fadeDuration = in.readFloatBig(); + x18_fadeDuration = in.ReadFloat(); } } diff --git a/Runtime/CScriptMailbox.cpp b/Runtime/CScriptMailbox.cpp index 2f6b10dde..a6b64edb8 100644 --- a/Runtime/CScriptMailbox.cpp +++ b/Runtime/CScriptMailbox.cpp @@ -8,12 +8,12 @@ namespace metaforce { -CScriptMailbox::CScriptMailbox(CBitStreamReader& in, const CWorldSaveGameInfo& saveWorld) { +CScriptMailbox::CScriptMailbox(CInputStream& in, const CWorldSaveGameInfo& saveWorld) { const u32 relayCount = saveWorld.GetRelayCount(); if (saveWorld.GetRelayCount()) { std::vector relayStates(saveWorld.GetRelayCount()); for (u32 i = 0; i < relayCount; ++i) { - relayStates[i] = in.ReadEncoded(1); + relayStates[i] = in.ReadBits(1); } for (u32 i = 0; i < relayCount; ++i) { @@ -79,7 +79,7 @@ void CScriptMailbox::SendMsgs(TAreaId areaId, CStateManager& stateMgr) { } } -void CScriptMailbox::PutTo(CBitStreamWriter& out, const CWorldSaveGameInfo& saveWorld) { +void CScriptMailbox::PutTo(COutputStream& out, const CWorldSaveGameInfo& saveWorld) { const u32 relayCount = saveWorld.GetRelayCount(); std::vector relays(relayCount); @@ -91,7 +91,7 @@ void CScriptMailbox::PutTo(CBitStreamWriter& out, const CWorldSaveGameInfo& save } for (u32 i = 0; i < relayCount; ++i) { - out.WriteEncoded(u32(relays[i]), 1); + out.WriteBits(u32(relays[i]), 1); } } diff --git a/Runtime/CScriptMailbox.hpp b/Runtime/CScriptMailbox.hpp index a8fac0dbc..db02b3078 100644 --- a/Runtime/CScriptMailbox.hpp +++ b/Runtime/CScriptMailbox.hpp @@ -29,13 +29,13 @@ class CScriptMailbox { public: CScriptMailbox() = default; - CScriptMailbox(CBitStreamReader& in, const CWorldSaveGameInfo& saveWorld); + CScriptMailbox(CInputStream& in, const CWorldSaveGameInfo& saveWorld); bool HasMsg(TEditorId id) const; void AddMsg(TEditorId id); void RemoveMsg(TEditorId id); void SendMsgs(TAreaId areaId, CStateManager& stateMgr); - void PutTo(CBitStreamWriter& out, const CWorldSaveGameInfo& saveWorld); + void PutTo(COutputStream& out, const CWorldSaveGameInfo& saveWorld); }; } // namespace metaforce diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 56ab6ec29..670b8d3be 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -439,7 +439,7 @@ void CStateManager::SetupParticleHook(const CActor& actor) const { void CStateManager::MurderScriptInstanceNames() { xb40_uniqueInstanceNames.clear(); } -std::string CStateManager::HashInstanceName(CInputStream& in) { return in.readString(); } +std::string CStateManager::HashInstanceName(CInputStream& in) { return in.Get(); } void CStateManager::SetActorAreaId(CActor& actor, TAreaId aid) { const TAreaId actorAid = actor.GetAreaIdAlways(); @@ -985,90 +985,90 @@ void CStateManager::DrawWorld() { } void CStateManager::DrawActorCubeFaces(CActor& actor, int& cubeInst) const { -// if (!actor.m_reflectionCube || -// (!TCastToPtr(actor) && (!actor.GetActive() || !actor.IsDrawEnabled() || actor.xe4_30_outOfFrustum))) -// return; -// -// const TAreaId visAreaId = actor.GetAreaIdAlways(); -// const SViewport backupVp = g_Viewport; -// -// int areaCount = 0; -// std::array areaArr; -// for (const CGameArea& area : *x850_world) { -// if (areaCount == 10) { -// break; -// } -// auto occState = CGameArea::EOcclusionState::Occluded; -// if (area.IsPostConstructed()) { -// occState = area.GetOcclusionState(); -// } -// if (occState == CGameArea::EOcclusionState::Visible) { -// areaArr[areaCount++] = &area; -// } -// } -// -// for (int f = 0; f < 6; ++f) { -// SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CStateManager::DrawActorCubeFaces [{}] {} {} {}"), f, -// actor.GetUniqueId(), actor.GetEditorId(), actor.GetName()) -// .c_str(), -// zeus::skOrange); -// CGraphics::g_BooMainCommandQueue->setRenderTarget(actor.m_reflectionCube, f); -// SetupViewForCubeFaceDraw(actor.GetRenderBounds().center(), f); -// CGraphics::g_BooMainCommandQueue->clearTarget(); -// -// std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) { -// if (a->x4_selfIdx == b->x4_selfIdx) { -// return false; -// } -// if (visAreaId == a->x4_selfIdx) { -// return false; -// } -// if (visAreaId == b->x4_selfIdx) { -// return true; -// } -// return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); -// }); -// -// int pvsCount = 0; -// std::array pvsArr; -// for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) { -// const CGameArea* areaPtr = *area; -// CPVSVisSet& pvsSet = pvsArr[pvsCount++]; -// pvsSet.Reset(EPVSVisSetState::OutOfBounds); -// GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet); -// } -// -// for (int i = areaCount - 1; i >= 0; --i) { -// const CGameArea& area = *areaArr[i]; -// SetupFogForArea(area); -// g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx); -// g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); -// g_Renderer->UpdateAreaUniforms(area.x4_selfIdx, EWorldShadowMode::None, true, cubeInst * 6 + f); -// g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, 0x2, 0x0); -// } -// -// if (!SetupFogForDraw()) { -// g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); -// } -// -// x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); -// -// for (int i = 0; i < areaCount; ++i) { -// const CGameArea& area = *areaArr[i]; -// CPVSVisSet& pvs = pvsArr[i]; -// SetupFogForArea(area); -// g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); -// g_Renderer->EnablePVS(pvs, area.x4_selfIdx); -// g_Renderer->DrawSortedGeometry(area.x4_selfIdx, 0x2, 0x0); -// } -// } -// -// CGraphics::g_BooMainCommandQueue->generateMipmaps(actor.m_reflectionCube); -// -// CBooRenderer::BindMainDrawTarget(); -// g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); -// -// ++cubeInst; + // if (!actor.m_reflectionCube || + // (!TCastToPtr(actor) && (!actor.GetActive() || !actor.IsDrawEnabled() || actor.xe4_30_outOfFrustum))) + // return; + // + // const TAreaId visAreaId = actor.GetAreaIdAlways(); + // const SViewport backupVp = g_Viewport; + // + // int areaCount = 0; + // std::array areaArr; + // for (const CGameArea& area : *x850_world) { + // if (areaCount == 10) { + // break; + // } + // auto occState = CGameArea::EOcclusionState::Occluded; + // if (area.IsPostConstructed()) { + // occState = area.GetOcclusionState(); + // } + // if (occState == CGameArea::EOcclusionState::Visible) { + // areaArr[areaCount++] = &area; + // } + // } + // + // for (int f = 0; f < 6; ++f) { + // SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CStateManager::DrawActorCubeFaces [{}] {} {} {}"), f, + // actor.GetUniqueId(), actor.GetEditorId(), actor.GetName()) + // .c_str(), + // zeus::skOrange); + // CGraphics::g_BooMainCommandQueue->setRenderTarget(actor.m_reflectionCube, f); + // SetupViewForCubeFaceDraw(actor.GetRenderBounds().center(), f); + // CGraphics::g_BooMainCommandQueue->clearTarget(); + // + // std::sort(areaArr.begin(), areaArr.begin() + areaCount, [visAreaId](const CGameArea* a, const CGameArea* b) { + // if (a->x4_selfIdx == b->x4_selfIdx) { + // return false; + // } + // if (visAreaId == a->x4_selfIdx) { + // return false; + // } + // if (visAreaId == b->x4_selfIdx) { + // return true; + // } + // return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); + // }); + // + // int pvsCount = 0; + // std::array pvsArr; + // for (auto area = areaArr.cbegin(); area != areaArr.cbegin() + areaCount; ++area) { + // const CGameArea* areaPtr = *area; + // CPVSVisSet& pvsSet = pvsArr[pvsCount++]; + // pvsSet.Reset(EPVSVisSetState::OutOfBounds); + // GetVisSetForArea(areaPtr->x4_selfIdx, visAreaId, pvsSet); + // } + // + // for (int i = areaCount - 1; i >= 0; --i) { + // const CGameArea& area = *areaArr[i]; + // SetupFogForArea(area); + // g_Renderer->EnablePVS(pvsArr[i], area.x4_selfIdx); + // g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); + // g_Renderer->UpdateAreaUniforms(area.x4_selfIdx, EWorldShadowMode::None, true, cubeInst * 6 + f); + // g_Renderer->DrawUnsortedGeometry(area.x4_selfIdx, 0x2, 0x0); + // } + // + // if (!SetupFogForDraw()) { + // g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); + // } + // + // x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); + // + // for (int i = 0; i < areaCount; ++i) { + // const CGameArea& area = *areaArr[i]; + // CPVSVisSet& pvs = pvsArr[i]; + // SetupFogForArea(area); + // g_Renderer->SetWorldLightFadeLevel(area.GetPostConstructed()->x1128_worldLightingLevel); + // g_Renderer->EnablePVS(pvs, area.x4_selfIdx); + // g_Renderer->DrawSortedGeometry(area.x4_selfIdx, 0x2, 0x0); + // } + // } + // + // CGraphics::g_BooMainCommandQueue->generateMipmaps(actor.m_reflectionCube); + // + // CBooRenderer::BindMainDrawTarget(); + // g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); + // + // ++cubeInst; } void CStateManager::DrawWorldCubeFaces() const { @@ -1470,14 +1470,14 @@ CStateManager::GetIdListForScript(TEditorId id) const { } void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector& idsOut) { - in.readUByte(); + in.ReadUint8(); - const u32 objCount = in.readUint32Big(); + const u32 objCount = in.ReadLong(); idsOut.reserve(idsOut.size() + objCount); for (u32 i = 0; i < objCount; ++i) { - const auto objType = static_cast(in.readUByte()); - const u32 objSize = in.readUint32Big(); - const u32 pos = static_cast(in.position()); + const auto objType = static_cast(in.ReadUint8()); + const u32 objSize = in.ReadLong(); + const u32 pos = static_cast(in.GetReadPosition()); const auto id = LoadScriptObject(aid, objType, objSize, in); if (id.first == kInvalidEditorId) { continue; @@ -1502,15 +1502,15 @@ void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector std::pair CStateManager::LoadScriptObject(TAreaId aid, EScriptObjectType type, u32 length, CInputStream& in) { OPTICK_EVENT(); - const TEditorId id = in.readUint32Big(); - const u32 connCount = in.readUint32Big(); + const TEditorId id = in.ReadLong(); + const u32 connCount = in.ReadLong(); length -= 8; std::vector conns; conns.reserve(connCount); for (u32 i = 0; i < connCount; ++i) { - const auto state = EScriptObjectState(in.readUint32Big()); - const auto msg = EScriptObjectMessage(in.readUint32Big()); - const TEditorId target = in.readUint32Big(); + const auto state = EScriptObjectState(in.ReadLong()); + const auto msg = EScriptObjectMessage(in.ReadLong()); + const TEditorId target = in.ReadLong(); // Metaforce Addition if (m_incomingConnections.find(target) == m_incomingConnections.cend()) { m_incomingConnections.emplace(target, std::set()); @@ -1521,9 +1521,9 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc length -= 12; conns.push_back(SConnection{state, msg, target}); } - const u32 propCount = in.readUint32Big(); + const u32 propCount = in.ReadLong(); length -= 4; - const auto startPos = in.position(); + const auto startPos = in.GetReadPosition(); bool error = false; FScriptLoader loader = {}; @@ -1545,7 +1545,7 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc error = true; } - const u32 readAmt = in.position() - startPos; + const u32 readAmt = in.GetReadPosition() - startPos; if (readAmt > length) { LogModule.report(logvisor::Fatal, FMT_STRING("Script object overread while reading {}"), ScriptObjectTypeToStr(type)); @@ -1553,13 +1553,17 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc const u32 leftover = length - readAmt; for (u32 i = 0; i < leftover; ++i) { - in.readByte(); + in.ReadChar(); } if (error || ent == nullptr) { - in.seek(startPos, athena::SeekOrigin::Begin); + while (in.GetReadPosition() != startPos) { + in.ReadChar(); + } const std::string name = HashInstanceName(in); - in.seek(startPos + length, athena::SeekOrigin::Begin); + while (in.GetReadPosition() != startPos + length) { + in.ReadChar(); + } LogModule.report(logvisor::Error, FMT_STRING("Script load error while loading {}, name: {}"), ScriptObjectTypeToStr(type), name); return {kInvalidEditorId, kInvalidUniqueId}; diff --git a/Runtime/CStringExtras.cpp b/Runtime/CStringExtras.cpp new file mode 100644 index 000000000..6d50ab1b0 --- /dev/null +++ b/Runtime/CStringExtras.cpp @@ -0,0 +1,21 @@ +#include "Runtime/CStringExtras.hpp" +#include "Runtime/CInputStream.hpp" + +namespace metaforce { +std::string CStringExtras::ReadString(CInputStream& in) { + u32 strLen = in.ReadLong(); + std::string ret; + u32 readLen = 512; + char tmp[512] = {}; + for (; strLen > 0; strLen -= readLen) { + readLen = 512; + if (strLen <= 512) { + readLen = strLen; + } + in.ReadBytes(tmp, readLen); + ret.append(tmp, readLen); + } + + return ret; +} +} \ No newline at end of file diff --git a/Runtime/CStringExtras.hpp b/Runtime/CStringExtras.hpp index 96bb9ba3a..03a295cf1 100644 --- a/Runtime/CStringExtras.hpp +++ b/Runtime/CStringExtras.hpp @@ -5,7 +5,7 @@ #include namespace metaforce { - +class CInputStream; class CStringExtras { public: // Checks if the provided views into string data can be considered equal or not based on @@ -35,6 +35,8 @@ public: } return s; } + + static std::string ReadString(CInputStream& in); }; } // namespace metaforce diff --git a/Runtime/CTextureCache.cpp b/Runtime/CTextureCache.cpp index 3311e857b..2c4bee3b3 100644 --- a/Runtime/CTextureCache.cpp +++ b/Runtime/CTextureCache.cpp @@ -3,11 +3,11 @@ namespace metaforce { CTextureCache::CTextureCache(CInputStream& in) { - u32 textureCount = in.readUint32Big(); + u32 textureCount = in.ReadLong(); for (u32 i = 0; i < textureCount; ++i) { CAssetId uid(in); if (m_textureInfo.find(uid) == m_textureInfo.end()) - m_textureInfo.emplace(uid, CTextureInfo(in)); + m_textureInfo.emplace(uid, in.Get()); } } diff --git a/Runtime/CTextureCache.hpp b/Runtime/CTextureCache.hpp index 3dc558331..258965014 100644 --- a/Runtime/CTextureCache.hpp +++ b/Runtime/CTextureCache.hpp @@ -13,7 +13,7 @@ class CPaletteInfo { public: explicit CPaletteInfo(CInputStream& in) - : m_format(in.readUint32Big()), m_elementCount(in.readUint32Big()), m_dolphinHash(in.readUint64Big()) {} + : m_format(in.ReadLong()), m_elementCount(in.ReadLong()), m_dolphinHash(in.ReadLongLong()) {} }; class CTextureInfo { ETexelFormat m_format; @@ -25,12 +25,12 @@ class CTextureInfo { public: explicit CTextureInfo(CInputStream& in) - : m_format(ETexelFormat(in.readUint32Big())) - , m_mipCount(in.readUint32Big()) - , m_width(in.readUint16Big()) - , m_height(in.readUint16Big()) - , m_dolphinHash(in.readUint64Big()) { - bool hasPal = in.readBool(); + : m_format(ETexelFormat(in.ReadLong())) + , m_mipCount(in.ReadLong()) + , m_width(in.ReadShort()) + , m_height(in.ReadShort()) + , m_dolphinHash(in.ReadLongLong()) { + bool hasPal = in.ReadBool(); if (hasPal) m_paletteInfo.emplace(in); } diff --git a/Runtime/CWorldSaveGameInfo.cpp b/Runtime/CWorldSaveGameInfo.cpp index dd0829d03..aec5b9cf9 100644 --- a/Runtime/CWorldSaveGameInfo.cpp +++ b/Runtime/CWorldSaveGameInfo.cpp @@ -4,50 +4,50 @@ namespace metaforce { CWorldSaveGameInfo::CWorldSaveGameInfo(CInputStream& in) { - in.readUint32Big(); - const u32 version = in.readUint32Big(); + in.ReadLong(); + const u32 version = in.ReadLong(); if (version > 1) { - x0_areaCount = in.readUint32Big(); + x0_areaCount = in.ReadLong(); } if (version > 2) { - const u32 cinematicCount = in.readUint32Big(); + const u32 cinematicCount = in.ReadLong(); x4_cinematics.reserve(cinematicCount); for (u32 i = 0; i < cinematicCount; ++i) { - x4_cinematics.emplace_back(in.readUint32Big()); + x4_cinematics.emplace_back(in.ReadLong()); } - const u32 relayCount = in.readUint32Big(); + const u32 relayCount = in.ReadLong(); x14_relays.reserve(relayCount); for (u32 i = 0; i < relayCount; ++i) { - x14_relays.emplace_back(in.readUint32Big()); + x14_relays.emplace_back(in.ReadLong()); } } - const u32 layerCount = in.readUint32Big(); + const u32 layerCount = in.ReadLong(); x24_layers.reserve(layerCount); for (u32 i = 0; i < layerCount; ++i) { SLayerState& st = x24_layers.emplace_back(); - st.x0_area = in.readUint32Big(); - st.x4_layer = in.readUint32Big(); + st.x0_area = in.ReadLong(); + st.x4_layer = in.ReadLong(); } - const u32 doorCount = in.readUint32Big(); + const u32 doorCount = in.ReadLong(); x34_doors.reserve(doorCount); for (u32 i = 0; i < doorCount; ++i) { - x34_doors.emplace_back(in.readUint32Big()); + x34_doors.emplace_back(in.ReadLong()); } if (version <= 0) { return; } - const u32 scanCount = in.readUint32Big(); + const u32 scanCount = in.ReadLong(); x44_scans.reserve(scanCount); for (u32 i = 0; i < scanCount; ++i) { SScanState& st = x44_scans.emplace_back(); - st.x0_id = in.readUint32Big(); - st.x4_category = EScanCategory(in.readUint32Big()); + st.x0_id = in.ReadLong(); + st.x4_category = EScanCategory(in.ReadLong()); } } diff --git a/Runtime/CZipInputStream.cpp b/Runtime/CZipInputStream.cpp new file mode 100644 index 000000000..337792f9a --- /dev/null +++ b/Runtime/CZipInputStream.cpp @@ -0,0 +1,34 @@ +#include "CZipInputStream.hpp" + +namespace metaforce { +CZipInputStream::CZipInputStream(std::unique_ptr&& strm) +: CInputStream(4096), x24_compBuf(new u8[4096]), x28_strm(std::move(strm)) { + x30_zstrm = std::make_unique(); + x30_zstrm->next_in = x24_compBuf.get(); + x30_zstrm->avail_in = 0; + x30_zstrm->zalloc = [](void*, u32 c, u32 n) -> void* { return new u8[size_t{c} * size_t{n}]; }; + x30_zstrm->zfree = [](void*, void* buf) { delete[] static_cast(buf); }; + inflateInit(x30_zstrm.get()); +} + +CZipInputStream::~CZipInputStream() { inflateEnd(x30_zstrm.get()); } + +u32 CZipInputStream::Read(void* buf, u32 len) { + x30_zstrm->next_out = static_cast(buf); + x30_zstrm->avail_out = len; + x30_zstrm->total_out = 0; + while (x30_zstrm->avail_out != 0) { + if (x30_zstrm->avail_in == 0) { + u32 readSz = x28_strm->ReadBytes(x24_compBuf.get(), 4096); + x30_zstrm->avail_in = readSz; + x30_zstrm->next_in = x24_compBuf.get(); + } + int inflateRet = inflate(x30_zstrm.get(), Z_NO_FLUSH); + if (inflateRet != Z_OK) { + break; + } + } + return x30_zstrm->total_out; +} + +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/CZipInputStream.hpp b/Runtime/CZipInputStream.hpp new file mode 100644 index 000000000..9fa7e96cf --- /dev/null +++ b/Runtime/CZipInputStream.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "CInputStream.hpp" + +#include + +#include +namespace metaforce { +class CZipInputStream : public CInputStream { + std::unique_ptr x24_compBuf; + std::unique_ptr x28_strm; + std::unique_ptr x30_zstrm = {}; + +public: + explicit CZipInputStream(std::unique_ptr&& strm); + ~CZipInputStream() override; + + u32 Read(void* ptr, u32 len) override; +}; + +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/Camera/CCameraShakeData.cpp b/Runtime/Camera/CCameraShakeData.cpp index 28a25d3ed..8d97d0dea 100644 --- a/Runtime/Camera/CCameraShakeData.cpp +++ b/Runtime/Camera/CCameraShakeData.cpp @@ -13,10 +13,10 @@ namespace metaforce { SCameraShakePoint SCameraShakePoint::LoadCameraShakePoint(CInputStream& in) { u32 useEnvelope = ScriptLoader::LoadParameterFlags(in); - float attackTime = in.readFloatBig(); - float sustainTime = in.readFloatBig(); - float duration = in.readFloatBig(); - float magnitude = in.readFloatBig(); + float attackTime = in.ReadFloat(); + float sustainTime = in.ReadFloat(); + float duration = in.ReadFloat(); + float magnitude = in.ReadFloat(); return {useEnvelope != 0, attackTime, sustainTime, duration, magnitude}; } @@ -28,15 +28,15 @@ CCameraShakerComponent CCameraShakerComponent::LoadNewCameraShakerComponent(CInp } CCameraShakeData::CCameraShakeData(CInputStream& in) { - in.readUint32Big(); - in.readFloatBig(); - in.readFloatBig(); - in.readFloatBig(); - in.readFloatBig(); - in.readFloatBig(); - in.readFloatBig(); - in.readFloatBig(); - in.readBool(); + in.ReadLong(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadBool(); BuildProjectileCameraShake(0.5f, 0.75f); } @@ -100,13 +100,13 @@ float CCameraShakeData::GetMaxFMComponent() const { } CCameraShakeData CCameraShakeData::LoadCameraShakeData(CInputStream& in) { - const float xMag = in.readFloatBig(); - in.readFloatBig(); - const float yMag = in.readFloatBig(); - in.readFloatBig(); - const float zMag = in.readFloatBig(); - in.readFloatBig(); - const float duration = in.readFloatBig(); + const float xMag = in.ReadFloat(); + in.ReadFloat(); + const float yMag = in.ReadFloat(); + in.ReadFloat(); + const float zMag = in.ReadFloat(); + in.ReadFloat(); + const float duration = in.ReadFloat(); const SCameraShakePoint xAM(false, 0.f, 0.f, duration, 2.f * xMag); const SCameraShakePoint yAM(false, 0.f, 0.f, duration, 2.f * yMag); diff --git a/Runtime/Camera/CCameraShakeData.hpp b/Runtime/Camera/CCameraShakeData.hpp index b1a4de181..e5389d487 100644 --- a/Runtime/Camera/CCameraShakeData.hpp +++ b/Runtime/Camera/CCameraShakeData.hpp @@ -60,6 +60,7 @@ class CCameraShakeData { public: static const CCameraShakeData skChargedShotCameraShakeData; + constexpr CCameraShakeData() = default; constexpr CCameraShakeData(float duration, float sfxDist, u32 flags, const zeus::CVector3f& sfxPos, const CCameraShakerComponent& shaker1, const CCameraShakerComponent& shaker2, const CCameraShakerComponent& shaker3) noexcept diff --git a/Runtime/Character/CAdditiveAnimPlayback.hpp b/Runtime/Character/CAdditiveAnimPlayback.hpp index c85ac976d..80baee67d 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.hpp +++ b/Runtime/Character/CAdditiveAnimPlayback.hpp @@ -2,6 +2,7 @@ #include #include "Runtime/RetroTypes.hpp" +#include "Runtime/CInputStream.hpp" namespace metaforce { class CAdditiveAnimationInfo; @@ -16,8 +17,8 @@ class CAdditiveAnimationInfo { public: void read(CInputStream& in) { - x0_fadeInDur = in.readFloatBig(); - x4_fadeOutDur = in.readFloatBig(); + x0_fadeInDur = in.ReadFloat(); + x4_fadeOutDur = in.ReadFloat(); } CAdditiveAnimationInfo() = default; explicit CAdditiveAnimationInfo(CInputStream& in) { read(in); } diff --git a/Runtime/Character/CAllFormatsAnimSource.cpp b/Runtime/Character/CAllFormatsAnimSource.cpp index 7e852ede9..e3c01f9cc 100644 --- a/Runtime/Character/CAllFormatsAnimSource.cpp +++ b/Runtime/Character/CAllFormatsAnimSource.cpp @@ -26,7 +26,7 @@ void CAnimFormatUnion::SubConstruct(u8* storage, EAnimFormat fmt, CInputStream& } CAnimFormatUnion::CAnimFormatUnion(CInputStream& in, IObjectStore& store) { - x0_format = EAnimFormat(in.readUint32Big()); + x0_format = EAnimFormat(in.ReadLong()); SubConstruct(x4_storage, x0_format, in, store); } diff --git a/Runtime/Character/CAnimCharacterSet.cpp b/Runtime/Character/CAnimCharacterSet.cpp index a85150f8f..bced78e93 100644 --- a/Runtime/Character/CAnimCharacterSet.cpp +++ b/Runtime/Character/CAnimCharacterSet.cpp @@ -5,7 +5,7 @@ namespace metaforce { CAnimCharacterSet::CAnimCharacterSet(CInputStream& in) -: x0_version(in.readUint16Big()), x4_characterSet(in), x1c_animationSet(in) {} +: x0_version(in.ReadShort()), x4_characterSet(in), x1c_animationSet(in) {} CFactoryFnReturn FAnimCharacterSet(const SObjectTag&, CInputStream& in, const CVParamTransfer&, CObjectReference* selfRef) { diff --git a/Runtime/Character/CAnimPOIData.cpp b/Runtime/Character/CAnimPOIData.cpp index 0f9328307..600044fba 100644 --- a/Runtime/Character/CAnimPOIData.cpp +++ b/Runtime/Character/CAnimPOIData.cpp @@ -4,24 +4,24 @@ namespace metaforce { -CAnimPOIData::CAnimPOIData(CInputStream& in) : x0_version(in.readUint32Big()) { - u32 boolCount = in.readUint32Big(); +CAnimPOIData::CAnimPOIData(CInputStream& in) : x0_version(in.ReadLong()) { + u32 boolCount = in.ReadLong(); x4_boolNodes.reserve(boolCount); for (u32 i = 0; i < boolCount; ++i) x4_boolNodes.emplace_back(in); - u32 int32Count = in.readUint32Big(); + u32 int32Count = in.ReadLong(); x14_int32Nodes.reserve(int32Count); for (u32 i = 0; i < int32Count; ++i) x14_int32Nodes.emplace_back(in); - u32 particleCount = in.readUint32Big(); + u32 particleCount = in.ReadLong(); x24_particleNodes.reserve(particleCount); for (u32 i = 0; i < particleCount; ++i) x24_particleNodes.emplace_back(in); if (x0_version >= 2) { - u32 soundCount = in.readUint32Big(); + u32 soundCount = in.ReadLong(); x34_soundNodes.reserve(soundCount); for (u32 i = 0; i < soundCount; ++i) x34_soundNodes.emplace_back(in); diff --git a/Runtime/Character/CAnimSource.cpp b/Runtime/Character/CAnimSource.cpp index 7ab35115e..fc9e18281 100644 --- a/Runtime/Character/CAnimSource.cpp +++ b/Runtime/Character/CAnimSource.cpp @@ -51,16 +51,16 @@ std::unique_ptr RotationAndOffsetStorage::GetRotationsAndOffsets(const } RotationAndOffsetStorage::CRotationAndOffsetVectors::CRotationAndOffsetVectors(CInputStream& in) { - const u32 quatCount = in.readUint32Big(); + const u32 quatCount = in.ReadLong(); x0_rotations.reserve(quatCount); for (u32 i = 0; i < quatCount; ++i) { - x0_rotations.emplace_back().readBig(in); + x0_rotations.emplace_back() = in.Get(); } - const u32 vecCount = in.readUint32Big(); + const u32 vecCount = in.ReadLong(); x10_offsets.reserve(vecCount); for (u32 i = 0; i < vecCount; ++i) { - x10_offsets.emplace_back().readBig(in); + x10_offsets.emplace_back() = in.Get(); } } @@ -75,10 +75,10 @@ RotationAndOffsetStorage::RotationAndOffsetStorage(const CRotationAndOffsetVecto static std::vector ReadIndexTable(CInputStream& in) { std::vector ret; - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); ret.reserve(count); for (u32 i = 0; i < count; ++i) - ret.push_back(in.readUByte()); + ret.push_back(in.ReadUint8()); return ret; } @@ -103,12 +103,12 @@ void CAnimSource::CalcAverageVelocity() { CAnimSource::CAnimSource(CInputStream& in, IObjectStore& store) : x0_duration(in) , x8_interval(in) -, x10_frameCount(in.readUint32Big()) +, x10_frameCount(in.ReadLong()) , x1c_rootBone(in) , x20_rotationChannels(ReadIndexTable(in)) , x30_translationChannels(ReadIndexTable(in)) , x40_data(RotationAndOffsetStorage::CRotationAndOffsetVectors(in), x10_frameCount) -, x54_evntId(in.readUint32Big()) { +, x54_evntId(in.ReadLong()) { if (x54_evntId.IsValid()) { x58_evntData = store.GetObj({SBIG('EVNT'), x54_evntId}); x58_evntData.GetObj(); diff --git a/Runtime/Character/CAnimation.cpp b/Runtime/Character/CAnimation.cpp index d7de743bb..eb216e020 100644 --- a/Runtime/Character/CAnimation.cpp +++ b/Runtime/Character/CAnimation.cpp @@ -5,7 +5,7 @@ namespace metaforce { CAnimation::CAnimation(CInputStream& in) { - x0_name = in.readString(); + x0_name = in.Get(); x10_anim = CMetaAnimFactory::CreateMetaAnim(in); } diff --git a/Runtime/Character/CAnimationSet.cpp b/Runtime/Character/CAnimationSet.cpp index 690b1a3c7..68f5be3ee 100644 --- a/Runtime/Character/CAnimationSet.cpp +++ b/Runtime/Character/CAnimationSet.cpp @@ -4,13 +4,13 @@ namespace metaforce { -CAnimationSet::CAnimationSet(CInputStream& in) : x0_tableCount(in.readUint16Big()) { - u32 animationCount = in.readUint32Big(); +CAnimationSet::CAnimationSet(CInputStream& in) : x0_tableCount(in.ReadShort()) { + u32 animationCount = in.ReadLong(); x4_animations.reserve(animationCount); for (u32 i = 0; i < animationCount; ++i) x4_animations.emplace_back(in); - u32 transitionCount = in.readUint32Big(); + u32 transitionCount = in.ReadLong(); x14_transitions.reserve(transitionCount); for (u32 i = 0; i < transitionCount; ++i) x14_transitions.emplace_back(in); @@ -18,28 +18,28 @@ CAnimationSet::CAnimationSet(CInputStream& in) : x0_tableCount(in.readUint16Big( x24_defaultTransition = CMetaTransFactory::CreateMetaTrans(in); if (x0_tableCount > 1) { - u32 additiveAnimCount = in.readUint32Big(); + u32 additiveAnimCount = in.ReadLong(); x28_additiveInfo.reserve(additiveAnimCount); for (u32 i = 0; i < additiveAnimCount; ++i) { - u32 id = in.readUint32Big(); + u32 id = in.ReadLong(); x28_additiveInfo.emplace_back(id, in); } x38_defaultAdditiveInfo.read(in); } if (x0_tableCount > 2) { - u32 halfTransitionCount = in.readUint32Big(); + u32 halfTransitionCount = in.ReadLong(); x40_halfTransitions.reserve(halfTransitionCount); for (u32 i = 0; i < halfTransitionCount; ++i) x40_halfTransitions.emplace_back(in); } if (x0_tableCount > 3) { - u32 animResourcesCount = in.readUint32Big(); + u32 animResourcesCount = in.ReadLong(); x50_animRes.reserve(animResourcesCount); for (u32 i = 0; i < animResourcesCount; ++i) { - CAssetId anim = in.readUint32Big(); - CAssetId evnt = in.readUint32Big(); + CAssetId anim = in.ReadLong(); + CAssetId evnt = in.ReadLong(); x50_animRes.emplace_back(anim, evnt); } } diff --git a/Runtime/Character/CBoolPOINode.cpp b/Runtime/Character/CBoolPOINode.cpp index 50e847dfe..f65ae2f94 100644 --- a/Runtime/Character/CBoolPOINode.cpp +++ b/Runtime/Character/CBoolPOINode.cpp @@ -6,7 +6,7 @@ namespace metaforce { CBoolPOINode::CBoolPOINode() : CPOINode("root", EPOIType::EmptyBool, CCharAnimTime(), -1, false, 1.f, -1, 0) {} -CBoolPOINode::CBoolPOINode(CInputStream& in) : CPOINode(in), x38_val(in.readBool()) {} +CBoolPOINode::CBoolPOINode(CInputStream& in) : CPOINode(in), x38_val(in.ReadBool()) {} CBoolPOINode CBoolPOINode::CopyNodeMinusStartTime(const CBoolPOINode& node, const CCharAnimTime& startTime) { CBoolPOINode ret = node; diff --git a/Runtime/Character/CCharAnimTime.hpp b/Runtime/Character/CCharAnimTime.hpp index e2aa45e3b..0f38dc46e 100644 --- a/Runtime/Character/CCharAnimTime.hpp +++ b/Runtime/Character/CCharAnimTime.hpp @@ -19,7 +19,7 @@ public: constexpr CCharAnimTime() = default; constexpr CCharAnimTime(float time) : x0_time(time), x4_type(x0_time != 0.f ? EType::NonZero : EType::ZeroSteady) {} constexpr CCharAnimTime(EType type, float t) : x0_time(t), x4_type(type) {} - explicit CCharAnimTime(CInputStream& in) : x0_time(in.readFloatBig()), x4_type(EType(in.readUint32Big())) {} + explicit CCharAnimTime(CInputStream& in) : x0_time(in.ReadFloat()), x4_type(EType(in.ReadLong())) {} static constexpr CCharAnimTime Infinity() { return {EType::Infinity, 1.0f}; } float GetSeconds() const { return x0_time; } diff --git a/Runtime/Character/CCharLayoutInfo.cpp b/Runtime/Character/CCharLayoutInfo.cpp index 64b1941d5..8fd511d3f 100644 --- a/Runtime/Character/CCharLayoutInfo.cpp +++ b/Runtime/Character/CCharLayoutInfo.cpp @@ -32,30 +32,30 @@ CSegId CCharLayoutInfo::GetSegIdFromString(std::string_view name) const { void CCharLayoutNode::Bone::read(CInputStream& in) { x0_parentId = CSegId(in); - x4_origin.readBig(in); + x4_origin = in.Get(); - const u32 chCount = in.readUint32Big(); + const u32 chCount = in.ReadLong(); x10_children.reserve(chCount); for (u32 i = 0; i < chCount; ++i) { x10_children.emplace_back(in); } } -CCharLayoutNode::CCharLayoutNode(CInputStream& in) : x0_boneMap(in.readUint32Big()) { +CCharLayoutNode::CCharLayoutNode(CInputStream& in) : x0_boneMap(in.ReadLong()) { const u32 cap = x0_boneMap.GetCapacity(); for (u32 i = 0; i < cap; ++i) { - const u32 thisId = in.readUint32Big(); + const u32 thisId = in.ReadLong(); Bone& bone = x0_boneMap[thisId]; bone.read(in); } } CCharLayoutInfo::CCharLayoutInfo(CInputStream& in) : x0_node(std::make_shared(in)), x8_segIdList(in) { - const atUint32 mapCount = in.readUint32Big(); + const atUint32 mapCount = in.ReadLong(); for (atUint32 i = 0; i < mapCount; ++i) { - std::string key = in.readString(); + std::string key = in.Get(); x18_segIdMap.emplace(std::move(key), in); } } diff --git a/Runtime/Character/CCharacterInfo.cpp b/Runtime/Character/CCharacterInfo.cpp index 7dec11562..0ce8908a9 100644 --- a/Runtime/Character/CCharacterInfo.cpp +++ b/Runtime/Character/CCharacterInfo.cpp @@ -1,76 +1,77 @@ #include "Runtime/Character/CCharacterInfo.hpp" +#include "Runtime/IOStreams.hpp" namespace metaforce { CCharacterInfo::CParticleResData::CParticleResData(CInputStream& in, u16 tableCount) { - const u32 partCount = in.readUint32Big(); + const u32 partCount = in.ReadLong(); x0_part.reserve(partCount); for (u32 i = 0; i < partCount; ++i) { - x0_part.emplace_back(in.readUint32Big()); + x0_part.emplace_back(in.Get()); } - const u32 swhcCount = in.readUint32Big(); + const u32 swhcCount = in.ReadLong(); x10_swhc.reserve(swhcCount); for (u32 i = 0; i < swhcCount; ++i) { - x10_swhc.emplace_back(in.readUint32Big()); + x10_swhc.emplace_back(in.Get()); } - const u32 unkCount = in.readUint32Big(); + const u32 unkCount = in.ReadLong(); x20_elsc.reserve(unkCount); for (u32 i = 0; i < unkCount; ++i) { - x20_elsc.emplace_back(in.readUint32Big()); + x20_elsc.emplace_back(in.Get()); } if (tableCount > 5) { - const u32 elscCount = in.readUint32Big(); + const u32 elscCount = in.ReadLong(); x30_elsc.reserve(elscCount); for (u32 i = 0; i < elscCount; ++i) { - x30_elsc.emplace_back(in.readUint32Big()); + x30_elsc.emplace_back(in.Get()); } } } static std::vector>> MakeAnimInfoVector(CInputStream& in) { std::vector>> ret; - const u32 animInfoCount = in.readUint32Big(); + const u32 animInfoCount = in.ReadLong(); ret.reserve(animInfoCount); for (u32 i = 0; i < animInfoCount; ++i) { - const s32 idx = in.readInt32Big(); - std::string a = in.readString(); - std::string b = in.readString(); + const s32 idx = in.ReadLong(); + std::string a = in.Get(); + std::string b = in.Get(); ret.emplace_back(idx, std::make_pair(std::move(a), std::move(b))); } return ret; } CCharacterInfo::CCharacterInfo(CInputStream& in) -: x0_tableCount(in.readUint16Big()) -, x4_name(in.readString()) -, x14_cmdl(in.readUint32Big()) -, x18_cskr(in.readUint32Big()) -, x1c_cinf(in.readUint32Big()) +: x0_tableCount(in.ReadShort()) +, x4_name(in.Get()) +, x14_cmdl(in.ReadLong()) +, x18_cskr(in.ReadLong()) +, x1c_cinf(in.ReadLong()) , x20_animInfo(MakeAnimInfoVector(in)) , x30_pasDatabase(in) , x44_partRes(in, x0_tableCount) -, x84_unk(in.readUint32Big()) { +, x84_unk(in.ReadLong()) { if (x0_tableCount > 1) { - const u32 aabbCount = in.readUint32Big(); + const u32 aabbCount = in.ReadLong(); x88_aabbs.reserve(aabbCount); for (u32 i = 0; i < aabbCount; ++i) { - std::string name = in.readString(); + std::string name = in.Get(); x88_aabbs.emplace_back(std::move(name), zeus::CAABox()); - x88_aabbs.back().second.readBoundingBoxBig(in); + x88_aabbs.back().second = in.Get(); } } if (x0_tableCount > 2) { - const u32 effectCount = in.readUint32Big(); + const u32 effectCount = in.ReadLong(); x98_effects.reserve(effectCount); for (u32 i = 0; i < effectCount; ++i) { - std::string name = in.readString(); + std::string name = in.Get(); x98_effects.emplace_back(std::move(name), std::vector()); std::vector& comps = x98_effects.back().second; - const u32 compCount = in.readUint32Big(); + const u32 compCount = in.ReadLong(); comps.reserve(compCount); for (u32 j = 0; j < compCount; ++j) { comps.emplace_back(in); @@ -79,15 +80,15 @@ CCharacterInfo::CCharacterInfo(CInputStream& in) } if (x0_tableCount > 3) { - xa8_cmdlOverlay = in.readUint32Big(); - xac_cskrOverlay = in.readUint32Big(); + xa8_cmdlOverlay = in.ReadLong(); + xac_cskrOverlay = in.ReadLong(); } if (x0_tableCount > 4) { - const u32 aidxCount = in.readUint32Big(); + const u32 aidxCount = in.ReadLong(); xb0_animIdxs.reserve(aidxCount); for (u32 i = 0; i < aidxCount; ++i) { - xb0_animIdxs.push_back(in.readInt32Big()); + xb0_animIdxs.push_back(in.ReadLong()); } } } diff --git a/Runtime/Character/CCharacterSet.cpp b/Runtime/Character/CCharacterSet.cpp index a0bc9bbdc..4cc652b4d 100644 --- a/Runtime/Character/CCharacterSet.cpp +++ b/Runtime/Character/CCharacterSet.cpp @@ -2,10 +2,10 @@ namespace metaforce { -CCharacterSet::CCharacterSet(CInputStream& in) : x0_version(in.readUint16Big()) { - u32 charCount = in.readUint32Big(); +CCharacterSet::CCharacterSet(CInputStream& in) : x0_version(in.ReadShort()) { + u32 charCount = in.ReadLong(); for (u32 i = 0; i < charCount; ++i) { - u32 id = in.readUint32Big(); + u32 id = in.ReadLong(); x4_characters.emplace(id, in); } } diff --git a/Runtime/Character/CEffectComponent.cpp b/Runtime/Character/CEffectComponent.cpp index 050a960d9..17f79d617 100644 --- a/Runtime/Character/CEffectComponent.cpp +++ b/Runtime/Character/CEffectComponent.cpp @@ -2,15 +2,15 @@ namespace metaforce { -SObjectTag CEffectComponent::GetSObjectTagFromStream(CInputStream& in) { return SObjectTag(in); } +SObjectTag CEffectComponent::GetSObjectTagFromStream(CInputStream& in) { return in.Get(); } CEffectComponent::CEffectComponent(CInputStream& in) { - x0_name = in.readString(); + x0_name = in.Get(); x10_tag = GetSObjectTagFromStream(in); - x18_boneName = in.readString(); - x28_scale = in.readFloatBig(); - x2c_parentedMode = CParticleData::EParentedMode(in.readUint32Big()); - x30_flags = in.readUint32Big(); + x18_boneName = in.Get(); + x28_scale = in.ReadFloat(); + x2c_parentedMode = CParticleData::EParentedMode(in.ReadLong()); + x30_flags = in.ReadLong(); } } // namespace metaforce diff --git a/Runtime/Character/CFBStreamedCompression.cpp b/Runtime/Character/CFBStreamedCompression.cpp index a2be29412..4b18c7afb 100644 --- a/Runtime/Character/CFBStreamedCompression.cpp +++ b/Runtime/Character/CFBStreamedCompression.cpp @@ -23,8 +23,8 @@ void WriteValue(u8* data, T value) { } // Anonymous namespace CFBStreamedCompression::CFBStreamedCompression(CInputStream& in, IObjectStore& objStore, bool pc) : m_pc(pc) { - x0_scratchSize = in.readUint32Big(); - x4_evnt = in.readUint32Big(); + x0_scratchSize = in.ReadLong(); + x4_evnt = in.ReadLong(); xc_rotsAndOffs = GetRotationsAndOffsets(x0_scratchSize / 4 + 1, in); @@ -86,78 +86,78 @@ std::unique_ptr CFBStreamedCompression::GetRotationsAndOffsets(u32 words, std::memcpy(ret.get(), &head, sizeof(head)); u32* bitmapOut = &ret[9]; - const u32 bitmapBitCount = in.readUint32Big(); + const u32 bitmapBitCount = in.ReadLong(); bitmapOut[0] = bitmapBitCount; const u32 bitmapWordCount = (bitmapBitCount + 31) / 32; for (u32 i = 0; i < bitmapWordCount; ++i) { - bitmapOut[i + 1] = in.readUint32Big(); + bitmapOut[i + 1] = in.ReadLong(); } - in.readUint32Big(); + in.ReadLong(); u8* chans = reinterpret_cast(bitmapOut + bitmapWordCount + 1); u8* bs = ReadBoneChannelDescriptors(chans, in); const u32 bsWords = ComputeBitstreamWords(chans); u32* bsPtr = reinterpret_cast(bs); for (u32 w = 0; w < bsWords; ++w) - bsPtr[w] = in.readUint32Big(); + bsPtr[w] = in.ReadLong(); return ret; } u8* CFBStreamedCompression::ReadBoneChannelDescriptors(u8* out, CInputStream& in) const { - const u32 boneChanCount = in.readUint32Big(); + const u32 boneChanCount = in.ReadLong(); WriteValue(out, boneChanCount); out += 4; if (m_pc) { for (u32 b = 0; b < boneChanCount; ++b) { - WriteValue(out, in.readUint32Big()); + WriteValue(out, in.ReadLong()); out += 4; - WriteValue(out, in.readUint32Big()); + WriteValue(out, in.ReadLong()); out += 4; for (int i = 0; i < 3; ++i) { - WriteValue(out, in.readUint32Big()); + WriteValue(out, in.ReadLong()); out += 4; } - const u32 tCount = in.readUint32Big(); + const u32 tCount = in.ReadLong(); WriteValue(out, tCount); out += 4; if (tCount != 0) { for (int i = 0; i < 3; ++i) { - WriteValue(out, in.readUint32Big()); + WriteValue(out, in.ReadLong()); out += 4; } } } } else { for (u32 b = 0; b < boneChanCount; ++b) { - WriteValue(out, in.readUint32Big()); + WriteValue(out, in.ReadLong()); out += 4; - WriteValue(out, in.readUint16Big()); + WriteValue(out, in.ReadShort()); out += 2; for (int i = 0; i < 3; ++i) { - WriteValue(out, in.readInt16Big()); + WriteValue(out, in.ReadShort()); out += 2; - WriteValue(out, in.readUByte()); + WriteValue(out, in.ReadUint8()); out += 1; } - const u16 tCount = in.readUint16Big(); + const u16 tCount = in.ReadShort(); WriteValue(out, tCount); out += 2; if (tCount != 0) { for (int i = 0; i < 3; ++i) { - WriteValue(out, in.readInt16Big()); + WriteValue(out, in.ReadShort()); out += 2; - WriteValue(out, in.readUByte()); + WriteValue(out, in.ReadUint8()); out += 1; } } diff --git a/Runtime/Character/CFBStreamedCompression.hpp b/Runtime/Character/CFBStreamedCompression.hpp index 2d06cd1cc..a6aca4390 100644 --- a/Runtime/Character/CFBStreamedCompression.hpp +++ b/Runtime/Character/CFBStreamedCompression.hpp @@ -31,23 +31,23 @@ public: void read(CInputStream& in) { /* unk0 */ - unk0 = in.readUint32Big(); + unk0 = in.ReadLong(); /* duration */ - duration = in.readFloatBig(); + duration = in.ReadFloat(); /* interval */ - interval = in.readFloatBig(); + interval = in.ReadFloat(); /* rootBoneId */ - rootBoneId = in.readUint32Big(); + rootBoneId = in.ReadLong(); /* looping */ - looping = in.readUint32Big(); + looping = in.ReadLong(); /* rotDiv */ - rotDiv = in.readUint32Big(); + rotDiv = in.ReadLong(); /* translationMult */ - translationMult = in.readFloatBig(); + translationMult = in.ReadFloat(); /* boneChannelCount */ - boneChannelCount = in.readUint32Big(); + boneChannelCount = in.ReadLong(); /* unk3 */ - unk3 = in.readUint32Big(); + unk3 = in.ReadLong(); } }; diff --git a/Runtime/Character/CHalfTransition.cpp b/Runtime/Character/CHalfTransition.cpp index 36a00f1e3..43025512f 100644 --- a/Runtime/Character/CHalfTransition.cpp +++ b/Runtime/Character/CHalfTransition.cpp @@ -5,7 +5,7 @@ namespace metaforce { CHalfTransition::CHalfTransition(CInputStream& in) { - x0_id = in.readUint32Big(); + x0_id = in.ReadLong(); x4_trans = CMetaTransFactory::CreateMetaTrans(in); } diff --git a/Runtime/Character/CInt32POINode.cpp b/Runtime/Character/CInt32POINode.cpp index 324ff54f4..3e0cd218b 100644 --- a/Runtime/Character/CInt32POINode.cpp +++ b/Runtime/Character/CInt32POINode.cpp @@ -11,7 +11,7 @@ CInt32POINode::CInt32POINode(std::string_view name, EPOIType type, const CCharAn : CPOINode(name, type, time, index, unique, weight, charIndex, flags), x38_val(val), x3c_locatorName(locator) {} CInt32POINode::CInt32POINode(CInputStream& in) -: CPOINode(in), x38_val(in.readUint32Big()), x3c_locatorName(in.readString()) {} +: CPOINode(in), x38_val(in.ReadLong()), x3c_locatorName(in.Get()) {} CInt32POINode CInt32POINode::CopyNodeMinusStartTime(const CInt32POINode& node, const CCharAnimTime& startTime) { CInt32POINode ret = node; diff --git a/Runtime/Character/CMetaAnimBlend.cpp b/Runtime/Character/CMetaAnimBlend.cpp index 67d81f3d2..30c988ec2 100644 --- a/Runtime/Character/CMetaAnimBlend.cpp +++ b/Runtime/Character/CMetaAnimBlend.cpp @@ -8,8 +8,8 @@ namespace metaforce { CMetaAnimBlend::CMetaAnimBlend(CInputStream& in) { x4_animA = CMetaAnimFactory::CreateMetaAnim(in); x8_animB = CMetaAnimFactory::CreateMetaAnim(in); - xc_blend = in.readFloatBig(); - x10_ = in.readBool(); + xc_blend = in.ReadFloat(); + x10_ = in.ReadBool(); } void CMetaAnimBlend::GetUniquePrimitives(std::set& primsOut) const { diff --git a/Runtime/Character/CMetaAnimFactory.cpp b/Runtime/Character/CMetaAnimFactory.cpp index daf92802e..b41bc3c11 100644 --- a/Runtime/Character/CMetaAnimFactory.cpp +++ b/Runtime/Character/CMetaAnimFactory.cpp @@ -9,7 +9,7 @@ namespace metaforce { std::shared_ptr CMetaAnimFactory::CreateMetaAnim(CInputStream& in) { - EMetaAnimType type = EMetaAnimType(in.readUint32Big()); + EMetaAnimType type = EMetaAnimType(in.ReadLong()); switch (type) { case EMetaAnimType::Play: diff --git a/Runtime/Character/CMetaAnimPhaseBlend.cpp b/Runtime/Character/CMetaAnimPhaseBlend.cpp index da9d00cde..42095d332 100644 --- a/Runtime/Character/CMetaAnimPhaseBlend.cpp +++ b/Runtime/Character/CMetaAnimPhaseBlend.cpp @@ -9,8 +9,8 @@ namespace metaforce { CMetaAnimPhaseBlend::CMetaAnimPhaseBlend(CInputStream& in) { x4_animA = CMetaAnimFactory::CreateMetaAnim(in); x8_animB = CMetaAnimFactory::CreateMetaAnim(in); - xc_blend = in.readFloatBig(); - x10_ = in.readBool(); + xc_blend = in.ReadFloat(); + x10_ = in.ReadBool(); } void CMetaAnimPhaseBlend::GetUniquePrimitives(std::set& primsOut) const { diff --git a/Runtime/Character/CMetaAnimRandom.cpp b/Runtime/Character/CMetaAnimRandom.cpp index 02f1f1342..74cdac9c1 100644 --- a/Runtime/Character/CMetaAnimRandom.cpp +++ b/Runtime/Character/CMetaAnimRandom.cpp @@ -7,12 +7,12 @@ namespace metaforce { CMetaAnimRandom::RandomData CMetaAnimRandom::CreateRandomData(CInputStream& in) { CMetaAnimRandom::RandomData ret; - u32 randCount = in.readUint32Big(); + u32 randCount = in.ReadLong(); ret.reserve(randCount); for (u32 i = 0; i < randCount; ++i) { std::shared_ptr metaAnim = CMetaAnimFactory::CreateMetaAnim(in); - ret.emplace_back(std::move(metaAnim), in.readUint32Big()); + ret.emplace_back(std::move(metaAnim), in.ReadLong()); } return ret; diff --git a/Runtime/Character/CMetaAnimSequence.cpp b/Runtime/Character/CMetaAnimSequence.cpp index a96539731..ffa717670 100644 --- a/Runtime/Character/CMetaAnimSequence.cpp +++ b/Runtime/Character/CMetaAnimSequence.cpp @@ -7,7 +7,7 @@ namespace metaforce { std::vector> CMetaAnimSequence::CreateSequence(CInputStream& in) { std::vector> ret; - u32 seqCount = in.readUint32Big(); + u32 seqCount = in.ReadLong(); ret.reserve(seqCount); for (u32 i = 0; i < seqCount; ++i) diff --git a/Runtime/Character/CMetaTransFactory.cpp b/Runtime/Character/CMetaTransFactory.cpp index 1ae7d87fd..b408d00f1 100644 --- a/Runtime/Character/CMetaTransFactory.cpp +++ b/Runtime/Character/CMetaTransFactory.cpp @@ -8,7 +8,7 @@ namespace metaforce { std::shared_ptr CMetaTransFactory::CreateMetaTrans(CInputStream& in) { - EMetaTransType type = EMetaTransType(in.readUint32Big()); + EMetaTransType type = EMetaTransType(in.ReadLong()); switch (type) { case EMetaTransType::MetaAnim: diff --git a/Runtime/Character/CMetaTransPhaseTrans.cpp b/Runtime/Character/CMetaTransPhaseTrans.cpp index f158da0aa..7a09cee6b 100644 --- a/Runtime/Character/CMetaTransPhaseTrans.cpp +++ b/Runtime/Character/CMetaTransPhaseTrans.cpp @@ -9,9 +9,9 @@ namespace metaforce { CMetaTransPhaseTrans::CMetaTransPhaseTrans(CInputStream& in) { x4_transDur = CCharAnimTime(in); - xc_ = in.readBool(); - xd_runA = in.readBool(); - x10_flags = in.readUint32Big(); + xc_ = in.ReadBool(); + xd_runA = in.ReadBool(); + x10_flags = in.ReadLong(); } std::shared_ptr CMetaTransPhaseTrans::VGetTransitionTree(const std::weak_ptr& a, diff --git a/Runtime/Character/CMetaTransTrans.cpp b/Runtime/Character/CMetaTransTrans.cpp index a64b86b30..914d1755c 100644 --- a/Runtime/Character/CMetaTransTrans.cpp +++ b/Runtime/Character/CMetaTransTrans.cpp @@ -5,10 +5,10 @@ namespace metaforce { CMetaTransTrans::CMetaTransTrans(CInputStream& in) { - x4_transDur = CCharAnimTime(in); - xc_ = in.readBool(); - xd_runA = in.readBool(); - x10_flags = in.readUint32Big(); + x4_transDur = in.Get(); + xc_ = in.ReadBool(); + xd_runA = in.ReadBool(); + x10_flags = in.ReadLong(); } std::shared_ptr CMetaTransTrans::VGetTransitionTree(const std::weak_ptr& a, diff --git a/Runtime/Character/CPASAnimState.cpp b/Runtime/Character/CPASAnimState.cpp index 1c02ffd78..8781f94e2 100644 --- a/Runtime/Character/CPASAnimState.cpp +++ b/Runtime/Character/CPASAnimState.cpp @@ -14,9 +14,9 @@ namespace metaforce { CPASAnimState::CPASAnimState(CInputStream& in) { - x0_id = static_cast(in.readUint32Big()); - u32 parmCount = in.readUint32Big(); - u32 animCount = in.readUint32Big(); + x0_id = static_cast(in.ReadLong()); + u32 parmCount = in.ReadLong(); + u32 animCount = in.ReadLong(); x4_parms.reserve(parmCount); x14_anims.reserve(animCount); @@ -26,25 +26,25 @@ CPASAnimState::CPASAnimState(CInputStream& in) { x4_parms.emplace_back(in); for (u32 i = 0; i < animCount; ++i) { - s32 id = in.readUint32Big(); + s32 id = in.ReadLong(); rstl::reserved_vector parms; for (const CPASParmInfo& parm : x4_parms) { CPASAnimParm::UParmValue val = {}; switch (parm.GetParameterType()) { case CPASAnimParm::EParmType::Int32: - val.m_int = in.readInt32Big(); + val.m_int = in.ReadInt32(); break; case CPASAnimParm::EParmType::UInt32: - val.m_uint = in.readUint32Big(); + val.m_uint = in.ReadLong(); break; case CPASAnimParm::EParmType::Float: - val.m_float = in.readFloatBig(); + val.m_float = in.ReadFloat(); break; case CPASAnimParm::EParmType::Bool: - val.m_bool = in.readBool(); + val.m_bool = in.ReadBool(); break; case CPASAnimParm::EParmType::Enum: - val.m_int = in.readInt32Big(); + val.m_int = in.ReadInt32(); break; default: break; diff --git a/Runtime/Character/CPASDatabase.cpp b/Runtime/Character/CPASDatabase.cpp index d6d922684..d661116e0 100644 --- a/Runtime/Character/CPASDatabase.cpp +++ b/Runtime/Character/CPASDatabase.cpp @@ -17,9 +17,9 @@ void CPASDatabase::AddAnimState(CPASAnimState&& state) { } CPASDatabase::CPASDatabase(CInputStream& in) { - in.readUint32Big(); - u32 animStateCount = in.readUint32Big(); - u32 defaultState = in.readUint32Big(); + in.ReadLong(); + u32 animStateCount = in.ReadLong(); + u32 defaultState = in.ReadLong(); x0_states.reserve(animStateCount); for (u32 i = 0; i < animStateCount; ++i) { diff --git a/Runtime/Character/CPASParmInfo.cpp b/Runtime/Character/CPASParmInfo.cpp index 80920c0b4..919f1ff5f 100644 --- a/Runtime/Character/CPASParmInfo.cpp +++ b/Runtime/Character/CPASParmInfo.cpp @@ -2,33 +2,33 @@ namespace metaforce { -CPASParmInfo::CPASParmInfo(CInputStream& in) { +CPASParmInfo::CPASParmInfo(CInputStream& in) +: x0_type(CPASAnimParm::EParmType(in.ReadLong())), x4_weightFunction(EWeightFunction(in.ReadLong())) { xc_min.m_int = 0; x10_max.m_int = 0; - x0_type = CPASAnimParm::EParmType(in.readUint32Big()); - x4_weightFunction = EWeightFunction(in.readUint32Big()); - x8_weight = in.readFloatBig(); + + x8_weight = in.ReadFloat(); switch (x0_type) { case CPASAnimParm::EParmType::Int32: - xc_min.m_int = in.readInt32Big(); - x10_max.m_int = in.readInt32Big(); + xc_min.m_int = in.ReadInt32(); + x10_max.m_int = in.ReadInt32(); break; case CPASAnimParm::EParmType::UInt32: - xc_min.m_uint = in.readUint32Big(); - x10_max.m_uint = in.readUint32Big(); + xc_min.m_uint = in.ReadLong(); + x10_max.m_uint = in.ReadLong(); break; case CPASAnimParm::EParmType::Float: - xc_min.m_float = in.readFloatBig(); - x10_max.m_float = in.readFloatBig(); + xc_min.m_float = in.ReadFloat(); + x10_max.m_float = in.ReadFloat(); break; case CPASAnimParm::EParmType::Bool: - xc_min.m_bool = in.readBool(); - x10_max.m_bool = in.readBool(); + xc_min.m_bool = in.ReadBool(); + x10_max.m_bool = in.ReadBool(); break; case CPASAnimParm::EParmType::Enum: - xc_min.m_int = in.readInt32Big(); - x10_max.m_int = in.readInt32Big(); + xc_min.m_int = in.ReadInt32(); + x10_max.m_int = in.ReadInt32(); break; default: break; diff --git a/Runtime/Character/CPOINode.cpp b/Runtime/Character/CPOINode.cpp index 9e3ece784..911c1c107 100644 --- a/Runtime/Character/CPOINode.cpp +++ b/Runtime/Character/CPOINode.cpp @@ -21,15 +21,15 @@ CPOINode::CPOINode(std::string_view name, EPOIType type, const CCharAnimTime& ti , x34_flags(f) {} CPOINode::CPOINode(CInputStream& in) -: x4_(in.readUint16Big()) -, x8_name(in.readString()) -, x18_type(EPOIType(in.readUint16Big())) +: x4_(in.ReadShort()) +, x8_name(in.Get()) +, x18_type(EPOIType(in.ReadShort())) , x1c_time(in) -, x24_index(in.readInt32Big()) -, x28_unique(in.readBool()) -, x2c_weight(in.readFloatBig()) -, x30_charIdx(in.readInt32Big()) -, x34_flags(in.readInt32Big()) {} +, x24_index(in.ReadInt32()) +, x28_unique(in.ReadBool()) +, x2c_weight(in.ReadFloat()) +, x30_charIdx(in.ReadInt32()) +, x34_flags(in.ReadInt32()) {} bool CPOINode::operator>(const CPOINode& other) const { return x1c_time > other.x1c_time; } diff --git a/Runtime/Character/CParticleData.cpp b/Runtime/Character/CParticleData.cpp index c54b8bc26..3b0b11905 100644 --- a/Runtime/Character/CParticleData.cpp +++ b/Runtime/Character/CParticleData.cpp @@ -3,10 +3,10 @@ namespace metaforce { CParticleData::CParticleData(CInputStream& in) -: x0_duration(in.readUint32Big()) +: x0_duration(in.ReadLong()) , x4_particle(in) -, xc_boneName(in.readString()) -, x1c_scale(in.readFloatBig()) -, x20_parentMode(EParentedMode(in.readUint32Big())) {} +, xc_boneName(in.Get()) +, x1c_scale(in.ReadFloat()) +, x20_parentMode(EParentedMode(in.ReadLong())) {} } // namespace metaforce diff --git a/Runtime/Character/CPrimitive.cpp b/Runtime/Character/CPrimitive.cpp index 3857528c0..feb436ce0 100644 --- a/Runtime/Character/CPrimitive.cpp +++ b/Runtime/Character/CPrimitive.cpp @@ -3,9 +3,9 @@ namespace metaforce { CPrimitive::CPrimitive(CInputStream& in) { - x0_animId = in.readUint32Big(); - x4_animIdx = in.readUint32Big(); - x8_animName = in.readString(); + x0_animId = in.ReadLong(); + x4_animIdx = in.ReadLong(); + x8_animName = in.Get(); } } // namespace metaforce diff --git a/Runtime/Character/CSegId.hpp b/Runtime/Character/CSegId.hpp index 3bcaa78d2..2611e60ba 100644 --- a/Runtime/Character/CSegId.hpp +++ b/Runtime/Character/CSegId.hpp @@ -11,7 +11,7 @@ class CSegId { public: constexpr CSegId() noexcept = default; constexpr CSegId(u8 id) noexcept : x0_segId(id) {} - explicit CSegId(CInputStream& in) : x0_segId(in.readUint32Big()) {} + explicit CSegId(CInputStream& in) : x0_segId(in.ReadUint8()) {} constexpr CSegId& operator++() noexcept { ++x0_segId; return *this; diff --git a/Runtime/Character/CSegIdList.cpp b/Runtime/Character/CSegIdList.cpp index aecb44d48..9ece5f11d 100644 --- a/Runtime/Character/CSegIdList.cpp +++ b/Runtime/Character/CSegIdList.cpp @@ -3,7 +3,7 @@ namespace metaforce { CSegIdList::CSegIdList(CInputStream& in) { - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x0_list.reserve(count); for (u32 i = 0; i < count; ++i) x0_list.emplace_back(in); diff --git a/Runtime/Character/CSkinBank.cpp b/Runtime/Character/CSkinBank.cpp index 487a58875..ca9f42406 100644 --- a/Runtime/Character/CSkinBank.cpp +++ b/Runtime/Character/CSkinBank.cpp @@ -5,7 +5,7 @@ namespace metaforce { CSkinBank::CSkinBank(CInputStream& in) { - u32 boneCount = in.readUint32Big(); + u32 boneCount = in.ReadLong(); x0_segments.reserve(boneCount); for (u32 i = 0; i < boneCount; ++i) x0_segments.emplace_back(in); diff --git a/Runtime/Character/CSkinRules.cpp b/Runtime/Character/CSkinRules.cpp index dce9d3b2e..f05e1a21d 100644 --- a/Runtime/Character/CSkinRules.cpp +++ b/Runtime/Character/CSkinRules.cpp @@ -7,16 +7,21 @@ namespace metaforce { static u32 ReadCount(CInputStream& in) { - u32 result = in.readUint32Big(); + u32 result = in.ReadLong(); if (result == UINT32_MAX) { - return in.readUint32Big(); + return in.ReadLong(); + } + u8 junk[784]; + for (u32 i = 0; i < (result * 3); ++i) { + u32 iVar2 = ((result * 3) - i); + iVar2 = 192 < iVar2 ? 192 : iVar2; + in.Get(junk, iVar2 * 4); } - in.seek(s64(result) * 3); return result; } CSkinRules::CSkinRules(CInputStream& in) { - u32 weightCount = in.readUint32Big(); + u32 weightCount = in.ReadLong(); x0_bones.reserve(weightCount); for (int i = 0; i < weightCount; ++i) { x0_bones.emplace_back(in); @@ -51,7 +56,7 @@ CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, cons auto StreamInSkinWeighting(CInputStream& in) { rstl::reserved_vector weights; - u32 weightCount = in.readUint32Big(); + u32 weightCount = in.ReadLong(); for (int i = 0; i < std::min(3u, weightCount); ++i) { weights.emplace_back(in); } @@ -62,5 +67,5 @@ auto StreamInSkinWeighting(CInputStream& in) { } CVirtualBone::CVirtualBone(CInputStream& in) -: x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.readUint32Big()) {} +: x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.ReadLong()) {} } // namespace metaforce diff --git a/Runtime/Character/CSkinRules.hpp b/Runtime/Character/CSkinRules.hpp index 109c9a783..732166a07 100644 --- a/Runtime/Character/CSkinRules.hpp +++ b/Runtime/Character/CSkinRules.hpp @@ -15,7 +15,7 @@ class CModel; struct SSkinWeighting { CSegId x0_id; float x4_weight; - explicit SSkinWeighting(CInputStream& in) : x0_id(in), x4_weight(in.readFloatBig()) {} + explicit SSkinWeighting(CInputStream& in) : x0_id(in), x4_weight(in.ReadFloat()) {} }; class CVirtualBone { diff --git a/Runtime/Character/CSoundPOINode.cpp b/Runtime/Character/CSoundPOINode.cpp index 53a2b3c1f..3f65d7c4b 100644 --- a/Runtime/Character/CSoundPOINode.cpp +++ b/Runtime/Character/CSoundPOINode.cpp @@ -11,7 +11,7 @@ CSoundPOINode::CSoundPOINode() , x40_maxDist(0.f) {} CSoundPOINode::CSoundPOINode(CInputStream& in) -: CPOINode(in), x38_sfxId(in.readUint32Big()), x3c_falloff(in.readFloatBig()), x40_maxDist(in.readFloatBig()) {} +: CPOINode(in), x38_sfxId(in.ReadLong()), x3c_falloff(in.ReadFloat()), x40_maxDist(in.ReadFloat()) {} CSoundPOINode::CSoundPOINode(std::string_view name, EPOIType a, const CCharAnimTime& time, u32 b, bool c, float d, u32 e, u32 f, u32 sfxId, float falloff, float maxDist) diff --git a/Runtime/Character/CTransition.cpp b/Runtime/Character/CTransition.cpp index db98cd867..358fb1745 100644 --- a/Runtime/Character/CTransition.cpp +++ b/Runtime/Character/CTransition.cpp @@ -3,9 +3,9 @@ namespace metaforce { CTransition::CTransition(CInputStream& in) -: x0_id(in.readUint32Big()) -, x4_animA(in.readUint32Big()) -, x8_animB(in.readUint32Big()) +: x0_id(in.ReadLong()) +, x4_animA(in.ReadLong()) +, x8_animB(in.ReadLong()) , xc_trans(CMetaTransFactory::CreateMetaTrans(in)) {} } // namespace metaforce diff --git a/Runtime/Collision/CAreaOctTree.cpp b/Runtime/Collision/CAreaOctTree.cpp index 5cf30f2a3..11804b718 100644 --- a/Runtime/Collision/CAreaOctTree.cpp +++ b/Runtime/Collision/CAreaOctTree.cpp @@ -538,14 +538,13 @@ CAreaOctTree::CAreaOctTree(const zeus::CAABox& aabb, Node::ETreeType treeType, c } std::unique_ptr CAreaOctTree::MakeFromMemory(const u8* buf, unsigned int size) { - athena::io::MemoryReader r(buf + 8, size - 8); - r.readUint32Big(); - r.readUint32Big(); - zeus::CAABox aabb; - aabb.readBoundingBoxBig(r); - Node::ETreeType nodeType = Node::ETreeType(r.readUint32Big()); - u32 treeSize = r.readUint32Big(); - const u8* cur = reinterpret_cast(buf) + 8 + r.position(); + CMemoryInStream r(buf + 8, size - 8, CMemoryInStream::EOwnerShip::NotOwned); + r.ReadLong(); + r.ReadLong(); + zeus::CAABox aabb = r.Get(); + Node::ETreeType nodeType = Node::ETreeType(r.ReadLong()); + u32 treeSize = r.ReadLong(); + const u8* cur = reinterpret_cast(buf) + 8 + r.GetReadPosition(); const u8* treeBuf = cur; cur += treeSize; diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.cpp b/Runtime/Collision/CCollidableOBBTreeGroup.cpp index fcedbe3c4..8d59ccc5b 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.cpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.cpp @@ -11,7 +11,7 @@ namespace metaforce { constexpr CCollisionPrimitive::Type sType(CCollidableOBBTreeGroup::SetStaticTableIndex, "CCollidableOBBTreeGroup"); CCollidableOBBTreeGroupContainer::CCollidableOBBTreeGroupContainer(CInputStream& in) { - const u32 treeCount = in.readUint32Big(); + const u32 treeCount = in.ReadLong(); x0_trees.reserve(treeCount); for (u32 i = 0; i < treeCount; i++) { diff --git a/Runtime/Collision/CCollisionEdge.cpp b/Runtime/Collision/CCollisionEdge.cpp index d7733136b..368a6c359 100644 --- a/Runtime/Collision/CCollisionEdge.cpp +++ b/Runtime/Collision/CCollisionEdge.cpp @@ -1,8 +1,9 @@ #include "Runtime/Collision/CCollisionEdge.hpp" +#include "Runtime/CInputStream.hpp" namespace metaforce { CCollisionEdge::CCollisionEdge(CInputStream& in) { - x0_index1 = in.readUint16Big(); - x2_index2 = in.readUint16Big(); + x0_index1 = in.ReadShort(); + x2_index2 = in.ReadShort(); } } // namespace metaforce diff --git a/Runtime/Collision/CCollisionResponseData.cpp b/Runtime/Collision/CCollisionResponseData.cpp index e99c8fbc1..cff473279 100644 --- a/Runtime/Collision/CCollisionResponseData.cpp +++ b/Runtime/Collision/CCollisionResponseData.cpp @@ -100,7 +100,7 @@ bool CCollisionResponseData::CheckAndAddDecalToResponse(FourCC clsId, CInputStre return true; } - const CAssetId id{u64(in.readUint32Big())}; + const CAssetId id = in.Get(); if (!id.IsValid()) { return true; } diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index fec3facd0..aa54e57b9 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -41,16 +41,16 @@ constexpr std::array DefaultSurfaceIndices{ }; /* This is exactly what retro did >.< */ -u32 verify_deaf_babe(CInputStream& in) { return in.readUint32Big(); } +u32 verify_deaf_babe(CInputStream& in) { return in.ReadLong(); } /* This is exactly what retro did >.< */ -u32 verify_version(CInputStream& in) { return in.readUint32Big(); } +u32 verify_version(CInputStream& in) { return in.ReadLong(); } } // Anonymous namespace COBBTree::COBBTree(CInputStream& in) : x0_magic(verify_deaf_babe(in)) , x4_version(verify_version(in)) -, x8_memsize(in.readUint32()) +, x8_memsize(in.ReadLong()) , x18_indexData(in) , x88_root(std::make_unique(in)) {} @@ -158,38 +158,38 @@ zeus::CAABox COBBTree::CalculateAABox(const zeus::CTransform& xf) const { } COBBTree::SIndexData::SIndexData(CInputStream& in) { - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x0_materials.reserve(count); for (u32 i = 0; i < count; i++) { - x0_materials.emplace_back(in.readUint32Big()); + x0_materials.emplace_back(in.ReadLong()); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { - x10_vertMaterials.emplace_back(in.readUByte()); + x10_vertMaterials.emplace_back(in.ReadUint8()); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { - x20_edgeMaterials.emplace_back(in.readUByte()); + x20_edgeMaterials.emplace_back(in.ReadUint8()); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { - x30_surfaceMaterials.emplace_back(in.readUByte()); + x30_surfaceMaterials.emplace_back(in.ReadUint8()); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { x40_edges.emplace_back(in); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { - x50_surfaceIndices.emplace_back(in.readUint16Big()); + x50_surfaceIndices.emplace_back(in.ReadShort()); } - count = in.readUint32Big(); + count = in.ReadLong(); for (u32 i = 0; i < count; i++) { - x60_vertices.emplace_back(zeus::CVector3f::ReadBig(in)); + x60_vertices.emplace_back(in.Get()); } } @@ -202,8 +202,8 @@ COBBTree::CNode::CNode(const zeus::CTransform& xf, const zeus::CVector3f& point, , x48_leaf(std::move(leaf)) {} COBBTree::CNode::CNode(CInputStream& in) { - x0_obb = zeus::COBBox::ReadBig(in); - x3c_isLeaf = in.readBool(); + x0_obb = in.Get(); + x3c_isLeaf = in.ReadBool(); if (x3c_isLeaf) x48_leaf = std::make_unique(in); else { @@ -236,9 +236,9 @@ size_t COBBTree::CLeafData::GetMemoryUsage() const { } COBBTree::CLeafData::CLeafData(CInputStream& in) { - const u32 edgeCount = in.readUint32Big(); + const u32 edgeCount = in.ReadLong(); for (u32 i = 0; i < edgeCount; i++) { - x0_surface.emplace_back(in.readUint16Big()); + x0_surface.emplace_back(in.ReadShort()); } } diff --git a/Runtime/Graphics/CCubeModel.cpp b/Runtime/Graphics/CCubeModel.cpp index 184eba72d..dc151c453 100644 --- a/Runtime/Graphics/CCubeModel.cpp +++ b/Runtime/Graphics/CCubeModel.cpp @@ -253,16 +253,16 @@ void CCubeModel::MakeTexturesFromMats(const u8* ptr, std::vector(mem.readUint32Big()); - x18_nextSurface = reinterpret_cast(mem.readUint32Big()); - x1c_extraSize = mem.readUint32Big(); - x20_normal.readBig(mem); + CMemoryInStream mem(ptr, 10000, CMemoryInStream::EOwnerShip::NotOwned); // Oversized so we can read everything in + x0_center = mem.Get(); + xc_materialIndex = mem.ReadLong(); + x10_displayListSize = mem.ReadLong(); + x14_parent = reinterpret_cast(mem.ReadLong()); + x18_nextSurface = reinterpret_cast(mem.ReadLong()); + x1c_extraSize = mem.ReadLong(); + x20_normal = mem.Get(); if (x1c_extraSize > 0) { - x2c_bounds = zeus::CAABox::ReadBoundingBoxBig(mem); + x2c_bounds = mem.Get(); } } diff --git a/Runtime/Graphics/CGraphicsPalette.hpp b/Runtime/Graphics/CGraphicsPalette.hpp index 3c83d78b7..cdf2436cb 100644 --- a/Runtime/Graphics/CGraphicsPalette.hpp +++ b/Runtime/Graphics/CGraphicsPalette.hpp @@ -23,9 +23,9 @@ class CGraphicsPalette { public: explicit CGraphicsPalette(EPaletteFormat fmt, int count) : x0_fmt(fmt), x8_entryCount(count), xc_entries(new u16[count]) {} - explicit CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in.readUint32Big())) { - u16 w = in.readUint16Big(); - u16 h = in.readUint16Big(); + explicit CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in.ReadLong())) { + u16 w = in.ReadShort(); + u16 h = in.ReadShort(); x8_entryCount = w * h; /* GX Tlut init here */ diff --git a/Runtime/Graphics/CPVSAreaSet.cpp b/Runtime/Graphics/CPVSAreaSet.cpp index 085d0c8d5..cf51a1a2a 100644 --- a/Runtime/Graphics/CPVSAreaSet.cpp +++ b/Runtime/Graphics/CPVSAreaSet.cpp @@ -5,16 +5,16 @@ namespace metaforce { CPVSAreaSet::CPVSAreaSet(const u8* data, u32 len) { CMemoryInStream r(data, len); - x0_numFeatures = r.readUint32Big(); - x4_numLights = r.readUint32Big(); - x8_num2ndLights = r.readUint32Big(); - xc_numActors = r.readUint32Big(); - x10_leafSize = r.readUint32Big(); - x14_lightIndexCount = r.readUint32Big(); + x0_numFeatures = r.ReadLong(); + x4_numLights = r.ReadLong(); + x8_num2ndLights = r.ReadLong(); + xc_numActors = r.ReadLong(); + x10_leafSize = r.ReadLong(); + x14_lightIndexCount = r.ReadLong(); x18_entityIndex.reserve(xc_numActors); for (u32 i = 0; i < xc_numActors; ++i) - x18_entityIndex.push_back(r.readUint32Big()); - x1c_lightLeaves = data + r.position(); + x18_entityIndex.push_back(r.ReadLong()); + x1c_lightLeaves = data + r.GetReadPosition(); const u8* octreeData = x1c_lightLeaves + x14_lightIndexCount * x10_leafSize; x20_octree = CPVSVisOctree::MakePVSVisOctree(octreeData); } diff --git a/Runtime/Graphics/CPVSVisOctree.cpp b/Runtime/Graphics/CPVSVisOctree.cpp index 5f58e334a..643407584 100644 --- a/Runtime/Graphics/CPVSVisOctree.cpp +++ b/Runtime/Graphics/CPVSVisOctree.cpp @@ -7,11 +7,11 @@ namespace metaforce { CPVSVisOctree CPVSVisOctree::MakePVSVisOctree(const u8* data) { CMemoryInStream r(data, 68); - const zeus::CAABox aabb = zeus::CAABox::ReadBoundingBoxBig(r); - const u32 numObjects = r.readUint32Big(); - const u32 numLights = r.readUint32Big(); - r.readUint32Big(); - return CPVSVisOctree(aabb, numObjects, numLights, data + r.position()); + const zeus::CAABox aabb = r.Get(); + const u32 numObjects = r.ReadLong(); + const u32 numLights = r.ReadLong(); + r.ReadLong(); + return CPVSVisOctree(aabb, numObjects, numLights, data + r.GetReadPosition()); } CPVSVisOctree::CPVSVisOctree(const zeus::CAABox& aabb, u32 numObjects, u32 numLights, const u8* c) diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 40832a6d1..b91255ecf 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -92,7 +92,7 @@ void CTexture::BuildI4FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < std::min(h, 8); ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), std::min(size_t(w) / 4, source.size())); + in.Get(source.data(), std::min(size_t(w) / 4, source.size())); for (size_t x = 0; x < std::min(w, 8); ++x) { target[x].r = Convert4To8(source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf); target[x].g = target[x].r; @@ -132,7 +132,7 @@ void CTexture::BuildI8FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); + in.Get(source.data(), source.size()); for (size_t x = 0; x < source.size(); ++x) { target[x].r = source[x]; target[x].g = source[x]; @@ -172,7 +172,7 @@ void CTexture::BuildIA4FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); + in.Get(source.data(), source.size()); for (size_t x = 0; x < source.size(); ++x) { const u8 intensity = Convert4To8(source[x] >> 4 & 0xf); target[x].r = intensity; @@ -213,7 +213,7 @@ void CTexture::BuildIA8FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), sizeof(source)); + in.Get(reinterpret_cast(source.data()), sizeof(source)); for (size_t x = 0; x < source.size(); ++x) { const u8 intensity = source[x] >> 8; target[x].r = intensity; @@ -243,27 +243,27 @@ static std::vector DecodePalette(int numEntries, CInputStream& in) { enum class EPaletteType { IA8, RGB565, RGB5A3 }; - EPaletteType format = EPaletteType(in.readUint32Big()); - in.readUint32Big(); + EPaletteType format = EPaletteType(in.ReadLong()); + in.ReadLong(); switch (format) { case EPaletteType::IA8: { for (int e = 0; e < numEntries; ++e) { - u8 intensity = in.readUByte(); - u8 alpha = in.readUByte(); + u8 intensity = in.ReadUint8(); + u8 alpha = in.ReadUint8(); ret.push_back({intensity, intensity, intensity, alpha}); } break; } case EPaletteType::RGB565: { for (int e = 0; e < numEntries; ++e) { - u16 texel = in.readUint16Big(); + u16 texel = in.ReadShort(); ret.push_back({Convert5To8(texel >> 11 & 0x1f), Convert6To8(texel >> 5 & 0x3f), Convert5To8(texel & 0x1f), 0xff}); } break; } case EPaletteType::RGB5A3: { for (int e = 0; e < numEntries; ++e) { - u16 texel = in.readUint16Big(); + u16 texel = in.ReadShort(); if (texel & 0x8000) { ret.push_back( {Convert5To8(texel >> 10 & 0x1f), Convert5To8(texel >> 5 & 0x1f), Convert5To8(texel & 0x1f), 0xff}); @@ -296,7 +296,7 @@ void CTexture::BuildC4FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 8; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); + in.Get(source.data(), source.size()); for (size_t x = 0; x < 8; ++x) { target[x] = palette[source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf]; } @@ -334,7 +334,7 @@ void CTexture::BuildC8FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); + in.Get(source.data(), source.size()); for (size_t x = 0; x < source.size(); ++x) { target[x] = palette[source[x]]; } @@ -375,7 +375,7 @@ void CTexture::BuildRGB565FromGCN(CInputStream& in, aurora::zstring_view label) for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; for (size_t x = 0; x < 4; ++x) { - const u16 texel = in.readUint16Big(); + const u16 texel = in.ReadShort(); target[x].r = Convert5To8(texel >> 11 & 0x1f); target[x].g = Convert6To8(texel >> 5 & 0x3f); target[x].b = Convert5To8(texel & 0x1f); @@ -414,7 +414,7 @@ void CTexture::BuildRGB5A3FromGCN(CInputStream& in, aurora::zstring_view label) for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; for (size_t x = 0; x < 4; ++x) { - const u16 texel = in.readUint16Big(); + const u16 texel = in.ReadShort(); if ((texel & 0x8000) != 0) { target[x].r = Convert5To8(texel >> 10 & 0x1f); target[x].g = Convert5To8(texel >> 5 & 0x1f); @@ -461,7 +461,7 @@ void CTexture::BuildRGBA8FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 4; ++y) { RGBA8* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), source.size()); + in.Get(source.data(), source.size()); for (size_t x = 0; x < 4; ++x) { if (c != 0) { target[x].g = source[x * 2]; @@ -505,7 +505,7 @@ void CTexture::BuildDXT1FromGCN(CInputStream& in, aurora::zstring_view label) { for (int y = 0; y < 2; ++y) { DXT1Block* target = targetMip + (baseY + y) * w + baseX; std::array source; - in.readBytesToBuf(source.data(), sizeof(source)); + in.Get(reinterpret_cast(source.data()), sizeof(source)); for (size_t x = 0; x < source.size(); ++x) { target[x].color1 = hecl::SBig(source[x].color1); target[x].color2 = hecl::SBig(source[x].color2); @@ -715,11 +715,11 @@ CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips) : x0_fmt(fmt), x4_w CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id) : m_textureInfo(inf) { std::unique_ptr owned = std::move(in); - athena::io::MemoryReader r(owned.get(), length); - x0_fmt = ETexelFormat(r.readUint32Big()); - x4_w = r.readUint16Big(); - x6_h = r.readUint16Big(); - x8_mips = r.readUint32Big(); + CMemoryInStream r(owned.get(), length, CMemoryInStream::EOwnerShip::NotOwned); + x0_fmt = ETexelFormat(r.ReadLong()); + x4_w = r.ReadShort(); + x6_h = r.ReadShort(); + x8_mips = r.ReadLong(); auto label = fmt::format(FMT_STRING("TXTR {:08X} ({})"), id.Value(), TextureFormatString(x0_fmt)); switch (x0_fmt) { diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.cpp b/Runtime/GuiSys/CAuiEnergyBarT01.cpp index e01285c93..d255a729b 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.cpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.cpp @@ -142,7 +142,7 @@ void CAuiEnergyBarT01::SetMaxEnergy(float maxEnergy) { std::shared_ptr CAuiEnergyBarT01::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - CAssetId tex = in.readUint32Big(); + CAssetId tex = in.ReadLong(); std::shared_ptr ret = std::make_shared(parms, sp, tex); ret->ParseBaseInfo(frame, in, parms); return ret; diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index 5c86d1bc7..43252d022 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -17,17 +17,17 @@ CAuiImagePane::CAuiImagePane(const CGuiWidgetParms& parms, CSimplePool* sp, CAss std::shared_ptr CAuiImagePane::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - in.readUint32Big(); - in.readUint32Big(); - in.readUint32Big(); - u32 coordCount = in.readUint32Big(); + in.ReadLong(); + in.ReadLong(); + in.ReadLong(); + u32 coordCount = in.ReadLong(); rstl::reserved_vector coords; for (u32 i = 0; i < coordCount; ++i) - coords.push_back(zeus::CVector3f::ReadBig(in)); - u32 uvCount = in.readUint32Big(); + coords.push_back(in.Get()); + u32 uvCount = in.ReadLong(); rstl::reserved_vector uvs; for (u32 i = 0; i < uvCount; ++i) - uvs.push_back(zeus::CVector2f::ReadBig(in)); + uvs.push_back(in.Get()); std::shared_ptr ret = std::make_shared(parms, sp, -1, -1, std::move(coords), std::move(uvs), true); ret->ParseBaseInfo(frame, in, parms); diff --git a/Runtime/GuiSys/CAuiMeter.cpp b/Runtime/GuiSys/CAuiMeter.cpp index 5addf96dd..68e4c08d8 100644 --- a/Runtime/GuiSys/CAuiMeter.cpp +++ b/Runtime/GuiSys/CAuiMeter.cpp @@ -89,10 +89,10 @@ bool CAuiMeter::AddWorkerWidget(CGuiWidget* worker) { std::shared_ptr CAuiMeter::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - in.readBool(); - bool noRoundUp = in.readBool(); - u32 maxCapacity = in.readUint32Big(); - u32 workerCount = in.readUint32Big(); + in.ReadBool(); + bool noRoundUp = in.ReadBool(); + u32 maxCapacity = in.ReadLong(); + u32 workerCount = in.ReadLong(); std::shared_ptr ret = std::make_shared(parms, noRoundUp, maxCapacity, workerCount); ret->ParseBaseInfo(frame, in, parms); return ret; diff --git a/Runtime/GuiSys/CGuiCamera.cpp b/Runtime/GuiSys/CGuiCamera.cpp index b5ade0c7f..b173456df 100644 --- a/Runtime/GuiSys/CGuiCamera.cpp +++ b/Runtime/GuiSys/CGuiCamera.cpp @@ -38,24 +38,24 @@ void CGuiCamera::Draw(const CGuiWidgetDrawParms& parms) { std::shared_ptr CGuiCamera::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - EProjection proj = EProjection(in.readUint32Big()); + EProjection proj = EProjection(in.ReadLong()); std::shared_ptr ret = {}; switch (proj) { case EProjection::Perspective: { - float fov = in.readFloatBig(); - float aspect = in.readFloatBig(); - float znear = in.readFloatBig(); - float zfar = in.readFloatBig(); + float fov = in.ReadFloat(); + float aspect = in.ReadFloat(); + float znear = in.ReadFloat(); + float zfar = in.ReadFloat(); ret = std::make_shared(parms, fov, aspect, znear, zfar); break; } case EProjection::Orthographic: { - float left = in.readFloatBig(); - float right = in.readFloatBig(); - float top = in.readFloatBig(); - float bottom = in.readFloatBig(); - float znear = in.readFloatBig(); - float zfar = in.readFloatBig(); + float left = in.ReadFloat(); + float right = in.ReadFloat(); + float top = in.ReadFloat(); + float bottom = in.ReadFloat(); + float znear = in.ReadFloat(); + float zfar = in.ReadFloat(); ret = std::make_shared(parms, left, right, top, bottom, znear, zfar); break; } diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index fb93c4887..ce3bf264e 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -164,11 +164,11 @@ void CGuiFrame::Initialize() { } void CGuiFrame::LoadWidgetsInGame(CInputStream& in, CSimplePool* sp) { - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x2c_widgets.reserve(count); for (u32 i = 0; i < count; ++i) { - DataSpec::DNAFourCC type; - type.read(in); + FourCC type; + in.Get(reinterpret_cast(&type), 4); std::shared_ptr widget = CGuiSys::CreateWidgetInGame(type.toUint32(), in, this, sp); switch (widget->GetWidgetTypeID().toUint32()) { case SBIG('CAMR'): @@ -263,10 +263,10 @@ void CGuiFrame::ResetMouseState() { } std::unique_ptr CGuiFrame::CreateFrame(CAssetId frmeId, CGuiSys& sys, CInputStream& in, CSimplePool* sp) { - in.readInt32Big(); - int a = in.readInt32Big(); - int b = in.readInt32Big(); - int c = in.readInt32Big(); + in.ReadLong(); + int a = in.ReadLong(); + int b = in.ReadLong(); + int c = in.ReadLong(); std::unique_ptr ret = std::make_unique(frmeId, sys, a, b, c, sp); ret->LoadWidgetsInGame(in, sp); diff --git a/Runtime/GuiSys/CGuiGroup.cpp b/Runtime/GuiSys/CGuiGroup.cpp index 105387c3d..ac8e31d8a 100644 --- a/Runtime/GuiSys/CGuiGroup.cpp +++ b/Runtime/GuiSys/CGuiGroup.cpp @@ -43,8 +43,8 @@ void CGuiGroup::OnActiveChange() { std::shared_ptr CGuiGroup::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - s16 defaultWorker = in.readInt16Big(); - bool b = in.readBool(); + s16 defaultWorker = in.ReadInt16(); + bool b = in.ReadBool(); std::shared_ptr ret = std::make_shared(parms, defaultWorker, b); ret->ParseBaseInfo(frame, in, parms); return ret; diff --git a/Runtime/GuiSys/CGuiLight.cpp b/Runtime/GuiSys/CGuiLight.cpp index c65166b55..d326f027e 100644 --- a/Runtime/GuiSys/CGuiLight.cpp +++ b/Runtime/GuiSys/CGuiLight.cpp @@ -50,19 +50,19 @@ void CGuiLight::SetIsVisible(bool vis) { std::shared_ptr CGuiLight::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - ELightType tp = ELightType(in.readUint32Big()); - float distC = in.readFloatBig(); - float distL = in.readFloatBig(); - float distQ = in.readFloatBig(); - float angC = in.readFloatBig(); - float angL = in.readFloatBig(); - float angQ = in.readFloatBig(); - u32 lightId = in.readUint32Big(); + ELightType tp = ELightType(in.ReadLong()); + float distC = in.ReadFloat(); + float distL = in.ReadFloat(); + float distQ = in.ReadFloat(); + float angC = in.ReadFloat(); + float angL = in.ReadFloat(); + float angQ = in.ReadFloat(); + u32 lightId = in.ReadLong(); std::shared_ptr ret = {}; switch (tp) { case ELightType::Spot: { - float cutoff = in.readFloatBig(); + float cutoff = in.ReadFloat(); CLight lt = CLight::BuildSpot(zeus::skZero3f, zeus::skZero3f, parms.x10_color, cutoff); lt.SetAttenuation(distC, distL, distQ); lt.SetAngleAttenuation(angC, angL, angQ); diff --git a/Runtime/GuiSys/CGuiModel.cpp b/Runtime/GuiSys/CGuiModel.cpp index a397356bf..a2b67640e 100644 --- a/Runtime/GuiSys/CGuiModel.cpp +++ b/Runtime/GuiSys/CGuiModel.cpp @@ -123,9 +123,9 @@ bool CGuiModel::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& std::shared_ptr CGuiModel::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - CAssetId model = in.readUint32Big(); - in.readUint32Big(); - u32 lightMask = in.readUint32Big(); + CAssetId model = in.Get(); + in.ReadLong(); + u32 lightMask = in.ReadLong(); std::shared_ptr ret = std::make_shared(parms, sp, model, lightMask, true); ret->ParseBaseInfo(frame, in, parms); diff --git a/Runtime/GuiSys/CGuiPane.cpp b/Runtime/GuiSys/CGuiPane.cpp index 09b683af7..446d78002 100644 --- a/Runtime/GuiSys/CGuiPane.cpp +++ b/Runtime/GuiSys/CGuiPane.cpp @@ -54,8 +54,8 @@ void CGuiPane::WriteData(COutputStream& out, bool flag) const {} std::shared_ptr CGuiPane::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - zeus::CVector2f dim = zeus::CVector2f::ReadBig(in); - zeus::CVector3f scaleCenter = zeus::CVector3f::ReadBig(in); + zeus::CVector2f dim = in.Get(); + zeus::CVector3f scaleCenter = in.Get(); std::shared_ptr ret = std::make_shared(parms, dim, scaleCenter); ret->ParseBaseInfo(frame, in, parms); return ret; diff --git a/Runtime/GuiSys/CGuiSliderGroup.cpp b/Runtime/GuiSys/CGuiSliderGroup.cpp index df7aef83c..048276848 100644 --- a/Runtime/GuiSys/CGuiSliderGroup.cpp +++ b/Runtime/GuiSys/CGuiSliderGroup.cpp @@ -158,10 +158,10 @@ CGuiWidget* CGuiSliderGroup::GetWorkerWidget(int id) const { std::shared_ptr CGuiSliderGroup::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - float min = in.readFloatBig(); - float max = in.readFloatBig(); - float cur = in.readFloatBig(); - float increment = in.readFloatBig(); + float min = in.ReadFloat(); + float max = in.ReadFloat(); + float cur = in.ReadFloat(); + float increment = in.ReadFloat(); std::shared_ptr ret = std::make_shared(parms, min, max, cur, increment); ret->ParseBaseInfo(frame, in, parms); diff --git a/Runtime/GuiSys/CGuiTableGroup.cpp b/Runtime/GuiSys/CGuiTableGroup.cpp index 671188df9..19a3e152d 100644 --- a/Runtime/GuiSys/CGuiTableGroup.cpp +++ b/Runtime/GuiSys/CGuiTableGroup.cpp @@ -207,21 +207,21 @@ void CGuiTableGroup::DoIncrement() { std::shared_ptr CGuiTableGroup::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - int elementCount = in.readInt16Big(); - in.readInt16Big(); - in.readUint32Big(); - int defaultSel = in.readInt16Big(); - in.readInt16Big(); - bool selectWraparound = in.readBool(); - in.readBool(); - in.readFloatBig(); - in.readFloatBig(); - in.readBool(); - in.readFloatBig(); - in.readInt16Big(); - in.readInt16Big(); - in.readInt16Big(); - in.readInt16Big(); + int elementCount = in.ReadInt16(); + in.ReadInt16(); + in.ReadLong(); + int defaultSel = in.ReadInt16(); + in.ReadInt16(); + bool selectWraparound = in.ReadBool(); + in.ReadBool(); + in.ReadFloat(); + in.ReadFloat(); + in.ReadBool(); + in.ReadFloat(); + in.ReadInt16(); + in.ReadInt16(); + in.ReadInt16(); + in.ReadInt16(); std::shared_ptr ret = std::make_shared(parms, elementCount, defaultSel, selectWraparound); ret->ParseBaseInfo(frame, in, parms); diff --git a/Runtime/GuiSys/CGuiTextPane.cpp b/Runtime/GuiSys/CGuiTextPane.cpp index 4a5c6ebaa..9667c6395 100644 --- a/Runtime/GuiSys/CGuiTextPane.cpp +++ b/Runtime/GuiSys/CGuiTextPane.cpp @@ -135,20 +135,18 @@ bool CGuiTextPane::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2 std::shared_ptr CGuiTextPane::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) { const CGuiWidgetParms parms = ReadWidgetHeader(frame, in); - const zeus::CVector2f dim = zeus::CVector2f::ReadBig(in); - const zeus::CVector3f vec = zeus::CVector3f::ReadBig(in); - const u32 fontId = in.readUint32Big(); - const bool wordWrap = in.readBool(); - const bool horizontal = in.readBool(); - const auto justification = EJustification(in.readUint32Big()); - const auto vJustification = EVerticalJustification(in.readUint32Big()); + const zeus::CVector2f dim = in.Get(); + const zeus::CVector3f vec = in.Get(); + const CAssetId fontId = in.Get(); + const bool wordWrap = in.ReadBool(); + const bool horizontal = in.ReadBool(); + const auto justification = EJustification(in.ReadLong()); + const auto vJustification = EVerticalJustification(in.ReadLong()); const CGuiTextProperties props(wordWrap, horizontal, justification, vJustification); - zeus::CColor fontCol; - fontCol.readRGBABig(in); - zeus::CColor outlineCol; - outlineCol.readRGBABig(in); - const int extentX = static_cast(in.readFloatBig()); - const int extentY = static_cast(in.readFloatBig()); + const zeus::CColor fontCol = in.Get(); + const zeus::CColor outlineCol = in.Get(); + const int extentX = static_cast(in.ReadFloat()); + const int extentY = static_cast(in.ReadFloat()); auto ret = std::make_shared(parms, sp, dim, vec, fontId, props, fontCol, outlineCol, extentX, extentY); ret->ParseBaseInfo(frame, in, parms); ret->InitializeBuffers(); diff --git a/Runtime/GuiSys/CGuiWidget.cpp b/Runtime/GuiSys/CGuiWidget.cpp index 775be6e3b..b13a9d33e 100644 --- a/Runtime/GuiSys/CGuiWidget.cpp +++ b/Runtime/GuiSys/CGuiWidget.cpp @@ -24,18 +24,17 @@ CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms) } CGuiWidget::CGuiWidgetParms CGuiWidget::ReadWidgetHeader(CGuiFrame* frame, CInputStream& in) { - std::string name = in.readString(-1); + std::string name = in.Get(); s16 selfId = frame->GetWidgetIdDB().AddWidget(name); - std::string parent = in.readString(-1); + std::string parent = in.Get(); s16 parentId = frame->GetWidgetIdDB().AddWidget(parent); - bool useAnimController = in.readBool(); - bool defaultVis = in.readBool(); - bool defaultActive = in.readBool(); - bool cullFaces = in.readBool(); - zeus::CColor color; - color.readRGBABig(in); - EGuiModelDrawFlags df = EGuiModelDrawFlags(in.readUint32Big()); + bool useAnimController = in.ReadBool(); + bool defaultVis = in.ReadBool(); + bool defaultActive = in.ReadBool(); + bool cullFaces = in.ReadBool(); + zeus::CColor color = in.Get(); + EGuiModelDrawFlags df = EGuiModelDrawFlags(in.ReadLong()); return CGuiWidget::CGuiWidgetParms(frame, useAnimController, selfId, parentId, defaultVis, defaultActive, cullFaces, color, df, true, false, std::move(name)); @@ -52,17 +51,17 @@ void CGuiWidget::Initialize() {} void CGuiWidget::ParseBaseInfo(CGuiFrame* frame, CInputStream& in, const CGuiWidgetParms& parms) { CGuiWidget* parent = frame->FindWidget(parms.x8_parentId); - bool isWorker = in.readBool(); + bool isWorker = in.ReadBool(); if (isWorker) - xb4_workerId = in.readInt16Big(); - zeus::CVector3f trans = zeus::CVector3f::ReadBig(in); - zeus::CMatrix3f orient = zeus::CMatrix3f::ReadBig(in); + xb4_workerId = in.ReadInt16(); + zeus::CVector3f trans = in.Get(); + zeus::CMatrix3f orient = in.Get(); x74_transform = zeus::CTransform(orient, trans); m_initTransform = x74_transform; ReapplyXform(); - (void)zeus::CVector3f::ReadBig(in); // Unused - in.readUint32Big(); - in.readUint16Big(); + in.Get(); // Unused + in.ReadLong(); + in.ReadShort(); if (isWorker) { if (!parent->AddWorkerWidget(this)) { Log.report(logvisor::Warning, diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index 53e1d46b4..e04114745 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -10,61 +10,61 @@ namespace metaforce { CRasterFont::CRasterFont(metaforce::CInputStream& in, metaforce::IObjectStore& store) { u32 magic = 0; - in.readBytesToBuf(&magic, 4); + in.Get(reinterpret_cast(&magic), 4); if (magic != SBIG('FONT')) return; - u32 version = in.readUint32Big(); - x4_monoWidth = in.readUint32Big(); - x8_monoHeight = in.readUint32Big(); + u32 version = in.ReadLong(); + x4_monoWidth = in.ReadLong(); + x8_monoHeight = in.ReadLong(); if (version >= 1) - x8c_baseline = in.readUint32Big(); + x8c_baseline = in.ReadLong(); else x8c_baseline = x8_monoHeight; if (version >= 2) - x90_lineMargin = in.readUint32Big(); + x90_lineMargin = in.ReadLong(); - bool tmp1 = in.readBool(); - bool tmp2 = in.readBool(); + bool tmp1 = in.ReadBool(); + bool tmp2 = in.ReadBool(); - u32 tmp3 = in.readUint32Big(); - u32 tmp4 = in.readUint32Big(); - std::string name = in.readString(); - u32 txtrId = (version == 5 ? in.readUint64Big() : in.readUint32Big()); + u32 tmp3 = in.ReadLong(); + u32 tmp4 = in.ReadLong(); + std::string name = in.Get(); + u32 txtrId = (version == 5 ? in.ReadLongLong() : in.ReadLong()); x30_fontInfo = CFontInfo(tmp1, tmp2, tmp3, tmp4, name.c_str()); x80_texture = store.GetObj({FOURCC('TXTR'), txtrId}); - x2c_mode = CTexture::EFontType(in.readUint32Big()); + x2c_mode = CTexture::EFontType(in.ReadLong()); - u32 glyphCount = in.readUint32Big(); + u32 glyphCount = in.ReadLong(); xc_glyphs.reserve(glyphCount); for (u32 i = 0; i < glyphCount; ++i) { - char16_t chr = in.readUint16Big(); - float startU = in.readFloatBig(); - float startV = in.readFloatBig(); - float endU = in.readFloatBig(); - float endV = in.readFloatBig(); + char16_t chr = in.ReadShort(); + float startU = in.ReadFloat(); + float startV = in.ReadFloat(); + float endU = in.ReadFloat(); + float endV = in.ReadFloat(); s32 layer = 0; s32 a, b, c, cellWidth, cellHeight, baseline, kernStart; if (version < 4) { - a = in.readInt32Big(); - b = in.readInt32Big(); - c = in.readInt32Big(); - cellWidth = in.readInt32Big(); - cellHeight = in.readInt32Big(); - baseline = in.readInt32Big(); - kernStart = in.readInt32Big(); + a = in.ReadInt32(); + b = in.ReadInt32(); + c = in.ReadInt32(); + cellWidth = in.ReadInt32(); + cellHeight = in.ReadInt32(); + baseline = in.ReadInt32(); + kernStart = in.ReadInt32(); } else { - layer = in.readByte(); - a = in.readByte(); - b = in.readByte(); - c = in.readByte(); - cellWidth = in.readByte(); - cellHeight = in.readByte(); - baseline = in.readByte(); - kernStart = in.readInt16Big(); + layer = in.ReadInt8(); + a = in.ReadInt8(); + b = in.ReadInt8(); + c = in.ReadInt8(); + cellWidth = in.ReadInt8(); + cellHeight = in.ReadInt8(); + baseline = in.ReadInt8(); + kernStart = in.ReadInt16(); } xc_glyphs.emplace_back( chr, CGlyph(a, b, c, startU, startV, endU, endV, cellWidth, cellHeight, baseline, kernStart, layer)); @@ -72,13 +72,13 @@ CRasterFont::CRasterFont(metaforce::CInputStream& in, metaforce::IObjectStore& s std::sort(xc_glyphs.begin(), xc_glyphs.end(), [=](auto& a, auto& b) -> bool { return a.first < b.first; }); - u32 kernCount = in.readUint32Big(); + u32 kernCount = in.ReadLong(); x1c_kerning.reserve(kernCount); for (u32 i = 0; i < kernCount; ++i) { - char16_t first = in.readUint16Big(); - char16_t second = in.readUint16Big(); - s32 howMuch = in.readInt32Big(); + char16_t first = in.ReadShort(); + char16_t second = in.ReadShort(); + s32 howMuch = in.ReadInt32(); x1c_kerning.emplace_back(first, second, howMuch); } diff --git a/Runtime/GuiSys/CStringTable.cpp b/Runtime/GuiSys/CStringTable.cpp index c35914d73..eacefba90 100644 --- a/Runtime/GuiSys/CStringTable.cpp +++ b/Runtime/GuiSys/CStringTable.cpp @@ -1,9 +1,11 @@ #include "Runtime/GuiSys/CStringTable.hpp" -#include - +#include "Runtime/CBasics.hpp" +#include "Runtime/CInputStream.hpp" #include "Runtime/CToken.hpp" +#include + namespace metaforce { namespace { constexpr std::array languages{ @@ -16,14 +18,15 @@ FourCC CStringTable::mCurrentLanguage = languages[0]; CStringTable::CStringTable(CInputStream& in) { LoadStringTable(in); } void CStringTable::LoadStringTable(CInputStream& in) { - in.readUint32Big(); - in.readUint32Big(); - u32 langCount = in.readUint32Big(); - x0_stringCount = in.readUint32Big(); + in.ReadLong(); + in.ReadLong(); + u32 langCount = in.ReadLong(); + x0_stringCount = in.ReadLong(); std::vector> langOffsets; for (u32 i = 0; i < langCount; ++i) { - FourCC fcc(in.readUint32()); - u32 off = in.readUint32Big(); + FourCC fcc; + in.Get(reinterpret_cast(&fcc), 4); + u32 off = in.ReadLong(); langOffsets.emplace_back(fcc, off); } @@ -45,21 +48,26 @@ void CStringTable::LoadStringTable(CInputStream& in) { if (offset == UINT32_MAX) offset = langOffsets[0].second; - in.seek(offset); + for (u32 i = 0; i < offset; ++i) { + in.ReadChar(); + } - u32 dataLen = in.readUint32Big(); + u32 dataLen = in.ReadLong(); m_bufLen = dataLen; x4_data.reset(new u8[dataLen]); - in.readUBytesToBuf(x4_data.get(), dataLen); + in.Get(x4_data.get(), dataLen); +#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ u32* off = reinterpret_cast(x4_data.get()); - for (u32 i = 0; i < x0_stringCount; ++i, ++off) - *off = SBig(*off); + for (u32 i = 0; i < x0_stringCount; ++i, ++off) { + *off = CBasics::SwapBytes(*off); + } for (u32 i = x0_stringCount * 4; i < dataLen; i += 2) { u16* chr = reinterpret_cast(x4_data.get() + i); - *chr = SBig(*chr); + *chr = CBasics::SwapBytes(*chr); } +#endif } const char16_t* CStringTable::GetString(s32 str) const { diff --git a/Runtime/GuiSys/CStringTable.hpp b/Runtime/GuiSys/CStringTable.hpp index d122958d3..d500270da 100644 --- a/Runtime/GuiSys/CStringTable.hpp +++ b/Runtime/GuiSys/CStringTable.hpp @@ -10,7 +10,7 @@ class CStringTable { static FourCC mCurrentLanguage; u32 x0_stringCount = 0; std::unique_ptr x4_data; - u32 m_bufLen; + u32 m_bufLen = 0; public: explicit CStringTable(CInputStream& in); diff --git a/Runtime/IOStreams.cpp b/Runtime/IOStreams.cpp index da890cd47..4ded1d7a4 100644 --- a/Runtime/IOStreams.cpp +++ b/Runtime/IOStreams.cpp @@ -1,140 +1,96 @@ #include "Runtime/IOStreams.hpp" -#include +#include namespace metaforce { - -#define DUMP_BITS 0 - -#if DUMP_BITS -static void PrintBinary(u32 val, u32 count) { - for (u32 i = 0; i < count; ++i) { - fmt::print(FMT_STRING("{}"), (val >> (count - i - 1)) & 0x1); - } +template <> +zeus::CVector2f cinput_stream_helper(CInputStream& in) { + zeus::CVector2f ret; + ret.x() = in.ReadFloat(); + ret.y() = in.ReadFloat(); + return ret; } -#endif - -/*! - * \brief CBitStreamReader::ReadBit - * Reads and decodes an encoded value from a bitstream. - * \param bitCount How many bits to read - * \return s32 The encoded value - */ -s32 CBitStreamReader::ReadEncoded(u32 bitCount) { -#if DUMP_BITS - const auto pos = position(); - const auto boff = x20_bitOffset; -#endif - - u32 ret = 0; - const s32 shiftAmt = x20_bitOffset - s32(bitCount); - if (shiftAmt < 0) { - /* OR in remaining bits of cached value */ - u32 mask = bitCount == 32 ? UINT32_MAX : ((1U << bitCount) - 1); - ret |= (x1c_val << u32(-shiftAmt)) & mask; - - /* Load in exact number of bytes remaining */ - auto loadDiv = std::div(-shiftAmt, 8); - if (loadDiv.rem) - ++loadDiv.quot; - readUBytesToBuf(reinterpret_cast(&x1c_val) + 4 - loadDiv.quot, loadDiv.quot); - x1c_val = hecl::SBig(x1c_val); - - /* New bit offset */ - x20_bitOffset = loadDiv.quot * 8 + shiftAmt; - - /* OR in next bits */ - mask = (1U << u32(-shiftAmt)) - 1; - ret |= (x1c_val >> x20_bitOffset) & mask; - } else { - /* OR in bits of cached value */ - const u32 mask = bitCount == 32 ? UINT32_MAX : ((1U << bitCount) - 1); - ret |= (x1c_val >> u32(shiftAmt)) & mask; - - /* New bit offset */ - x20_bitOffset -= bitCount; - } - -#if DUMP_BITS - std::fputs("READ ", stdout); - PrintBinary(ret, bitCount); - fmt::print(FMT_STRING(" {} {}\n"), pos, boff); -#endif - +template <> +zeus::CVector3f cinput_stream_helper(CInputStream& in) { + zeus::CVector3f ret; + ret.x() = in.ReadFloat(); + ret.y() = in.ReadFloat(); + ret.z() = in.ReadFloat(); + return ret; +} +template <> +zeus::CVector4f cinput_stream_helper(CInputStream& in) { + zeus::CVector4f ret; + ret.x() = in.ReadFloat(); + ret.y() = in.ReadFloat(); + ret.z() = in.ReadFloat(); + ret.w() = in.ReadFloat(); return ret; } -void CBitStreamWriter::WriteEncoded(u32 val, u32 bitCount) { -#if DUMP_BITS - std::fputs("WRITE ", stdout); - PrintBinary(val, bitCount); - fmt::print(FMT_STRING(" {} {}\n"), position(), x18_bitOffset); -#endif - - const s32 shiftAmt = x18_bitOffset - s32(bitCount); - if (shiftAmt < 0) { - /* OR remaining bits to cached value */ - const u32 mask = (1U << x18_bitOffset) - 1; - x14_val |= (val >> u32(-shiftAmt)) & mask; - - /* Write out 32-bits */ - x14_val = hecl::SBig(x14_val); - writeBytes(&x14_val, sizeof(x14_val)); - - /* Cache remaining bits */ - x18_bitOffset = 0x20 + shiftAmt; - x14_val = val << x18_bitOffset; - } else { - /* OR bits to cached value */ - const u32 mask = bitCount == 32 ? UINT32_MAX : ((1U << bitCount) - 1); - x14_val |= (val & mask) << u32(shiftAmt); - - /* New bit offset */ - x18_bitOffset -= bitCount; - } +template <> +zeus::CQuaternion cinput_stream_helper(CInputStream& in) { + zeus::CQuaternion ret; + ret.w() = in.ReadFloat(); + ret.x() = in.ReadFloat(); + ret.y() = in.ReadFloat(); + ret.z() = in.ReadFloat(); + return ret; } -void CBitStreamWriter::Flush() { - if (x18_bitOffset >= 0x20) { - return; - } - - auto pos = std::div(0x20 - s32(x18_bitOffset), 8); - if (pos.rem != 0) { - ++pos.quot; - } - - x14_val = hecl::SBig(x14_val); - writeBytes(&x14_val, pos.quot); - x18_bitOffset = 0x20; - x14_val = 0; +template <> +zeus::CAABox cinput_stream_helper(CInputStream& in) { + zeus::CAABox ret; + ret.min = in.Get(); + ret.max = in.Get(); + return ret; } -CZipInputStream::CZipInputStream(std::unique_ptr&& strm) -: x24_compBuf(new u8[4096]), x28_strm(std::move(strm)) { - x30_zstrm.next_in = x24_compBuf.get(); - x30_zstrm.avail_in = 0; - x30_zstrm.zalloc = [](void*, u32 c, u32 n) -> void* { return new u8[size_t{c} * size_t{n}]; }; - x30_zstrm.zfree = [](void*, void* buf) { delete[] static_cast(buf); }; - inflateInit(&x30_zstrm); + +template <> +zeus::COBBox cinput_stream_helper(CInputStream& in) { + zeus::COBBox ret; + ret.transform = in.Get(); + ret.extents = in.Get(); + return ret; +} +template <> +zeus::CColor cinput_stream_helper(CInputStream& in) { + zeus::CColor ret; + ret.r() = in.ReadFloat(); + ret.g() = in.ReadFloat(); + ret.b() = in.ReadFloat(); + ret.a() = in.ReadFloat(); + return ret; } -CZipInputStream::~CZipInputStream() { inflateEnd(&x30_zstrm); } - -atUint64 CZipInputStream::readUBytesToBuf(void* buf, atUint64 len) { - x30_zstrm.next_out = static_cast(buf); - x30_zstrm.avail_out = len; - x30_zstrm.total_out = 0; - while (x30_zstrm.avail_out != 0) { - if (x30_zstrm.avail_in == 0) { - atUint64 readSz = x28_strm->readUBytesToBuf(x24_compBuf.get(), 4096); - x30_zstrm.avail_in = readSz; - x30_zstrm.next_in = x24_compBuf.get(); - } - int inflateRet = inflate(&x30_zstrm, Z_NO_FLUSH); - if (inflateRet != Z_OK) - break; - } - return x30_zstrm.total_out; +template <> +zeus::CTransform cinput_stream_helper(CInputStream& in) { + zeus::CTransform ret; + auto r0 = in.Get(); + auto r1 = in.Get(); + auto r2 = in.Get(); + ret.basis = zeus::CMatrix3f(r0, r1, r2); + ret.basis.transpose(); + ret.origin = zeus::CVector3f(r0.w(), r1.w(), r2.w()); + return ret; } +template <> +zeus::CMatrix3f cinput_stream_helper(CInputStream& in) { + zeus::CMatrix3f ret; + ret.m[0] = in.Get(); + ret.m[1] = in.Get(); + ret.m[2] = in.Get(); + return ret.transposed(); +} + +template <> +zeus::CMatrix4f cinput_stream_helper(CInputStream& in) { + zeus::CMatrix4f ret; + ret.m[0] = in.Get(); + ret.m[1] = in.Get(); + ret.m[2] = in.Get(); + ret.m[3] = in.Get(); + return ret.transposed(); +} } // namespace metaforce diff --git a/Runtime/IOStreams.hpp b/Runtime/IOStreams.hpp index 6aef9d55c..3e079d211 100644 --- a/Runtime/IOStreams.hpp +++ b/Runtime/IOStreams.hpp @@ -1,74 +1,41 @@ #pragma once -#include - -#include "Runtime/GCNTypes.hpp" - -#include -#include -#include -#include -#ifdef URDE_ZIP_INPUT_STREAM -#include -#endif +#include "Runtime/CMemoryInStream.hpp" +#include "Runtime/CMemoryStreamOut.hpp" +#include "Runtime/CZipInputStream.hpp" +namespace zeus { +class CVector2f; +class CVector3f; +class CVector4f; +class CTransform; +class CMatrix3f; +class CMatrix4f; +class CAABox; +class COBBox; +class CQuaternion; +class CColor; +} namespace metaforce { -using CInputStream = athena::io::IStreamReader; -using COutputStream = athena::io::IStreamWriter; - -struct CBitStreamReader : athena::io::MemoryReader { - u32 x1c_val = 0; - u32 x20_bitOffset = 0; - -public: - static constexpr u32 GetBitCount(u32 maxVal) { - u32 ret = 0; - while (maxVal != 0) { - maxVal /= 2; - ret++; - } - - return ret; - } - - CBitStreamReader(const void* data, atUint64 length) : MemoryReader(data, length) {} - - s32 ReadEncoded(u32 key); -}; - -class CBitStreamWriter : public athena::io::MemoryWriter { - u32 x14_val = 0; - u32 x18_bitOffset = 0x20; - -public: - static constexpr u32 GetBitCount(u32 maxVal) { return CBitStreamReader::GetBitCount(maxVal); } - - explicit CBitStreamWriter(atUint8* data = nullptr, atUint64 length = 0x10) : MemoryWriter(data, length) {} - - void WriteEncoded(u32 val, u32 bitCount); - - void Flush(); - - ~CBitStreamWriter() override { Flush(); } -}; - -using CMemoryInStream = athena::io::MemoryReader; -using CMemoryOutStream = athena::io::MemoryWriter; - -#ifdef URDE_ZIP_INPUT_STREAM -class CZipInputStream : public CInputStream { - std::unique_ptr x24_compBuf; - std::unique_ptr x28_strm; - z_stream x30_zstrm = {}; - -public: - explicit CZipInputStream(std::unique_ptr&& strm); - ~CZipInputStream() override; - atUint64 readUBytesToBuf(void* buf, atUint64 len) override; - void seek(atInt64, athena::SeekOrigin) override {} - atUint64 position() const override { return 0; } - atUint64 length() const override { return 0; } -}; -#endif - -} // namespace metaforce +// Custom helpers for input/output +template <> +zeus::CVector2f cinput_stream_helper(CInputStream& in); +template <> +zeus::CVector3f cinput_stream_helper(CInputStream& in); +template <> +zeus::CVector4f cinput_stream_helper(CInputStream& in); +template <> +zeus::CQuaternion cinput_stream_helper(CInputStream& in); +template <> +zeus::CAABox cinput_stream_helper(CInputStream& in); +template <> +zeus::COBBox cinput_stream_helper(CInputStream& in); +template <> +zeus::CColor cinput_stream_helper(CInputStream& in); +template <> +zeus::CTransform cinput_stream_helper(CInputStream& in); +template <> +zeus::CMatrix3f cinput_stream_helper(CInputStream& in); +template <> +zeus::CMatrix4f cinput_stream_helper(CInputStream& in); +} \ No newline at end of file diff --git a/Runtime/MP1/CMemoryCardDriver.cpp b/Runtime/MP1/CMemoryCardDriver.cpp index eee2a05ea..203e0bddb 100644 --- a/Runtime/MP1/CMemoryCardDriver.cpp +++ b/Runtime/MP1/CMemoryCardDriver.cpp @@ -106,19 +106,19 @@ ECardResult CMemoryCardDriver::SFileInfo::GetSaveDataOffset(u32& offOut) const { CMemoryCardDriver::SGameFileSlot::SGameFileSlot() { InitializeFromGameState(); } CMemoryCardDriver::SGameFileSlot::SGameFileSlot(CMemoryInStream& in) { - in.readBytesToBuf(x0_saveBuffer.data(), x0_saveBuffer.size()); + in.ReadBytes(reinterpret_cast(x0_saveBuffer.data()), x0_saveBuffer.size()); x944_fileInfo = CGameState::LoadGameFileState(x0_saveBuffer.data()); } void CMemoryCardDriver::SGameFileSlot::InitializeFromGameState() { - CBitStreamWriter w(x0_saveBuffer.data(), x0_saveBuffer.size()); + CMemoryStreamOut w(x0_saveBuffer.data(), x0_saveBuffer.size()); g_GameState->PutTo(w); w.Flush(); x944_fileInfo = CGameState::LoadGameFileState(x0_saveBuffer.data()); } void CMemoryCardDriver::SGameFileSlot::LoadGameState(u32 idx) { - CBitStreamReader r(x0_saveBuffer.data(), x0_saveBuffer.size()); + CMemoryInStream r(x0_saveBuffer.data(), x0_saveBuffer.size(), CMemoryInStream::EOwnerShip::NotOwned); static_cast(g_Main)->StreamNewGameState(r, idx); } @@ -151,9 +151,9 @@ const CGameState::GameFileStateInfo* CMemoryCardDriver::GetGameFileStateInfo(int CMemoryCardDriver::SSaveHeader CMemoryCardDriver::LoadSaveHeader(CMemoryInStream& in) { SSaveHeader ret; - ret.x0_version = in.readUint32Big(); + ret.x0_version = in.ReadLong(); for (bool& present : ret.x4_savePresent) { - present = in.readBool(); + present = in.ReadBool(); } return ret; } @@ -174,7 +174,7 @@ void CMemoryCardDriver::ReadFinished() { x20_fileTime = stat.GetTime(); CMemoryInStream r(fileInfo.x34_saveData.data(), 3004); SSaveHeader header = LoadSaveHeader(r); - r.readBytesToBuf(x30_systemData.data(), x30_systemData.size()); + r.ReadBytes(reinterpret_cast(x30_systemData.data()), x30_systemData.size()); for (size_t i = 0; i < xe4_fileSlots.size(); ++i) { if (header.x4_savePresent[i]) { @@ -188,17 +188,17 @@ void CMemoryCardDriver::ReadFinished() { } void CMemoryCardDriver::ImportPersistentOptions() { - CBitStreamReader r(x30_systemData.data(), x30_systemData.size()); + CMemoryInStream r(x30_systemData.data(), x30_systemData.size(), CMemoryInStream::EOwnerShip::NotOwned); CPersistentOptions opts(r); g_GameState->ImportPersistentOptions(opts); } void CMemoryCardDriver::ExportPersistentOptions() { - CBitStreamReader r(x30_systemData.data(), x30_systemData.size()); + CMemoryInStream r(x30_systemData.data(), x30_systemData.size(), CMemoryInStream::EOwnerShip::NotOwned); CPersistentOptions opts(r); g_GameState->ExportPersistentOptions(opts); - CBitStreamWriter w(x30_systemData.data(), x30_systemData.size()); - opts.PutTo(w); + CMemoryStreamOut w(x30_systemData.data(), x30_systemData.size()); + w.Put(opts); } void CMemoryCardDriver::CheckCardCapacity() { @@ -645,7 +645,7 @@ void CMemoryCardDriver::BuildNewFileSlot(u32 saveIdx) { slot = std::make_unique(); slot->LoadGameState(saveIdx); - CBitStreamReader r(x30_systemData.data(), x30_systemData.size()); + CMemoryInStream r(x30_systemData.data(), x30_systemData.size()); g_GameState->ReadPersistentOptions(r); ImportPersistentOptions(); g_GameState->SetCardSerial(x28_cardSerial); @@ -663,7 +663,7 @@ void CMemoryCardDriver::BuildExistingFileSlot(u32 saveIdx) { else slot->InitializeFromGameState(); - CBitStreamWriter w(x30_systemData.data(), x30_systemData.size()); + CMemoryStreamOut w(x30_systemData.data(), x30_systemData.size()); g_GameState->PutTo(w); } @@ -680,7 +680,7 @@ void CMemoryCardDriver::InitializeFileInfo() { x198_fileInfo->LockBannerToken(x4_saveBanner, *g_SimplePool); x198_fileInfo->LockIconToken(x8_saveIcon0, kabufuda::EAnimationSpeed::Middle, *g_SimplePool); - CMemoryOutStream w = x198_fileInfo->BeginMemoryOut(3004); + CMemoryStreamOut w = x198_fileInfo->BeginMemoryOut(3004); SSaveHeader header; for (size_t i = 0; i < xe4_fileSlots.size(); ++i) { @@ -688,7 +688,7 @@ void CMemoryCardDriver::InitializeFileInfo() { } header.DoPut(w); - w.writeBytes(x30_systemData.data(), x30_systemData.size()); + w.Put(x30_systemData.data(), x30_systemData.size()); for (auto& fileSlot : xe4_fileSlots) { if (fileSlot) { diff --git a/Runtime/MP1/CMemoryCardDriver.hpp b/Runtime/MP1/CMemoryCardDriver.hpp index fec06aa25..c68ba45c9 100644 --- a/Runtime/MP1/CMemoryCardDriver.hpp +++ b/Runtime/MP1/CMemoryCardDriver.hpp @@ -90,10 +90,10 @@ private: u32 x0_version = 0; std::array x4_savePresent{}; - void DoPut(CMemoryOutStream& out) const { - out.writeUint32Big(x0_version); + void DoPut(CMemoryStreamOut& out) const { + out.WriteLong(x0_version); for (const bool savePresent : x4_savePresent) { - out.writeBool(savePresent); + out.Put(savePresent); } } }; @@ -106,7 +106,7 @@ private: explicit SGameFileSlot(CMemoryInStream& in); void InitializeFromGameState(); void LoadGameState(u32 idx); - void DoPut(CMemoryOutStream& w) const { w.writeBytes(x0_saveBuffer.data(), x0_saveBuffer.size()); } + void DoPut(CMemoryStreamOut& w) const { w.Put(x0_saveBuffer.data(), x0_saveBuffer.size()); } }; enum class EFileState { Unknown, NoFile, File, BadFile }; diff --git a/Runtime/MP1/CTweaks.cpp b/Runtime/MP1/CTweaks.cpp index d7767c3be..1bfdd8820 100644 --- a/Runtime/MP1/CTweaks.cpp +++ b/Runtime/MP1/CTweaks.cpp @@ -26,35 +26,41 @@ namespace metaforce::MP1 { static logvisor::Module Log("MP1::CTweaks"); void CTweaks::RegisterTweaks(hecl::CVarManager* cvarMgr) { +#if 0 // TODO: Migrate tweaks into metaforce std::optional strm; const SObjectTag* tag; /* Particle */ tag = g_ResFactory->GetResourceIdByName("Particle"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakParticle = new DataSpec::DNAMP1::CTweakParticle(*strm); g_tweakParticle->initCVars(cvarMgr); /* Player */ tag = g_ResFactory->GetResourceIdByName("Player"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakPlayer = new DataSpec::DNAMP1::CTweakPlayer(*strm); g_tweakPlayer->initCVars(cvarMgr); /* CameraBob */ tag = g_ResFactory->GetResourceIdByName("CameraBob"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); CPlayerCameraBob::ReadTweaks(*strm); /* Ball */ tag = g_ResFactory->GetResourceIdByName("Ball"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakBall = new DataSpec::DNAMP1::CTweakBall(*strm); g_tweakBall->initCVars(cvarMgr); /* PlayerGun */ tag = g_ResFactory->GetResourceIdByName("PlayerGun"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakPlayerGun = new DataSpec::DNAMP1::CTweakPlayerGun(*strm); g_tweakPlayerGun->initCVars(cvarMgr); @@ -73,59 +79,70 @@ void CTweaks::RegisterTweaks(hecl::CVarManager* cvarMgr) { /* Game */ tag = g_ResFactory->GetResourceIdByName("Game"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakGame = new DataSpec::DNAMP1::CTweakGame(*strm); g_tweakGame->initCVars(cvarMgr); /* GuiColors */ tag = g_ResFactory->GetResourceIdByName("GuiColors"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakGuiColors = new DataSpec::DNAMP1::CTweakGuiColors(*strm); g_tweakGuiColors->initCVars(cvarMgr); /* AutoMapper */ tag = g_ResFactory->GetResourceIdByName("AutoMapper"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakAutoMapper = new DataSpec::DNAMP1::CTweakAutoMapper(*strm); CMappableObject::ReadAutoMapperTweaks(*g_tweakAutoMapper); g_tweakAutoMapper->initCVars(cvarMgr); /* Gui */ tag = g_ResFactory->GetResourceIdByName("Gui"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakGui = new DataSpec::DNAMP1::CTweakGui(*strm); g_tweakPlayerGun->initCVars(cvarMgr); /* PlayerControls */ tag = g_ResFactory->GetResourceIdByName("PlayerControls"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakPlayerControl = new DataSpec::DNAMP1::CTweakPlayerControl(*strm); /* PlayerControls2 */ tag = g_ResFactory->GetResourceIdByName("PlayerControls2"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakPlayerControlAlt = new DataSpec::DNAMP1::CTweakPlayerControl(*strm); g_currentPlayerControl = g_tweakPlayerControl; /* SlideShow */ tag = g_ResFactory->GetResourceIdByName("SlideShow"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakSlideShow = new DataSpec::DNAMP1::CTweakSlideShow(*strm); g_tweakSlideShow->initCVars(cvarMgr); +#endif } void CTweaks::RegisterResourceTweaks(hecl::CVarManager* cvarMgr) { +#if 0 // TODO: Migrate tweaks into metaforce std::optional strm; const SObjectTag* tag = g_ResFactory->GetResourceIdByName("GunRes"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); g_tweakGunRes = new DataSpec::DNAMP1::CTweakGunRes(*strm); g_tweakGunRes->ResolveResources(*g_ResFactory); g_tweakGunRes->initCVars(cvarMgr); tag = g_ResFactory->GetResourceIdByName("PlayerRes"); - strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), true); + strm.emplace(g_ResFactory->LoadResourceSync(*tag).release(), g_ResFactory->ResourceSize(*tag), + CMemoryInStream::EOwnerShip::Owned); if (g_Main->IsTrilogy() || g_Main->IsPAL() || g_Main->IsJapanese()) { g_tweakPlayerRes = new DataSpec::DNAMP1::CTweakPlayerRes(*strm); } else { @@ -134,6 +151,7 @@ void CTweaks::RegisterResourceTweaks(hecl::CVarManager* cvarMgr) { g_tweakPlayerRes->ResolveResources(*g_ResFactory); g_tweakPlayerRes->initCVars(cvarMgr); +#endif } } // namespace metaforce::MP1 diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 8a4894d2b..6574b8499 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -452,7 +452,7 @@ void CMain::EnsureWorldPaksReady() {} void CMain::EnsureWorldPakReady(CAssetId mlvl) { /* TODO: Schedule resource list load for World Pak containing mlvl */ } -void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx) { +void CMain::StreamNewGameState(CInputStream& r, u32 idx) { bool fusionBackup = g_GameState->SystemOptions().GetPlayerFusionSuitActive(); x128_globalObjects->x134_gameState = std::make_unique(r, idx); g_GameState = x128_globalObjects->x134_gameState.get(); @@ -466,7 +466,7 @@ void CMain::RefreshGameState() { u64 cardSerial = g_GameState->GetCardSerial(); std::vector saveData = g_GameState->BackupBuf(); CGameOptions gameOpts = g_GameState->GameOptions(); - CBitStreamReader r(saveData.data(), saveData.size()); + CMemoryInStream r(saveData.data(), saveData.size(), CMemoryInStream::EOwnerShip::NotOwned); x128_globalObjects->StreamInGameState(r, g_GameState->GetFileIdx()); g_GameState->SetPersistentOptions(sysOpts); g_GameState->SetGameOptions(gameOpts); @@ -558,6 +558,7 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarMana m_cvarCommons = std::make_unique(*m_cvarMgr); bool loadedVersion = false; +#if 0 if (CDvdFile::FileExists("version.yaml")) { CDvdFile file("version.yaml"); if (file) { @@ -570,7 +571,9 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarMana MainLog.report(logvisor::Level::Info, FMT_STRING("Loaded version info")); } } - } else if (CDvdFile::FileExists("default.dol")) { + } else +#endif + if (CDvdFile::FileExists("default.dol")) { CDvdFile file("default.dol"); if (file) { std::unique_ptr buf = std::make_unique(file.Length()); diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 9edeb4ba9..3b88c403d 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -108,7 +108,7 @@ public: g_GameState = x134_gameState.get(); } - void StreamInGameState(CBitStreamReader& stream, u32 saveIdx) { + void StreamInGameState(CInputStream& stream, u32 saveIdx) { x134_gameState = std::make_unique(stream, saveIdx); g_GameState = x134_gameState.get(); } @@ -268,7 +268,7 @@ public: void AddWorldPaks(); void AddOverridePaks(); void ResetGameState(); - void StreamNewGameState(CBitStreamReader&, u32 idx); + void StreamNewGameState(CInputStream&, u32 idx); void RefreshGameState(); void CheckTweakManagerDebugOptions() {} void SetMFGameBuilt(bool b) { x160_25_mfGameBuilt = b; } diff --git a/Runtime/MP1/World/CBabygoth.cpp b/Runtime/MP1/World/CBabygoth.cpp index f8a8edef1..3595aa3a8 100644 --- a/Runtime/MP1/World/CBabygoth.cpp +++ b/Runtime/MP1/World/CBabygoth.cpp @@ -34,8 +34,8 @@ constexpr std::array skSphereJointList{{ }}; CBabygothData::CBabygothData(CInputStream& in) -: x0_fireballAttackTime(in.readFloatBig()) -, x4_fireballAttackTimeVariance(in.readFloatBig()) +: x0_fireballAttackTime(in.ReadFloat()) +, x4_fireballAttackTimeVariance(in.ReadFloat()) , x8_fireballWeapon(in) , xc_fireballDamage(in) , x28_attackContactDamage(in) @@ -46,20 +46,20 @@ CBabygothData::CBabygothData(CInputStream& in) , xd0_shellVulnerabilities(in) , x138_noShellModel(in) , x13c_noShellSkin(in) -, x140_shellHitPoints(in.readFloatBig()) -, x144_shellCrackSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x140_shellHitPoints(in.ReadFloat()) +, x144_shellCrackSfx(CSfxManager::TranslateSFXID(in.ReadLong())) , x148_intermediateCrackParticle(in) , x14c_crackOneParticle(in) , x150_crackTwoParticle(in) , x154_destroyShellParticle(in) -, x158_crackOneSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x15a_crackTwoSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x15c_destroyShellSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x160_timeUntilAttack(in.readFloatBig()) -, x164_attackCooldownTime(in.readFloatBig()) -, x168_interestTime(in.readFloatBig()) +, x158_crackOneSfx(CSfxManager::TranslateSFXID(in.ReadLong())) +, x15a_crackTwoSfx(CSfxManager::TranslateSFXID(in.ReadLong())) +, x15c_destroyShellSfx(CSfxManager::TranslateSFXID(in.ReadLong())) +, x160_timeUntilAttack(in.ReadFloat()) +, x164_attackCooldownTime(in.ReadFloat()) +, x168_interestTime(in.ReadFloat()) , x16c_flamePlayerSteamTxtr(in) -, x170_flamePlayerHitSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x170_flamePlayerHitSfx(CSfxManager::TranslateSFXID(in.ReadLong())) , x174_flamePlayerIceTxtr(in) {} CBabygoth::CBabygoth(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, diff --git a/Runtime/MP1/World/CBouncyGrenade.hpp b/Runtime/MP1/World/CBouncyGrenade.hpp index 0a4893ddd..73ca6e750 100644 --- a/Runtime/MP1/World/CBouncyGrenade.hpp +++ b/Runtime/MP1/World/CBouncyGrenade.hpp @@ -15,7 +15,7 @@ private: float x4_speed; public: - explicit SGrenadeVelocityInfo(CInputStream& in) : x0_mass(in.readFloatBig()), x4_speed(in.readFloatBig()) {} + explicit SGrenadeVelocityInfo(CInputStream& in) : x0_mass(in.ReadFloat()), x4_speed(in.ReadFloat()) {} [[nodiscard]] float GetMass() const { return x0_mass; } [[nodiscard]] float GetSpeed() const { return x4_speed; } diff --git a/Runtime/MP1/World/CChozoGhost.cpp b/Runtime/MP1/World/CChozoGhost.cpp index 26b6cc759..b611ee221 100644 --- a/Runtime/MP1/World/CChozoGhost.cpp +++ b/Runtime/MP1/World/CChozoGhost.cpp @@ -15,14 +15,14 @@ namespace metaforce::MP1 { CChozoGhost::CBehaveChance::CBehaveChance(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_lurk(in.readFloatBig()) -, x8_taunt(in.readFloatBig()) -, xc_attack(in.readFloatBig()) -, x10_move(in.readFloatBig()) -, x14_lurkTime(in.readFloatBig()) -, x18_chargeAttack(x0_propertyCount < 6 ? 0.5f : in.readFloatBig() * .01f) -, x1c_numBolts(x0_propertyCount < 7 ? 2 : in.readUint32Big()) { +: x0_propertyCount(in.ReadLong()) +, x4_lurk(in.ReadFloat()) +, x8_taunt(in.ReadFloat()) +, xc_attack(in.ReadFloat()) +, x10_move(in.ReadFloat()) +, x14_lurkTime(in.ReadFloat()) +, x18_chargeAttack(x0_propertyCount < 6 ? 0.5f : in.ReadFloat() * .01f) +, x1c_numBolts(x0_propertyCount < 7 ? 2 : in.ReadLong()) { float f2 = 1.f / (x10_move + xc_attack + x4_lurk + x8_taunt); x4_lurk *= f2; x8_taunt *= f2; diff --git a/Runtime/MP1/World/CElitePirate.cpp b/Runtime/MP1/World/CElitePirate.cpp index 98fde2c44..d0849ccc2 100644 --- a/Runtime/MP1/World/CElitePirate.cpp +++ b/Runtime/MP1/World/CElitePirate.cpp @@ -60,38 +60,38 @@ bool IsArmClawCollider(TUniqueId uid, const rstl::reserved_vector& } // Anonymous namespace CElitePirateData::CElitePirateData(CInputStream& in, u32 propCount) -: x0_tauntInterval(in.readFloatBig()) -, x4_tauntVariance(in.readFloatBig()) -, x8_(in.readFloatBig()) -, xc_(in.readFloatBig()) -, x10_attackChance(in.readFloatBig()) -, x14_shotAtTime(in.readFloatBig()) -, x18_shotAtTimeVariance(in.readFloatBig()) -, x1c_projectileAttractionRadius(in.readFloatBig()) +: x0_tauntInterval(in.ReadFloat()) +, x4_tauntVariance(in.ReadFloat()) +, x8_(in.ReadFloat()) +, xc_(in.ReadFloat()) +, x10_attackChance(in.ReadFloat()) +, x14_shotAtTime(in.ReadFloat()) +, x18_shotAtTimeVariance(in.ReadFloat()) +, x1c_projectileAttractionRadius(in.ReadFloat()) , x20_energyAbsorbParticleDescId(in) -, x24_energyAbsorbSfxId(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x24_energyAbsorbSfxId(CSfxManager::TranslateSFXID(in.ReadLong())) , x28_launcherActParams(ScriptLoader::LoadActorParameters(in)) , x90_launcherAnimParams(ScriptLoader::LoadAnimationParameters(in)) , x9c_launcherParticleGenDescId(in) -, xa0_launcherSfxId(CSfxManager::TranslateSFXID(in.readUint32Big())) +, xa0_launcherSfxId(CSfxManager::TranslateSFXID(in.ReadLong())) , xa4_grenadeModelId(in) , xa8_grenadeDamageInfo(in) -, xc4_launcherHp(in.readFloatBig()) +, xc4_launcherHp(in.ReadFloat()) , xc8_grenadeElementGenDescId1(in) , xcc_grenadeElementGenDescId2(in) , xd0_grenadeElementGenDescId3(in) , xd4_grenadeElementGenDescId4(in) , xd8_grenadeVelocityInfo(in) , xe0_grenadeTrajectoryInfo(in) -, xf0_grenadeNumBounces(in.readUint32Big()) -, xf4_grenadeBounceSfxId(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xf6_grenadeExplodeSfxId(CSfxManager::TranslateSFXID(in.readUint32Big())) +, xf0_grenadeNumBounces(in.ReadLong()) +, xf4_grenadeBounceSfxId(CSfxManager::TranslateSFXID(in.ReadLong())) +, xf6_grenadeExplodeSfxId(CSfxManager::TranslateSFXID(in.ReadLong())) , xf8_shockwaveParticleDescId(in) , xfc_shockwaveDamageInfo(in) , x118_shockwaveWeaponDescId(in) -, x11c_shockwaveElectrocuteSfxId(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x11e_canCallForBackup(in.readBool()) -, x11f_fastWhenAttractingEnergy(propCount < 42 ? true : in.readBool()) {} +, x11c_shockwaveElectrocuteSfxId(CSfxManager::TranslateSFXID(in.ReadLong())) +, x11e_canCallForBackup(in.ReadBool()) +, x11f_fastWhenAttractingEnergy(propCount < 42 ? true : in.ReadBool()) {} CElitePirate::CElitePirate(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& actParms, diff --git a/Runtime/MP1/World/CFlaahgra.cpp b/Runtime/MP1/World/CFlaahgra.cpp index 2ec9fd1c7..63c65963d 100644 --- a/Runtime/MP1/World/CFlaahgra.cpp +++ b/Runtime/MP1/World/CFlaahgra.cpp @@ -45,10 +45,10 @@ constexpr std::array skSphereJointList{{ }}; CFlaahgraData::CFlaahgraData(CInputStream& in) -: x0_(in.readFloatBig()) -, x4_(in.readFloatBig()) -, x8_(in.readFloatBig()) -, xc_faintDuration(in.readFloatBig()) +: x0_(in.ReadFloat()) +, x4_(in.ReadFloat()) +, x8_(in.ReadFloat()) +, xc_faintDuration(in.ReadFloat()) , x10_(in) , x78_(in) , x7c_(in) @@ -57,9 +57,9 @@ CFlaahgraData::CFlaahgraData(CInputStream& in) , xb8_plantsParticleGenDescId(in) , xbc_(in) , xd8_(ScriptLoader::LoadActorParameters(in)) -, x140_(in.readFloatBig()) -, x144_(in.readFloatBig()) -, x148_(in.readFloatBig()) +, x140_(in.ReadFloat()) +, x144_(in.ReadFloat()) +, x148_(in.ReadFloat()) , x14c_animationParameters(ScriptLoader::LoadAnimationParameters(in)) , x158_(in) {} diff --git a/Runtime/MP1/World/CFlyingPirate.cpp b/Runtime/MP1/World/CFlyingPirate.cpp index 4842f2411..ba90fc9b2 100644 --- a/Runtime/MP1/World/CFlyingPirate.cpp +++ b/Runtime/MP1/World/CFlyingPirate.cpp @@ -74,34 +74,34 @@ constexpr std::array skRadii{ } // namespace CFlyingPirate::CFlyingPirateData::CFlyingPirateData(CInputStream& in, u32 propCount) -: x0_maxCoverDistance(in.readFloatBig()) -, x4_hearingDistance(in.readFloatBig()) -, x8_type(EFlyingPirateType(in.readUint32Big())) +: x0_maxCoverDistance(in.ReadFloat()) +, x4_hearingDistance(in.ReadFloat()) +, x8_type(EFlyingPirateType(in.ReadLong())) , xc_gunProjectileInfo(in) -, x34_gunSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x34_gunSfx(CSfxManager::TranslateSFXID(in.ReadLong())) , x38_altProjectileInfo1(in) , x60_altProjectileInfo2(CAssetId(in), {}) -, x88_knockBackDelay(in.readFloatBig()) -, x8c_flyingHeight(in.readFloatBig()) +, x88_knockBackDelay(in.ReadFloat()) +, x8c_flyingHeight(in.ReadFloat()) , x90_particleGenDesc(g_SimplePool->GetObj({SBIG('PART'), CAssetId(in)})) , x9c_dInfo(in) -, xb8_(in.readFloatBig()) -, xbc_(in.readFloatBig()) -, xc0_(in.readFloatBig()) -, xc4_(in.readFloatBig()) -, xc8_ragDollSfx1(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xca_ragDollSfx2(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xcc_coverCheckChance(in.readFloatBig()) -, xd0_(in.readFloatBig()) -, xd4_(in.readFloatBig()) +, xb8_(in.ReadFloat()) +, xbc_(in.ReadFloat()) +, xc0_(in.ReadFloat()) +, xc4_(in.ReadFloat()) +, xc8_ragDollSfx1(CSfxManager::TranslateSFXID(in.ReadLong())) +, xca_ragDollSfx2(CSfxManager::TranslateSFXID(in.ReadLong())) +, xcc_coverCheckChance(in.ReadFloat()) +, xd0_(in.ReadFloat()) +, xd4_(in.ReadFloat()) , xd8_particleGen1(in) , xdc_particleGen2(in) , xe0_particleGen3(in) -, xe4_knockBackSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xe6_deathSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xe8_aggressionChance(in.readFloatBig()) -, xec_(in.readFloatBig()) -, xf0_projectileHomingDistance(propCount < 36 ? 0.f : in.readFloatBig()) { +, xe4_knockBackSfx(CSfxManager::TranslateSFXID(in.ReadLong())) +, xe6_deathSfx(CSfxManager::TranslateSFXID(in.ReadLong())) +, xe8_aggressionChance(in.ReadFloat()) +, xec_(in.ReadFloat()) +, xf0_projectileHomingDistance(propCount < 36 ? 0.f : in.ReadFloat()) { xc_gunProjectileInfo.Token().Lock(); x38_altProjectileInfo1.Token().Lock(); x60_altProjectileInfo2.Token().Lock(); diff --git a/Runtime/MP1/World/CGrenadeLauncher.hpp b/Runtime/MP1/World/CGrenadeLauncher.hpp index f3dc57e69..ed0e9050e 100644 --- a/Runtime/MP1/World/CGrenadeLauncher.hpp +++ b/Runtime/MP1/World/CGrenadeLauncher.hpp @@ -29,10 +29,10 @@ private: public: explicit SGrenadeTrajectoryInfo(CInputStream& in) - : x0_velocityMin(in.readFloatBig()) - , x4_velocityMax(in.readFloatBig()) - , x8_angleMin(zeus::degToRad(in.readFloatBig())) - , xc_angleMax(zeus::degToRad(in.readFloatBig())) {} + : x0_velocityMin(in.ReadFloat()) + , x4_velocityMax(in.ReadFloat()) + , x8_angleMin(zeus::degToRad(in.ReadFloat())) + , xc_angleMax(zeus::degToRad(in.ReadFloat())) {} [[nodiscard]] float GetVelocityMin() const { return x0_velocityMin; } [[nodiscard]] float GetVelocityMax() const { return x4_velocityMax; } diff --git a/Runtime/MP1/World/CIceSheegoth.cpp b/Runtime/MP1/World/CIceSheegoth.cpp index df5da2bee..bfebf602c 100644 --- a/Runtime/MP1/World/CIceSheegoth.cpp +++ b/Runtime/MP1/World/CIceSheegoth.cpp @@ -46,17 +46,17 @@ constexpr std::array skRightLegJointList = {{ } // namespace CIceSheegothData::CIceSheegothData(CInputStream& in, [[maybe_unused]] s32 propertyCount) -: x0_(zeus::degToRad(in.readFloatBig())) -, x4_(zeus::degToRad(in.readFloatBig())) -, x8_(zeus::CVector3f::ReadBig(in)) -, x14_(in.readFloatBig()) +: x0_(zeus::degToRad(in.ReadFloat())) +, x4_(zeus::degToRad(in.ReadFloat())) +, x8_(in.Get()) +, x14_(in.ReadFloat()) , x18_(in) , x80_(in) , xe8_(in) , x150_(in) , x154_(in) -, x170_(in.readFloatBig()) -, x174_(in.readFloatBig()) +, x170_(in.ReadFloat()) +, x174_(in.ReadFloat()) , x178_(in) , x17c_fireBreathResId(in) , x180_fireBreathDamage(in) @@ -65,18 +65,18 @@ CIceSheegothData::CIceSheegothData(CInputStream& in, [[maybe_unused]] s32 proper , x1a4_(in) , x1a8_(in) , x1ac_(in) -, x1b0_(in.readFloatBig()) -, x1b4_(in.readFloatBig()) +, x1b0_(in.ReadFloat()) +, x1b4_(in.ReadFloat()) , x1b8_(in) -, x1d4_(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x1d8_(in.readFloatBig()) -, x1dc_(in.readFloatBig()) -, x1e0_maxInterestTime(in.readFloatBig()) +, x1d4_(CSfxManager::TranslateSFXID(in.ReadLong())) +, x1d8_(in.ReadFloat()) +, x1dc_(in.ReadFloat()) +, x1e0_maxInterestTime(in.ReadFloat()) , x1e4_(in) -, x1e8_(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x1e8_(CSfxManager::TranslateSFXID(in.ReadLong())) , x1ec_(in) -, x1f0_24_(in.readBool()) -, x1f0_25_(in.readBool()) {} +, x1f0_24_(in.ReadBool()) +, x1f0_25_(in.ReadBool()) {} CIceSheegoth::CIceSheegoth(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& actParms, diff --git a/Runtime/MP1/World/CMetroid.cpp b/Runtime/MP1/World/CMetroid.cpp index 2ef82e5ca..d5705d041 100644 --- a/Runtime/MP1/World/CMetroid.cpp +++ b/Runtime/MP1/World/CMetroid.cpp @@ -61,17 +61,17 @@ constexpr std::array skJointNameList = { CMetroidData::CMetroidData(CInputStream& in) : x0_frozenVulnerability(in) , x68_energyDrainVulnerability(in) -, xd0_energyDrainPerSec(in.readFloatBig()) -, xd4_maxEnergyDrainAllowed(in.readFloatBig()) -, xd8_telegraphAttackTime(in.readFloatBig()) -, xdc_stage2GrowthScale(in.readFloatBig()) -, xe0_stage2GrowthEnergy(in.readFloatBig()) -, xe4_explosionGrowthEnergy(in.readFloatBig()) { +, xd0_energyDrainPerSec(in.ReadFloat()) +, xd4_maxEnergyDrainAllowed(in.ReadFloat()) +, xd8_telegraphAttackTime(in.ReadFloat()) +, xdc_stage2GrowthScale(in.ReadFloat()) +, xe0_stage2GrowthEnergy(in.ReadFloat()) +, xe4_explosionGrowthEnergy(in.ReadFloat()) { xe8_animParms1 = ScriptLoader::LoadAnimationParameters(in); xf8_animParms2 = ScriptLoader::LoadAnimationParameters(in); x108_animParms3 = ScriptLoader::LoadAnimationParameters(in); x118_animParms4 = ScriptLoader::LoadAnimationParameters(in); - x128_24_startsInWall = in.readBool(); + x128_24_startsInWall = in.ReadBool(); } CMetroid::CMetroid(TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info, diff --git a/Runtime/MP1/World/CMetroidBeta.cpp b/Runtime/MP1/World/CMetroidBeta.cpp index 2a6425daa..bd9a3a7de 100644 --- a/Runtime/MP1/World/CMetroidBeta.cpp +++ b/Runtime/MP1/World/CMetroidBeta.cpp @@ -20,21 +20,21 @@ namespace metaforce::MP1 { CMetroidBetaData::CMetroidBetaData(CInputStream& in) : x0_(in) , x68_(in) -, xd0_(in.readFloatBig()) -, xd4_(in.readFloatBig()) -, xd8_(in.readFloatBig()) -, xdc_(in.readFloatBig()) -, xe0_(in.readFloatBig()) -, xe4_(in.readFloatBig()) -, xe8_(in.readFloatBig()) -, xec_(in.readFloatBig()) -, xf0_(in.readFloatBig()) +, xd0_(in.ReadFloat()) +, xd4_(in.ReadFloat()) +, xd8_(in.ReadFloat()) +, xdc_(in.ReadFloat()) +, xe0_(in.ReadFloat()) +, xe4_(in.ReadFloat()) +, xe8_(in.ReadFloat()) +, xec_(in.ReadFloat()) +, xf0_(in.ReadFloat()) , xf4_(in) , xf8_(in) , xfc_(in) , x100_(in) , x104_(in) -, x108_24_(in.readBool()) {} +, x108_24_(in.ReadBool()) {} CMetroidBeta::CMetroidBeta(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, const CActorParameters& aParms, diff --git a/Runtime/MP1/World/CMetroidPrimeExo.cpp b/Runtime/MP1/World/CMetroidPrimeExo.cpp index 4d4da58a5..bab65f4c0 100644 --- a/Runtime/MP1/World/CMetroidPrimeExo.cpp +++ b/Runtime/MP1/World/CMetroidPrimeExo.cpp @@ -144,29 +144,29 @@ std::array, 14> skSomeValues2{{ }}; } // namespace SPrimeStruct2B::SPrimeStruct2B(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_particle1(in.readUint32Big()) -, x8_particle2(in.readUint32Big()) -, xc_particle3(in.readUint32Big()) +: x0_propertyCount(in.ReadLong()) +, x4_particle1(in.ReadLong()) +, x8_particle2(in.ReadLong()) +, xc_particle3(in.ReadLong()) , x10_dInfo(in) -, x2c_(in.readFloatBig()) -, x30_(in.readFloatBig()) -, x34_texture(in.readUint32Big()) -, x38_(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x3a_(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) {} +, x2c_(in.ReadFloat()) +, x30_(in.ReadFloat()) +, x34_texture(in.ReadLong()) +, x38_(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x3a_(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) {} SPrimeStruct4::SPrimeStruct4(CInputStream& in) : x0_beamInfo(in) -, x44_(in.readUint32Big()) +, x44_(in.ReadLong()) , x48_dInfo1(in) , x64_struct5(CPlasmaProjectile::LoadPlayerEffectResources(in)) -, x88_(in.readFloatBig()) +, x88_(in.ReadFloat()) , x8c_dInfo2(in) {} SPrimeStruct6::SPrimeStruct6(CInputStream& in) -: x0_propertyCount(in.readUint32Big()), x4_damageVulnerability(in), x6c_color(zeus::CColor::ReadRGBABig(in)) { - x70_[0] = in.readUint32Big(); - x70_[1] = in.readUint32Big(); +: x0_propertyCount(in.ReadLong()), x4_damageVulnerability(in), x6c_color(in.Get()) { + x70_[0] = in.ReadLong(); + x70_[1] = in.ReadLong(); } static CPatternedInfo LoadPatternedInfo(CInputStream& in) { @@ -185,12 +185,15 @@ static CCameraShakerComponent BuildCameraShakerComponent(CameraShakeData::Camera } static CCameraShakeData LoadCameraShakeData(CInputStream& in) { +#if 0 CameraShakeData shakeData; shakeData.read(in); return CCameraShakeData(shakeData.duration, shakeData.sfxDist, u32(shakeData.useSfx), zeus::skZero3f, BuildCameraShakerComponent(shakeData.shakerComponents[0]), BuildCameraShakerComponent(shakeData.shakerComponents[1]), BuildCameraShakerComponent(shakeData.shakerComponents[2])); +#endif + return {}; } static rstl::reserved_vector LoadPrimeStruct4s(CInputStream& in) { @@ -209,35 +212,35 @@ static rstl::reserved_vector LoadPrimeStruct6s(CInputStream& i } SPrimeExoParameters::SPrimeExoParameters(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) +: x0_propertyCount(in.ReadLong()) , x4_patternedInfo(LoadPatternedInfo(in)) , x13c_actorParms(ScriptLoader::LoadActorParameters(in)) -, x1a4_(in.readUint32Big()) +, x1a4_(in.ReadLong()) , x1a8_(LoadCameraShakeData(in)) , x27c_(LoadCameraShakeData(in)) , x350_(LoadCameraShakeData(in)) , x424_(in) -, x460_particle1(in.readUint32Big()) +, x460_particle1(in.ReadLong()) , x464_(LoadPrimeStruct4s(in)) -, x708_wpsc1(in.readUint32Big()) +, x708_wpsc1(in.ReadLong()) , x70c_dInfo1(in) , x728_shakeData1(LoadCameraShakeData(in)) -, x7fc_wpsc2(in.readUint32Big()) +, x7fc_wpsc2(in.ReadLong()) , x800_dInfo2(in) , x81c_shakeData2(LoadCameraShakeData(in)) , x8f0_(in) , x92c_(in) , x948_(LoadCameraShakeData(in)) -, xa1c_particle2(in.readUint32Big()) -, xa20_swoosh(in.readUint32Big()) -, xa24_particle3(in.readUint32Big()) -, xa28_particle4(in.readUint32Big()) +, xa1c_particle2(in.ReadLong()) +, xa20_swoosh(in.ReadLong()) +, xa24_particle3(in.ReadLong()) +, xa28_particle4(in.ReadLong()) , xa2c_(LoadPrimeStruct6s(in)) {} SPrimeExoRoomParameters::SPrimeExoRoomParameters(CInputStream& in) { - u32 propCount = std::min(u32(14), in.readUint32Big()); + u32 propCount = std::min(14, in.ReadLong()); for (u32 i = 0; i < propCount; ++i) { - x0_.push_back(in.readFloatBig()); + x0_.push_back(in.ReadFloat()); } } diff --git a/Runtime/MP1/World/CMetroidPrimeProjectile.cpp b/Runtime/MP1/World/CMetroidPrimeProjectile.cpp index 6c7b1bf8d..23ab8512a 100644 --- a/Runtime/MP1/World/CMetroidPrimeProjectile.cpp +++ b/Runtime/MP1/World/CMetroidPrimeProjectile.cpp @@ -6,17 +6,17 @@ namespace metaforce::MP1 { SPrimeProjectileInfo::SPrimeProjectileInfo(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_particle(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), in.readUint32Big()})) +: x0_propertyCount(in.ReadLong()) +, x4_particle(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), in.ReadLong()})) , xc_dInfo(in) -, x28_(in.readFloatBig()) -, x2c_(in.readFloatBig()) -, x30_(in.readFloatBig()) -, x34_texture(in.readUint32Big()) { - x38_24_ = in.readBool(); - x38_25_ = in.readBool(); - x38_26_ = in.readBool(); - x38_27_ = in.readBool(); +, x28_(in.ReadFloat()) +, x2c_(in.ReadFloat()) +, x30_(in.ReadFloat()) +, x34_texture(in.ReadLong()) { + x38_24_ = in.ReadBool(); + x38_25_ = in.ReadBool(); + x38_26_ = in.ReadBool(); + x38_27_ = in.ReadBool(); } CMetroidPrimeProjectile::CMetroidPrimeProjectile(bool active, const TToken& desc, EWeaponType type, diff --git a/Runtime/MP1/World/CRidley.cpp b/Runtime/MP1/World/CRidley.cpp index 5114a3ab0..09f8f1ddd 100644 --- a/Runtime/MP1/World/CRidley.cpp +++ b/Runtime/MP1/World/CRidley.cpp @@ -208,34 +208,34 @@ CRidleyData::CRidleyData(CInputStream& in, u32 propCount) , x28_(in) , x2c_(in) , x30_(in) -, x34_(in.readFloatBig()) -, x38_(in.readFloatBig()) -, x3c_(in.readFloatBig()) -, x40_(in.readFloatBig()) +, x34_(in.ReadFloat()) +, x38_(in.ReadFloat()) +, x3c_(in.ReadFloat()) +, x40_(in.ReadFloat()) , x44_(in) , x48_(in) , x64_(in) -, xa8_(CSfxManager::TranslateSFXID(in.readUint32Big())) +, xa8_(CSfxManager::TranslateSFXID(in.ReadLong())) , xac_(in) , xb0_(in) , xcc_(in) , x1a0_(in) , x1a4_(in) , x1c0_(in) -, x294_(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x294_(CSfxManager::TranslateSFXID(in.ReadLong())) , x298_(in) , x2b4_(in) -, x388_(in.readFloatBig()) -, x38c_(in.readFloatBig()) +, x388_(in.ReadFloat()) +, x38c_(in.ReadFloat()) , x390_(in) -, x3ac_(in.readFloatBig()) +, x3ac_(in.ReadFloat()) , x3b0_(in) -, x3cc_(in.readFloatBig()) +, x3cc_(in.ReadFloat()) , x3d0_(in) -, x3ec_(in.readFloatBig()) +, x3ec_(in.ReadFloat()) , x3f0_(in) -, x3f4_(in.readFloatBig()) -, x3f8_(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x3f4_(in.ReadFloat()) +, x3f8_(CSfxManager::TranslateSFXID(in.ReadLong())) , x3fc_(propCount > 47 ? CDamageInfo(in) : x48_) {} CRidley::CRidley(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, diff --git a/Runtime/MP1/World/CSpacePirate.cpp b/Runtime/MP1/World/CSpacePirate.cpp index 24467e064..413c4c1aa 100644 --- a/Runtime/MP1/World/CSpacePirate.cpp +++ b/Runtime/MP1/World/CSpacePirate.cpp @@ -152,34 +152,34 @@ std::list mChargePlayerList; } // Anonymous namespace CSpacePirate::CSpacePirateData::CSpacePirateData(metaforce::CInputStream& in, u32 propCount) -: x0_AggressionCheck(in.readFloatBig()) -, x4_CoverCheck(in.readFloatBig()) -, x8_SearchRadius(in.readFloatBig()) -, xc_FallBackCheck(in.readFloatBig()) -, x10_FallBackRadius(in.readFloatBig()) -, x14_HearingRadius(in.readFloatBig()) -, x18_flags(in.readUint32Big()) -, x1c_(in.readBool()) +: x0_AggressionCheck(in.ReadFloat()) +, x4_CoverCheck(in.ReadFloat()) +, x8_SearchRadius(in.ReadFloat()) +, xc_FallBackCheck(in.ReadFloat()) +, x10_FallBackRadius(in.ReadFloat()) +, x14_HearingRadius(in.ReadFloat()) +, x18_flags(in.ReadLong()) +, x1c_(in.ReadBool()) , x20_Projectile(in) -, x48_Sound_Projectile(CSfxManager::TranslateSFXID(in.readUint32Big())) +, x48_Sound_Projectile(CSfxManager::TranslateSFXID(in.ReadLong())) , x4c_BladeDamage(in) -, x68_KneelAttackChance(in.readFloatBig()) +, x68_KneelAttackChance(in.ReadFloat()) , x6c_KneelAttackShot(in) -, x94_DodgeCheck(in.readFloatBig()) -, x98_Sound_Impact(CSfxManager::TranslateSFXID(in.readUint32Big())) -, x9c_averageNextShotTime(in.readFloatBig()) -, xa0_nextShotTimeVariation(in.readFloatBig()) -, xa4_Sound_Alert(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xa8_GunTrackDelay(in.readFloatBig()) -, xac_firstBurstCount(in.readUint32Big()) -, xb0_CloakOpacity(in.readFloatBig()) -, xb4_MaxCloakOpacity(in.readFloatBig()) -, xb8_dodgeDelayTimeMin(in.readFloatBig()) -, xbc_dodgeDelayTimeMax(in.readFloatBig()) -, xc0_Sound_Hurled(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xc2_Sound_Death(CSfxManager::TranslateSFXID(in.readUint32Big())) -, xc4_(propCount > 35 ? in.readFloatBig() : 0.2f) -, xc8_AvoidDistance(propCount > 36 ? in.readFloatBig() : 8.f) {} +, x94_DodgeCheck(in.ReadFloat()) +, x98_Sound_Impact(CSfxManager::TranslateSFXID(in.ReadLong())) +, x9c_averageNextShotTime(in.ReadFloat()) +, xa0_nextShotTimeVariation(in.ReadFloat()) +, xa4_Sound_Alert(CSfxManager::TranslateSFXID(in.ReadLong())) +, xa8_GunTrackDelay(in.ReadFloat()) +, xac_firstBurstCount(in.ReadLong()) +, xb0_CloakOpacity(in.ReadFloat()) +, xb4_MaxCloakOpacity(in.ReadFloat()) +, xb8_dodgeDelayTimeMin(in.ReadFloat()) +, xbc_dodgeDelayTimeMax(in.ReadFloat()) +, xc0_Sound_Hurled(CSfxManager::TranslateSFXID(in.ReadLong())) +, xc2_Sound_Death(CSfxManager::TranslateSFXID(in.ReadLong())) +, xc4_(propCount > 35 ? in.ReadFloat() : 0.2f) +, xc8_AvoidDistance(propCount > 36 ? in.ReadFloat() : 8.f) {} CPirateRagDoll::CPirateRagDoll(CStateManager& mgr, CSpacePirate* sp, u16 thudSfx, u32 flags) : CRagDoll(-sp->GetGravityConstant(), -3.f, 8.f, flags), x6c_spacePirate(sp), x70_thudSfx(thudSfx) { diff --git a/Runtime/Particle/CColorElement.cpp b/Runtime/Particle/CColorElement.cpp index 6650c97b0..f48954268 100644 --- a/Runtime/Particle/CColorElement.cpp +++ b/Runtime/Particle/CColorElement.cpp @@ -12,17 +12,17 @@ namespace metaforce { CCEKeyframeEmitter::CCEKeyframeEmitter(CInputStream& in) { - x4_percent = in.readUint32Big(); - x8_unk1 = in.readUint32Big(); - xc_loop = in.readBool(); - xd_unk2 = in.readBool(); - x10_loopEnd = in.readUint32Big(); - x14_loopStart = in.readUint32Big(); + x4_percent = in.ReadLong(); + x8_unk1 = in.ReadLong(); + xc_loop = in.ReadBool(); + xd_unk2 = in.ReadBool(); + x10_loopEnd = in.ReadLong(); + x14_loopStart = in.ReadLong(); - const u32 count = in.readUint32Big(); + const u32 count = in.ReadLong(); x18_keys.reserve(count); for (u32 i = 0; i < count; ++i) { - x18_keys.emplace_back(in.readVec4fBig()); + x18_keys.emplace_back(in.Get()); } } diff --git a/Runtime/Particle/CDecalDataFactory.cpp b/Runtime/Particle/CDecalDataFactory.cpp index 7500438b0..18a4a2668 100644 --- a/Runtime/Particle/CDecalDataFactory.cpp +++ b/Runtime/Particle/CDecalDataFactory.cpp @@ -82,7 +82,7 @@ bool CDecalDataFactory::CreateDPSM(CDecalDescription* desc, CInputStream& in, CS desc->x5c_25_DMOO = CPF::GetBool(in); break; default: { - Log.report(logvisor::Fatal, FMT_STRING("Unknown DPSC class {} @{}"), clsId, in.position()); + Log.report(logvisor::Fatal, FMT_STRING("Unknown DPSC class {} @{}"), clsId, in.GetReadPosition()); return false; } } diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index f061fccd9..4bc4c7a62 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -12,17 +12,17 @@ namespace metaforce { CIEKeyframeEmitter::CIEKeyframeEmitter(CInputStream& in) { - x4_percent = in.readUint32Big(); - x8_unk1 = in.readUint32Big(); - xc_loop = in.readBool(); - xd_unk2 = in.readBool(); - x10_loopEnd = in.readUint32Big(); - x14_loopStart = in.readUint32Big(); + x4_percent = in.ReadLong(); + x8_unk1 = in.ReadLong(); + xc_loop = in.ReadBool(); + xd_unk2 = in.ReadBool(); + x10_loopEnd = in.ReadLong(); + x14_loopStart = in.ReadLong(); - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x18_keys.reserve(count); for (u32 i = 0; i < count; ++i) - x18_keys.push_back(in.readInt32Big()); + x18_keys.push_back(in.ReadInt32()); } bool CIEKeyframeEmitter::GetValue([[maybe_unused]] int frame, int& valOut) const { diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index 2613d4464..83b131520 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -11,20 +11,20 @@ namespace metaforce { static logvisor::Module Log("metaforce::CParticleDataFactory"); -float CParticleDataFactory::GetReal(CInputStream& in) { return in.readFloatBig(); } +float CParticleDataFactory::GetReal(CInputStream& in) { return in.ReadFloat(); } -s32 CParticleDataFactory::GetInt(CInputStream& in) { return in.readInt32Big(); } +s32 CParticleDataFactory::GetInt(CInputStream& in) { return in.ReadInt32(); } bool CParticleDataFactory::GetBool(CInputStream& in) { FourCC cid = GetClassID(in); if (cid != FOURCC('CNST')) Log.report(logvisor::Fatal, FMT_STRING("bool element does not begin with CNST")); - return in.readBool(); + return in.ReadBool(); } FourCC CParticleDataFactory::GetClassID(CInputStream& in) { u32 val = 0; - in.readBytesToBuf(&val, 4); + in.Get(reinterpret_cast(&val), 4); return val; } @@ -32,7 +32,7 @@ SParticleModel CParticleDataFactory::GetModel(CInputStream& in, CSimplePool* res FourCC clsId = GetClassID(in); if (clsId == SBIG('NONE')) return {}; - CAssetId id = in.readUint32Big(); + CAssetId id = in.Get(); if (!id.IsValid()) return {}; return {resPool->GetObj({FOURCC('CMDL'), id}), true}; @@ -50,7 +50,7 @@ SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(CInputStream& in FourCC clsId = GetClassID(in); if (clsId == SBIG('NONE')) return {}; - CAssetId id = in.readUint32Big(); + CAssetId id = in.Get(); if (!id.IsValid()) return {}; return GetChildGeneratorDesc(id, resPool, tracker); @@ -60,7 +60,7 @@ SSwooshGeneratorDesc CParticleDataFactory::GetSwooshGeneratorDesc(CInputStream& FourCC clsId = GetClassID(in); if (clsId == SBIG('NONE')) return {}; - CAssetId id = in.readUint32Big(); + CAssetId id = in.Get(); if (!id.IsValid()) return {}; return {resPool->GetObj({FOURCC('SWHC'), id}), true}; @@ -70,7 +70,7 @@ SElectricGeneratorDesc CParticleDataFactory::GetElectricGeneratorDesc(CInputStre FourCC clsId = GetClassID(in); if (clsId == SBIG('NONE')) return {}; - CAssetId id = in.readUint32Big(); + CAssetId id = in.Get(); if (!id.IsValid()) return {}; return {resPool->GetObj({FOURCC('ELSC'), id}), true}; @@ -83,7 +83,7 @@ std::unique_ptr CParticleDataFactory::GetTextureElement(CInputStream FourCC subId = GetClassID(in); if (subId == SBIG('NONE')) return nullptr; - CAssetId id = in.readUint32Big(); + CAssetId id = in.Get(); TToken txtr = resPool->GetObj({FOURCC('TXTR'), id}); return std::make_unique(std::move(txtr)); } @@ -92,7 +92,7 @@ std::unique_ptr CParticleDataFactory::GetTextureElement(CInputStream if (subId == SBIG('NONE')) { return nullptr; } - const CAssetId id = in.readUint32Big(); + const CAssetId id = in.Get(); auto a = GetIntElement(in); auto b = GetIntElement(in); auto c = GetIntElement(in); @@ -980,13 +980,13 @@ bool CParticleDataFactory::CreateGPSM(CGenDescription* fillDesc, CInputStream& i fillDesc->xec_xd8_SELC = GetElectricGeneratorDesc(in, resPool); break; default: { - Log.report(logvisor::Fatal, FMT_STRING("Unknown GPSM class {} @{}"), clsId, in.position()); + Log.report(logvisor::Fatal, FMT_STRING("Unknown GPSM class {} @{}"), clsId, in.GetReadPosition()); return false; } } clsId = GetClassID(in); } - +#if 0 /* Now for our custom additions, if available */ if (!in.atEnd() && (in.position() + 4) < in.length()) { clsId = GetClassID(in); @@ -1004,6 +1004,8 @@ bool CParticleDataFactory::CreateGPSM(CGenDescription* fillDesc, CInputStream& i clsId = GetClassID(in); } } +#endif + return true; } diff --git a/Runtime/Particle/CParticleElectricDataFactory.cpp b/Runtime/Particle/CParticleElectricDataFactory.cpp index dc6ef5f79..e2c849a1e 100644 --- a/Runtime/Particle/CParticleElectricDataFactory.cpp +++ b/Runtime/Particle/CParticleElectricDataFactory.cpp @@ -104,7 +104,7 @@ bool CParticleElectricDataFactory::CreateELSM(CElectricDescription* desc, CInput desc->x70_ZERY = CPF::GetBool(in); break; default: { - Log.report(logvisor::Fatal, FMT_STRING("Unknown ELSM class {} @{}"), clsId, in.position()); + Log.report(logvisor::Fatal, FMT_STRING("Unknown ELSM class {} @{}"), clsId, in.GetReadPosition()); return false; } } diff --git a/Runtime/Particle/CParticleSwooshDataFactory.cpp b/Runtime/Particle/CParticleSwooshDataFactory.cpp index 407f33ad6..eddd0faa5 100644 --- a/Runtime/Particle/CParticleSwooshDataFactory.cpp +++ b/Runtime/Particle/CParticleSwooshDataFactory.cpp @@ -122,7 +122,7 @@ bool CParticleSwooshDataFactory::CreateWPSM(CSwooshDescription* desc, CInputStre desc->x45_26_CRND = CPF::GetBool(in); break; default: { - Log.report(logvisor::Fatal, FMT_STRING("Unknown SWSH class {} @{}"), clsId, in.position()); + Log.report(logvisor::Fatal, FMT_STRING("Unknown SWSH class {} @{}"), clsId, in.GetReadPosition()); return false; } } diff --git a/Runtime/Particle/CProjectileWeaponDataFactory.cpp b/Runtime/Particle/CProjectileWeaponDataFactory.cpp index 554b54aeb..c388dfd82 100644 --- a/Runtime/Particle/CProjectileWeaponDataFactory.cpp +++ b/Runtime/Particle/CProjectileWeaponDataFactory.cpp @@ -158,7 +158,7 @@ bool CProjectileWeaponDataFactory::CreateWPSM(CWeaponDescription* desc, CInputSt desc->x29_FC60 = CPF::GetBool(in); break; default: { - Log.report(logvisor::Fatal, FMT_STRING("Unknown WPSM class {} @{}"), clsId, in.position()); + Log.report(logvisor::Fatal, FMT_STRING("Unknown WPSM class {} @{}"), clsId, in.GetReadPosition()); return false; } } diff --git a/Runtime/Particle/CRealElement.cpp b/Runtime/Particle/CRealElement.cpp index e42ddd4fc..b5b313ea8 100644 --- a/Runtime/Particle/CRealElement.cpp +++ b/Runtime/Particle/CRealElement.cpp @@ -13,17 +13,17 @@ namespace metaforce { CREKeyframeEmitter::CREKeyframeEmitter(CInputStream& in) { - x4_percent = in.readUint32Big(); - x8_unk1 = in.readUint32Big(); - xc_loop = in.readBool(); - xd_unk2 = in.readBool(); - x10_loopEnd = in.readUint32Big(); - x14_loopStart = in.readUint32Big(); + x4_percent = in.ReadLong(); + x8_unk1 = in.ReadLong(); + xc_loop = in.ReadBool(); + xd_unk2 = in.ReadBool(); + x10_loopEnd = in.ReadLong(); + x14_loopStart = in.ReadLong(); - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x18_keys.reserve(count); for (u32 i = 0; i < count; ++i) - x18_keys.push_back(in.readFloatBig()); + x18_keys.push_back(in.ReadFloat()); } bool CREKeyframeEmitter::GetValue([[maybe_unused]] int frame, float& valOut) const { diff --git a/Runtime/Particle/CSpawnSystemKeyframeData.cpp b/Runtime/Particle/CSpawnSystemKeyframeData.cpp index 4a039cc18..f75a2ae34 100644 --- a/Runtime/Particle/CSpawnSystemKeyframeData.cpp +++ b/Runtime/Particle/CSpawnSystemKeyframeData.cpp @@ -7,18 +7,18 @@ namespace metaforce { CSpawnSystemKeyframeData::CSpawnSystemKeyframeData(CInputStream& in) { - x0 = in.readUint32Big(); - x4 = in.readUint32Big(); - x8_endFrame = in.readUint32Big(); - xc = in.readUint32Big(); + x0 = in.ReadLong(); + x4 = in.ReadLong(); + x8_endFrame = in.ReadLong(); + xc = in.ReadLong(); - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); x10_spawns.reserve(count); for (u32 i = 0; i < count; ++i) { - u32 v1 = in.readUint32Big(); + u32 v1 = in.ReadLong(); x10_spawns.emplace_back(v1, std::vector()); std::vector& v2 = x10_spawns.back().second; - u32 v2c = in.readUint32Big(); + u32 v2c = in.ReadLong(); v2.reserve(v2c); for (u32 j = 0; j < v2c; ++j) v2.emplace_back(in); @@ -26,10 +26,10 @@ CSpawnSystemKeyframeData::CSpawnSystemKeyframeData(CInputStream& in) { } CSpawnSystemKeyframeData::CSpawnSystemKeyframeInfo::CSpawnSystemKeyframeInfo(CInputStream& in) { - x0_id = in.readUint32Big(); - x4 = in.readUint32Big(); - x8 = in.readUint32Big(); - xc = in.readUint32Big(); + x0_id = in.ReadLong(); + x4 = in.ReadLong(); + x8 = in.ReadLong(); + xc = in.ReadLong(); } void CSpawnSystemKeyframeData::LoadAllSpawnedSystemTokens(CSimplePool* pool) { diff --git a/Runtime/Particle/CVectorElement.cpp b/Runtime/Particle/CVectorElement.cpp index 32afa1541..ec36034c3 100644 --- a/Runtime/Particle/CVectorElement.cpp +++ b/Runtime/Particle/CVectorElement.cpp @@ -12,17 +12,17 @@ namespace metaforce { CVEKeyframeEmitter::CVEKeyframeEmitter(CInputStream& in) { - x4_percent = in.readUint32Big(); - x8_unk1 = in.readUint32Big(); - xc_loop = in.readBool(); - xd_unk2 = in.readBool(); - x10_loopEnd = in.readUint32Big(); - x14_loopStart = in.readUint32Big(); + x4_percent = in.ReadLong(); + x8_unk1 = in.ReadLong(); + xc_loop = in.ReadBool(); + xd_unk2 = in.ReadBool(); + x10_loopEnd = in.ReadLong(); + x14_loopStart = in.ReadLong(); - const u32 count = in.readUint32Big(); + const u32 count = in.ReadLong(); x18_keys.reserve(count); for (u32 i = 0; i < count; ++i) { - x18_keys.emplace_back(in.readVec3fBig()); + x18_keys.emplace_back(in.Get()); } } diff --git a/Runtime/RetroTypes.cpp b/Runtime/RetroTypes.cpp index 3cb13e09a..45ca652f8 100644 --- a/Runtime/RetroTypes.cpp +++ b/Runtime/RetroTypes.cpp @@ -1,5 +1,5 @@ #include "Runtime/RetroTypes.hpp" - +#include "Runtime/IOStreams.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/IMain.hpp" @@ -8,28 +8,42 @@ namespace metaforce { logvisor::Module Log("metaforce::RetroTypes::CAssetId"); +SObjectTag::SObjectTag(CInputStream& in) { + in.ReadBytes(reinterpret_cast(&type), 4); + id = in.Get(); +} + +void SObjectTag::ReadMLVL(CInputStream& in) { + id = in.Get(); + in.ReadBytes(reinterpret_cast(&type), 4); +} + CAssetId::CAssetId(CInputStream& in) { - if (g_Main) { - if (g_Main->GetExpectedIdSize() == sizeof(u32)) - Assign(in.readUint32Big()); - else if (g_Main->GetExpectedIdSize() == sizeof(u64)) - Assign(in.readUint64Big()); - else + if (g_Main != nullptr) { + if (g_Main->GetExpectedIdSize() == sizeof(u32)) { + Assign(in.ReadLong()); + } else if (g_Main->GetExpectedIdSize() == sizeof(u64)) { + Assign(in.ReadLongLong()); + } else { Log.report(logvisor::Fatal, FMT_STRING("Unsupported id length {}"), g_Main->GetExpectedIdSize()); - } else + } + } else { Log.report(logvisor::Fatal, FMT_STRING("Input constructor called before runtime Main entered!")); + } } void CAssetId::PutTo(COutputStream& out) { - if (g_Main) { - if (g_Main->GetExpectedIdSize() == sizeof(u32)) - out.writeUint32Big(u32(id)); - else if (g_Main->GetExpectedIdSize() == sizeof(u64)) - out.writeUint64Big(id); - else + if (g_Main != nullptr) { + if (g_Main->GetExpectedIdSize() == sizeof(u32)) { + out.Put(u32(id)); + } else if (g_Main->GetExpectedIdSize() == sizeof(u64)) { + out.Put(id); + } else { Log.report(logvisor::Fatal, FMT_STRING("Unsupported id length {}"), g_Main->GetExpectedIdSize()); - } else + } + } else { Log.report(logvisor::Fatal, FMT_STRING("PutTo called before runtime Main entered!")); + } } } // namespace metaforce \ No newline at end of file diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index 2025461da..27746d15a 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -20,12 +20,9 @@ using namespace std::literals; -namespace athena::io { -class IStreamReader; -class IStreamWriter; -} // namespace athena::io - namespace metaforce { +class CInputStream; +class COutputStream; using kUniqueIdType = u16; static constexpr int kMaxEntities = 1024; constexpr kUniqueIdType kUniqueIdSize = sizeof(u16); @@ -194,9 +191,6 @@ public: }; #define FOURCC(chars) FourCC(SBIG(chars)) -using CInputStream = athena::io::IStreamReader; -using COutputStream = athena::io::IStreamWriter; - class CAssetId { u64 id = UINT64_MAX; @@ -226,14 +220,8 @@ struct SObjectTag { [[nodiscard]] constexpr bool operator<(const SObjectTag& other) const noexcept { return id < other.id; } constexpr SObjectTag() noexcept = default; constexpr SObjectTag(FourCC tp, CAssetId rid) noexcept : type(tp), id(rid) {} - explicit SObjectTag(CInputStream& in) { - in.readBytesToBuf(&type, 4); - id = CAssetId(in); - } - void readMLVL(CInputStream& in) { - id = CAssetId(in); - in.readBytesToBuf(&type, 4); - } + explicit SObjectTag(CInputStream& in); + void ReadMLVL(CInputStream& in); }; struct TEditorId { diff --git a/Runtime/Weapon/CBeamInfo.hpp b/Runtime/Weapon/CBeamInfo.hpp index d800a489f..80426dc45 100644 --- a/Runtime/Weapon/CBeamInfo.hpp +++ b/Runtime/Weapon/CBeamInfo.hpp @@ -32,23 +32,23 @@ class CBeamInfo { public: explicit CBeamInfo(CInputStream& in) - : x0_(in.readUint32Big()) - , x4_beamAttributes(in.readUint32Big()) - , x8_contactFxId(in.readUint32Big()) - , xc_pulseFxId(in.readUint32Big()) - , x10_textureId(in.readUint32Big()) - , x14_glowTextureId(in.readUint32Big()) - , x18_length(in.readFloatBig()) - , x1c_radius(in.readFloatBig()) - , x20_expansionSpeed(in.readFloatBig()) - , x24_lifeTime(in.readFloatBig()) - , x28_pulseSpeed(in.readFloatBig()) - , x2c_shutdownTime(in.readFloatBig()) - , x30_contactFxScale(in.readFloatBig()) - , x34_pulseFxScale(in.readFloatBig()) - , x38_travelSpeed(in.readFloatBig()) - , x3c_innerColor(zeus::CColor::ReadRGBABig(in)) - , x40_outerColor(zeus::CColor::ReadRGBABig(in)) {} + : x0_(in.ReadLong()) + , x4_beamAttributes(in.ReadLong()) + , x8_contactFxId(in.ReadLong()) + , xc_pulseFxId(in.ReadLong()) + , x10_textureId(in.ReadLong()) + , x14_glowTextureId(in.ReadLong()) + , x18_length(in.ReadFloat()) + , x1c_radius(in.ReadFloat()) + , x20_expansionSpeed(in.ReadFloat()) + , x24_lifeTime(in.ReadFloat()) + , x28_pulseSpeed(in.ReadFloat()) + , x2c_shutdownTime(in.ReadFloat()) + , x30_contactFxScale(in.ReadFloat()) + , x34_pulseFxScale(in.ReadFloat()) + , x38_travelSpeed(in.ReadFloat()) + , x3c_innerColor(in.Get()) + , x40_outerColor(in.Get()) {} CBeamInfo(s32 beamAttributes, CAssetId contactFxId, CAssetId pulseFxId, CAssetId textureId, CAssetId glowTextureId, s32 length, float radius, float expansionSpeed, float lifeTime, float pulseSpeed, float shutdownTime, diff --git a/Runtime/Weapon/CFlameInfo.cpp b/Runtime/Weapon/CFlameInfo.cpp index ff6ccd3ec..ee57308cb 100644 --- a/Runtime/Weapon/CFlameInfo.cpp +++ b/Runtime/Weapon/CFlameInfo.cpp @@ -6,11 +6,11 @@ CFlameInfo::CFlameInfo(s32 w1, s32 w2, CAssetId flameFxId, s32 w3, float f1, flo : x0_propertyCount(w1), x4_attributes(w2), x8_flameFxId(flameFxId), xc_length(w3), x10_(f1), x18_(f2), x1c_(f3) {} CFlameInfo::CFlameInfo(CInputStream& in) -: x0_propertyCount(in.readUint32Big()) -, x4_attributes(in.readUint32Big()) +: x0_propertyCount(in.ReadLong()) +, x4_attributes(in.ReadLong()) , x8_flameFxId(in) -, xc_length(in.readUint32Big()) -, x10_(in.readFloatBig()) -, x18_(in.readFloatBig()) -, x1c_(in.readFloatBig()) {} +, xc_length(in.ReadLong()) +, x10_(in.ReadFloat()) +, x18_(in.ReadFloat()) +, x1c_(in.ReadFloat()) {} } // namespace metaforce diff --git a/Runtime/Weapon/CPlasmaProjectile.hpp b/Runtime/Weapon/CPlasmaProjectile.hpp index 2dec40569..36082353a 100644 --- a/Runtime/Weapon/CPlasmaProjectile.hpp +++ b/Runtime/Weapon/CPlasmaProjectile.hpp @@ -24,7 +24,7 @@ public: : rstl::reserved_vector({a, b, c, d, e, f, g, h}) {} }; static PlayerEffectResources LoadPlayerEffectResources(CInputStream& in) { - u32 propCount = in.readUint32(); + u32 propCount = in.ReadLong(); CAssetId a{in}; CAssetId b{in}; CAssetId c{in}; diff --git a/Runtime/World/CAnimationParameters.hpp b/Runtime/World/CAnimationParameters.hpp index 486ca8708..9c7de3bd3 100644 --- a/Runtime/World/CAnimationParameters.hpp +++ b/Runtime/World/CAnimationParameters.hpp @@ -1,6 +1,7 @@ #pragma once #include "Runtime/RetroTypes.hpp" +#include "Runtime/CInputStream.hpp" namespace metaforce { @@ -14,7 +15,7 @@ public: CAnimationParameters(CAssetId ancs, u32 charIdx, u32 defaultAnim) : x0_ancs(ancs), x4_charIdx(charIdx), x8_defaultAnim(defaultAnim) {} explicit CAnimationParameters(CInputStream& in) - : x0_ancs(in.readUint32Big()), x4_charIdx(in.readUint32Big()), x8_defaultAnim(in.readUint32Big()) {} + : x0_ancs(in.ReadLong()), x4_charIdx(in.ReadLong()), x8_defaultAnim(in.ReadLong()) {} CAssetId GetACSFile() const { return x0_ancs; } u32 GetCharacter() const { return x4_charIdx; } diff --git a/Runtime/World/CDamageInfo.hpp b/Runtime/World/CDamageInfo.hpp index 40880fd05..2ea087dbb 100644 --- a/Runtime/World/CDamageInfo.hpp +++ b/Runtime/World/CDamageInfo.hpp @@ -21,12 +21,12 @@ class CDamageInfo { public: constexpr CDamageInfo() = default; explicit CDamageInfo(CInputStream& in) { - in.readUint32Big(); - x0_weaponMode = CWeaponMode(EWeaponType(in.readUint32Big())); - x8_damage = in.readFloatBig(); + in.ReadLong(); + x0_weaponMode = CWeaponMode(EWeaponType(in.ReadLong())); + x8_damage = in.ReadFloat(); xc_radiusDamage = x8_damage; - x10_radius = in.readFloatBig(); - x14_knockback = in.readFloatBig(); + x10_radius = in.ReadFloat(); + x14_knockback = in.ReadFloat(); } constexpr CDamageInfo(const CWeaponMode& mode, float damage, float radius, float knockback) : x0_weaponMode(mode), x8_damage(damage), xc_radiusDamage(damage), x10_radius(radius), x14_knockback(knockback) {} diff --git a/Runtime/World/CDamageVulnerability.cpp b/Runtime/World/CDamageVulnerability.cpp index 857012117..b1b9c8802 100644 --- a/Runtime/World/CDamageVulnerability.cpp +++ b/Runtime/World/CDamageVulnerability.cpp @@ -48,7 +48,7 @@ void CDamageVulnerability::ConstructNew(CInputStream& in, int propCount) { propCount -= 3; for (int i = 0; i < std::min(propCount, 15); ++i) { - x0_normal[i] = EVulnerability(in.readUint32Big()); + x0_normal[i] = EVulnerability(in.ReadLong()); } if (propCount < 15) { @@ -58,32 +58,32 @@ void CDamageVulnerability::ConstructNew(CInputStream& in, int propCount) { } for (int i = 15; i < propCount; ++i) { - in.readUint32Big(); + in.ReadLong(); } - x5c_deflected = EDeflectType(in.readUint32Big()); - in.readUint32Big(); + x5c_deflected = EDeflectType(in.ReadLong()); + in.ReadLong(); for (int i = 0; i < 4; ++i) { - x3c_charged[i] = EVulnerability(in.readUint32Big()); + x3c_charged[i] = EVulnerability(in.ReadLong()); } - x60_chargedDeflected = EDeflectType(in.readUint32Big()); - in.readUint32Big(); + x60_chargedDeflected = EDeflectType(in.ReadLong()); + in.ReadLong(); for (int i = 0; i < 4; ++i) { - x4c_combo[i] = EVulnerability(in.readUint32Big()); + x4c_combo[i] = EVulnerability(in.ReadLong()); } - x64_comboDeflected = EDeflectType(in.readUint32Big()); + x64_comboDeflected = EDeflectType(in.ReadLong()); } CDamageVulnerability::CDamageVulnerability(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount == 11) { for (int i = 0; i < 15; ++i) { - x0_normal[i] = EVulnerability(in.readUint32Big()); + x0_normal[i] = EVulnerability(in.ReadLong()); } - x5c_deflected = EDeflectType(in.readUint32Big()); + x5c_deflected = EDeflectType(in.ReadLong()); x3c_charged[0] = x0_normal[0]; x4c_combo[0] = x0_normal[0]; x3c_charged[1] = x0_normal[1]; diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index 17b854979..8f27f16d1 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -20,11 +20,11 @@ static logvisor::Module Log("CGameArea"); CAreaRenderOctTree::CAreaRenderOctTree(const u8* buf) : x0_buf(buf) { CMemoryInStream r(x0_buf + 8, INT32_MAX); - x8_bitmapCount = r.readUint32Big(); - xc_meshCount = r.readUint32Big(); - x10_nodeCount = r.readUint32Big(); + x8_bitmapCount = r.ReadLong(); + xc_meshCount = r.ReadLong(); + x10_nodeCount = r.ReadLong(); x14_bitmapWordCount = (xc_meshCount + 31) / 32; - x18_aabb.readBoundingBoxBig(r); + x18_aabb = r.Get(); x30_bitmaps = reinterpret_cast(x0_buf + 64); u32 wc = x14_bitmapWordCount * x8_bitmapCount; @@ -239,10 +239,10 @@ void CGameArea::CAreaFog::DisableFog() { x0_fogMode = ERglFogMode::None; } static std::vector ReadDependencyList(CInputStream& in) { std::vector ret; - const u32 count = in.readUint32Big(); + const u32 count = in.ReadLong(); ret.reserve(count); for (u32 i = 0; i < count; ++i) { - ret.emplace_back().readMLVL(in); + ret.emplace_back().ReadMLVL(in); } return ret; } @@ -258,7 +258,7 @@ std::pair, s32> GetScriptingMemoryAlways(const IGameArea& } CMemoryInStream r(data.get() + 4, 96 - 4); - u32 version = r.readUint32Big(); + u32 version = r.ReadLong(); if ((version & 0x10000) == 0) { Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-URDE MREA")); } @@ -270,17 +270,17 @@ std::pair, s32> GetScriptingMemoryAlways(const IGameArea& return {}; } - header.xf.read34RowMajor(r); - header.modelCount = r.readUint32Big(); - header.secCount = r.readUint32Big(); - header.geomSecIdx = r.readUint32Big(); - header.sclySecIdx = r.readUint32Big(); - header.collisionSecIdx = r.readUint32Big(); - header.unkSecIdx = r.readUint32Big(); - header.lightSecIdx = r.readUint32Big(); - header.visiSecIdx = r.readUint32Big(); - header.pathSecIdx = r.readUint32Big(); - header.arotSecIdx = r.readUint32Big(); + header.xf = r.Get(); + header.modelCount = r.ReadLong(); + header.secCount = r.ReadLong(); + header.geomSecIdx = r.ReadLong(); + header.sclySecIdx = r.ReadLong(); + header.collisionSecIdx = r.ReadLong(); + header.unkSecIdx = r.ReadLong(); + header.lightSecIdx = r.ReadLong(); + header.visiSecIdx = r.ReadLong(); + header.pathSecIdx = r.ReadLong(); + header.arotSecIdx = r.ReadLong(); u32 dataLen = ROUND_UP_32(header.secCount * 4); @@ -291,7 +291,7 @@ std::pair, s32> GetScriptingMemoryAlways(const IGameArea& std::vector secSizes(header.secCount); u32 lastSize; for (u32 i = 0; i < header.secCount; ++i) { - lastSize = r.readUint32Big(); + lastSize = r.ReadLong(); secSizes.push_back(lastSize); } @@ -300,32 +300,31 @@ std::pair, s32> GetScriptingMemoryAlways(const IGameArea& } CDummyGameArea::CDummyGameArea(CInputStream& in, int idx, int mlvlVersion) { - x8_nameSTRG = in.readUint32Big(); - x14_transform.read34RowMajor(in); - zeus::CAABox aabb; - aabb.readBoundingBoxBig(in); - xc_mrea = in.readUint32Big(); + x8_nameSTRG = in.ReadLong(); + x14_transform = in.Get(); + zeus::CAABox aabb = in.Get(); + xc_mrea = in.ReadLong(); if (mlvlVersion > 15) { - x10_areaId = in.readUint32Big(); + x10_areaId = in.ReadLong(); } else { x10_areaId = -1; } - u32 attachAreaCount = in.readUint32Big(); + u32 attachAreaCount = in.ReadLong(); x44_attachedAreaIndices.reserve(attachAreaCount); for (u32 i = 0; i < attachAreaCount; ++i) - x44_attachedAreaIndices.push_back(in.readUint16Big()); + x44_attachedAreaIndices.push_back(in.ReadShort()); ::metaforce::ReadDependencyList(in); ::metaforce::ReadDependencyList(in); if (mlvlVersion > 13) { - u32 depCount = in.readUint32Big(); + u32 depCount = in.ReadLong(); for (u32 i = 0; i < depCount; ++i) - in.readUint32Big(); + in.ReadLong(); } - u32 dockCount = in.readUint32Big(); + u32 dockCount = in.ReadLong(); x54_docks.reserve(dockCount); for (u32 i = 0; i < dockCount; ++i) x54_docks.emplace_back(in, x14_transform); @@ -350,21 +349,21 @@ CAssetId CDummyGameArea::IGetStringTableAssetId() const { return x8_nameSTRG; } const zeus::CTransform& CDummyGameArea::IGetTM() const { return x14_transform; } CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(idx) { - x8_nameSTRG = in.readUint32Big(); - xc_transform.read34RowMajor(in); + x8_nameSTRG = in.ReadLong(); + xc_transform = in.Get(); x3c_invTransform = xc_transform.inverse(); - x6c_aabb.readBoundingBoxBig(in); + x6c_aabb = in.Get(); - x84_mrea = in.readUint32Big(); + x84_mrea = in.ReadLong(); if (mlvlVersion > 15) - x88_areaId = in.readUint32Big(); + x88_areaId = in.ReadLong(); else x88_areaId = INT_MAX; - const u32 attachedCount = in.readUint32Big(); + const u32 attachedCount = in.ReadLong(); x8c_attachedAreaIndices.reserve(attachedCount); for (u32 i = 0; i < attachedCount; ++i) { - x8c_attachedAreaIndices.emplace_back(in.readUint16Big()); + x8c_attachedAreaIndices.emplace_back(in.ReadShort()); } x9c_deps1 = metaforce::ReadDependencyList(in); @@ -374,14 +373,14 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(id x6c_aabb = aabb; if (mlvlVersion > 13) { - const u32 depCount = in.readUint32Big(); + const u32 depCount = in.ReadLong(); xbc_layerDepOffsets.reserve(depCount); for (u32 i = 0; i < depCount; ++i) { - xbc_layerDepOffsets.emplace_back(in.readUint32Big()); + xbc_layerDepOffsets.emplace_back(in.ReadLong()); } } - const u32 dockCount = in.readUint32Big(); + const u32 dockCount = in.ReadLong(); xcc_docks.reserve(dockCount); for (u32 i = 0; i < dockCount; ++i) { xcc_docks.emplace_back(in, xc_transform); @@ -415,7 +414,7 @@ CGameArea::CGameArea(CAssetId mreaId) : x84_mrea(mreaId), xf0_25_active{false} { CModelFlags defaultFlags; for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { CGraphics::SetModelMatrix(zeus::CTransform::Translate(-inst.x34_aabb.center())); -// inst.m_instance->UpdateUniformData(defaultFlags, nullptr, nullptr); + // inst.m_instance->UpdateUniformData(defaultFlags, nullptr, nullptr); inst.m_instance->WarmupDrawSurfaces(); } CGraphics::SetProjectionState(backupProj); @@ -956,10 +955,10 @@ void CGameArea::PostConstructArea() { /* Lights section */ if (header.version > 6) { - athena::io::MemoryReader r(secIt->first, secIt->second); - u32 magic = r.readUint32Big(); + CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + u32 magic = r.ReadLong(); if (magic == 0xBABEDEAD) { - u32 aCount = r.readUint32Big(); + u32 aCount = r.ReadLong(); x12c_postConstructed->x60_lightsA.reserve(aCount); x12c_postConstructed->x70_gfxLightsA.reserve(aCount); for (u32 i = 0; i < aCount; ++i) { @@ -967,7 +966,7 @@ void CGameArea::PostConstructArea() { x12c_postConstructed->x70_gfxLightsA.push_back(x12c_postConstructed->x60_lightsA.back().GetAsCGraphicsLight()); } - u32 bCount = r.readUint32Big(); + u32 bCount = r.ReadLong(); x12c_postConstructed->x80_lightsB.reserve(bCount); x12c_postConstructed->x90_gfxLightsB.reserve(bCount); for (u32 i = 0; i < bCount; ++i) { @@ -981,15 +980,15 @@ void CGameArea::PostConstructArea() { /* PVS section */ if (header.version > 7) { - athena::io::MemoryReader r(secIt->first, secIt->second); - u32 magic = r.readUint32Big(); + CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + u32 magic = r.ReadLong(); if (magic == 'VISI') { - x12c_postConstructed->x10a8_pvsVersion = r.readUint32Big(); + x12c_postConstructed->x10a8_pvsVersion = r.ReadLong(); if (x12c_postConstructed->x10a8_pvsVersion == 2) { - x12c_postConstructed->x1108_29_pvsHasActors = r.readBool(); - x12c_postConstructed->x1108_30_ = r.readBool(); + x12c_postConstructed->x1108_29_pvsHasActors = r.ReadBool(); + x12c_postConstructed->x1108_30_ = r.ReadBool(); x12c_postConstructed->xa0_pvs = - std::make_unique(secIt->first + r.position(), secIt->second - r.position()); + std::make_unique(secIt->first + r.GetReadPosition(), secIt->second - r.GetReadPosition()); } } @@ -998,8 +997,8 @@ void CGameArea::PostConstructArea() { /* Pathfinding section */ if (header.version > 9) { - athena::io::MemoryReader r(secIt->first, secIt->second); - CAssetId pathId = r.readUint32Big(); + CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + CAssetId pathId = r.ReadLong(); x12c_postConstructed->x10ac_pathToken = g_SimplePool->GetObj(SObjectTag{FOURCC('PATH'), pathId}); x12c_postConstructed->x10bc_pathArea = x12c_postConstructed->x10ac_pathToken.GetObj(); x12c_postConstructed->x10bc_pathArea->SetTransform(xc_transform); @@ -1017,16 +1016,17 @@ void CGameArea::PostConstructArea() { /* Resolve layer pointers */ if (x12c_postConstructed->x10c8_sclyBuf) { - athena::io::MemoryReader r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize); - hecl::DNAFourCC magic; - magic.read(r); - if (magic == hecl::FOURCC('SCLY')) { - r.readUint32Big(); - u32 layerCount = r.readUint32Big(); + CMemoryInStream r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize, + CMemoryInStream::EOwnerShip::NotOwned); + FourCC magic; + r.Get(reinterpret_cast(&magic), 4); + if (magic == FOURCC('SCLY')) { + r.ReadLong(); + u32 layerCount = r.ReadLong(); x12c_postConstructed->x110c_layerPtrs.resize(layerCount); for (u32 l = 0; l < layerCount; ++l) - x12c_postConstructed->x110c_layerPtrs[l].second = r.readUint32Big(); - const u8* ptr = x12c_postConstructed->x10c8_sclyBuf + r.position(); + x12c_postConstructed->x110c_layerPtrs[l].second = r.ReadLong(); + const u8* ptr = x12c_postConstructed->x10c8_sclyBuf + r.GetReadPosition(); for (u32 l = 0; l < layerCount; ++l) { x12c_postConstructed->x110c_layerPtrs[l].first = ptr; ptr += x12c_postConstructed->x110c_layerPtrs[l].second; @@ -1044,16 +1044,16 @@ void CGameArea::FillInStaticGeometry(bool textures) { SShader& matSet = x12c_postConstructed->m_materialSet; auto secIt = m_resolvedBufs.begin() + 2; { - athena::io::MemoryReader r(secIt->first, secIt->second); - matSet.m_matSet.read(r); + CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + //matSet.m_matSet.read(r); if (textures) CBooModel::MakeTexturesFromMats(matSet.m_matSet, matSet.x0_textures, *g_SimplePool); -// matSet.InitializeLayout(nullptr); + // matSet.InitializeLayout(nullptr); ++secIt; } /* Reserve extra buffers for 16 cubemaps and shadow rendering */ -// matSet.m_geomLayout->ReserveSharedBuffers(ctx, 96 + int(EWorldShadowMode::MAX)); + // matSet.m_geomLayout->ReserveSharedBuffers(ctx, 96 + int(EWorldShadowMode::MAX)); /* Models */ for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { @@ -1073,17 +1073,17 @@ void CGameArea::FillInStaticGeometry(bool textures) { } ++secIt; -// boo::ObjToken vbo; -// boo::ObjToken ibo; -// vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride, -// inst.m_hmdlMeta.vertCount); + // boo::ObjToken vbo; + // boo::ObjToken ibo; + // vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride, + // inst.m_hmdlMeta.vertCount); ++secIt; -// ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount); + // ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount); ++secIt; const u32 surfCount = hecl::SBig(*reinterpret_cast(secIt->first)); inst.m_surfaces.reserve(surfCount); -// inst.m_shaders.reserve(surfCount); + // inst.m_shaders.reserve(surfCount); ++secIt; for (u32 j = 0; j < surfCount; ++j) { CBooSurface& surf = inst.m_surfaces.emplace_back(); @@ -1094,15 +1094,15 @@ void CGameArea::FillInStaticGeometry(bool textures) { } TToken nullModel; - inst.m_instance = std::make_unique(nullModel, nullptr, &inst.m_surfaces, matSet, //vbo, ibo, + inst.m_instance = std::make_unique(nullModel, nullptr, &inst.m_surfaces, matSet, // vbo, ibo, inst.x34_aabb, static_cast(inst.x0_visorFlags)); } for (CMetroidModelInstance& inst : x12c_postConstructed->x4c_insts) { for (CBooSurface& surf : inst.m_surfaces) { -// auto& shad = inst.m_shaders[surf.m_data.matIdx]; -// if (!shad) -// shad = matSet.BuildShader(inst.m_hmdlMeta, matSet.m_matSet.materials[surf.m_data.matIdx]); + // auto& shad = inst.m_shaders[surf.m_data.matIdx]; + // if (!shad) + // shad = matSet.BuildShader(inst.m_hmdlMeta, matSet.m_matSet.materials[surf.m_data.matIdx]); } inst.m_instance->RemapMaterialData(matSet); } @@ -1154,7 +1154,7 @@ SMREAHeader CGameArea::VerifyHeader() const { } CMemoryInStream r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4); - u32 version = r.readUint32Big(); + u32 version = r.ReadLong(); if ((version & 0x10000) == 0) { Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-URDE MREA")); } @@ -1166,17 +1166,17 @@ SMREAHeader CGameArea::VerifyHeader() const { return {}; } - header.xf.read34RowMajor(r); - header.modelCount = r.readUint32Big(); - header.secCount = r.readUint32Big(); - header.geomSecIdx = r.readUint32Big(); - header.sclySecIdx = r.readUint32Big(); - header.collisionSecIdx = r.readUint32Big(); - header.unkSecIdx = r.readUint32Big(); - header.lightSecIdx = r.readUint32Big(); - header.visiSecIdx = r.readUint32Big(); - header.pathSecIdx = r.readUint32Big(); - header.arotSecIdx = r.readUint32Big(); + header.xf = r.Get(); + header.modelCount = r.ReadLong(); + header.secCount = r.ReadLong(); + header.geomSecIdx = r.ReadLong(); + header.sclySecIdx = r.ReadLong(); + header.collisionSecIdx = r.ReadLong(); + header.unkSecIdx = r.ReadLong(); + header.lightSecIdx = r.ReadLong(); + header.visiSecIdx = r.ReadLong(); + header.pathSecIdx = r.ReadLong(); + header.arotSecIdx = r.ReadLong(); return header; } diff --git a/Runtime/World/CHUDMemoParms.hpp b/Runtime/World/CHUDMemoParms.hpp index cceac81d7..2cd22bc0b 100644 --- a/Runtime/World/CHUDMemoParms.hpp +++ b/Runtime/World/CHUDMemoParms.hpp @@ -15,8 +15,8 @@ public: CHUDMemoParms(float dispTime, bool clearMemoWindow, bool fadeOutOnly, bool hintMemo) : x0_dispTime(dispTime), x4_clearMemoWindow(clearMemoWindow), x5_fadeOutOnly(fadeOutOnly), x6_hintMemo(hintMemo) {} explicit CHUDMemoParms(CInputStream& in) { - x0_dispTime = in.readFloatBig(); - x4_clearMemoWindow = in.readBool(); + x0_dispTime = in.ReadFloat(); + x4_clearMemoWindow = in.ReadBool(); } float GetDisplayTime() const { return x0_dispTime; } diff --git a/Runtime/World/CHealthInfo.cpp b/Runtime/World/CHealthInfo.cpp index efee7e7e9..54806ea22 100644 --- a/Runtime/World/CHealthInfo.cpp +++ b/Runtime/World/CHealthInfo.cpp @@ -1,11 +1,12 @@ #include "Runtime/World/CHealthInfo.hpp" +#include "Runtime/CInputStream.hpp" namespace metaforce { CHealthInfo::CHealthInfo(CInputStream& in) { - in.readUint32Big(); - x0_health = in.readFloatBig(); - x4_knockbackResistance = in.readFloatBig(); + in.ReadLong(); + x0_health = in.ReadFloat(); + x4_knockbackResistance = in.ReadFloat(); } } // namespace metaforce diff --git a/Runtime/World/CPathFindArea.cpp b/Runtime/World/CPathFindArea.cpp index d42cf8082..9829d29b1 100644 --- a/Runtime/World/CPathFindArea.cpp +++ b/Runtime/World/CPathFindArea.cpp @@ -10,13 +10,13 @@ namespace metaforce { static logvisor::Module Log("CPathFindArea"); CPFAreaOctree::CPFAreaOctree(CMemoryInStream& in) { - x0_isLeaf = in.readUint32Big(); - x4_aabb.readBoundingBoxBig(in); - x1c_center.readBig(in); + x0_isLeaf = in.ReadLong(); + x4_aabb = in.Get(); + x1c_center = in.Get(); for (auto& ptr : x28_children) - ptr = reinterpret_cast(in.readUint32Big()); - x48_regions.set_size(in.readUint32Big()); - x48_regions.set_data(reinterpret_cast(in.readUint32Big())); + ptr = reinterpret_cast(in.ReadLong()); + x48_regions.set_size(in.ReadLong()); + x48_regions.set_data(reinterpret_cast(in.ReadLong())); } void CPFAreaOctree::Fixup(CPFArea& area) { @@ -123,21 +123,21 @@ bool CPFOpenList::Test(const CPFRegion* reg) const { return x0_bitSet.Test(reg-> CPFArea::CPFArea(std::unique_ptr&& buf, u32 len) { CMemoryInStream r(buf.get(), len); - u32 version = r.readUint32Big(); + u32 version = r.ReadLong(); if (version != 4) Log.report(logvisor::Fatal, FMT_STRING("Unexpected PATH version {}, should be 4"), version); - u32 numNodes = r.readUint32Big(); + u32 numNodes = r.ReadLong(); x140_nodes.reserve(numNodes); for (u32 i = 0; i < numNodes; ++i) x140_nodes.emplace_back(r); - u32 numLinks = r.readUint32Big(); + u32 numLinks = r.ReadLong(); x148_links.reserve(numLinks); for (u32 i = 0; i < numLinks; ++i) x148_links.emplace_back(r); - u32 numRegions = r.readUint32Big(); + u32 numRegions = r.ReadLong(); x150_regions.reserve(numRegions); for (u32 i = 0; i < numRegions; ++i) x150_regions.emplace_back(r); @@ -154,22 +154,24 @@ CPFArea::CPFArea(std::unique_ptr&& buf, u32 len) { u32 numBitfieldWords = (numRegions * (numRegions - 1) / 2 + 31) / 32; x168_connectionsGround.reserve(numBitfieldWords); for (u32 i = 0; i < numBitfieldWords; ++i) - x168_connectionsGround.push_back(r.readUint32Big()); + x168_connectionsGround.push_back(r.ReadLong()); x170_connectionsFlyers.reserve(numBitfieldWords); for (u32 i = 0; i < numBitfieldWords; ++i) - x170_connectionsFlyers.push_back(r.readUint32Big()); + x170_connectionsFlyers.push_back(r.ReadLong()); - r.seek(((((numRegions * numRegions) + 31) / 32) - numBitfieldWords) * 2 * sizeof(u32)); + for (u32 i = 0; i < ((((numRegions * numRegions) + 31) / 32) - numBitfieldWords) * 2 * sizeof(u32); ++i) { + r.ReadChar(); + } - u32 numRegionLookups = r.readUint32Big(); + u32 numRegionLookups = r.ReadLong(); x160_octreeRegionLookup.reserve(numRegionLookups); for (u32 i = 0; i < numRegionLookups; ++i) - x160_octreeRegionLookup.push_back(reinterpret_cast(r.readUint32Big())); + x160_octreeRegionLookup.push_back(reinterpret_cast(r.ReadLong())); for (CPFRegion*& rl : x160_octreeRegionLookup) rl = &x150_regions[reinterpret_cast(rl)]; - u32 numOctreeNodes = r.readUint32Big(); + u32 numOctreeNodes = r.ReadLong(); x158_octree.reserve(numOctreeNodes); for (u32 i = 0; i < numOctreeNodes; ++i) x158_octree.emplace_back(r); diff --git a/Runtime/World/CPathFindRegion.cpp b/Runtime/World/CPathFindRegion.cpp index dc74b710d..26bf2195b 100644 --- a/Runtime/World/CPathFindRegion.cpp +++ b/Runtime/World/CPathFindRegion.cpp @@ -5,29 +5,29 @@ namespace metaforce { CPFNode::CPFNode(CMemoryInStream& in) { - x0_position.readBig(in); - xc_normal.readBig(in); + x0_position = in.Get(); + xc_normal = in.Get(); } CPFLink::CPFLink(CMemoryInStream& in) { - x0_node = in.readUint32Big(); - x4_region = in.readUint32Big(); - x8_2dWidth = in.readFloatBig(); - xc_oo2dWidth = in.readFloatBig(); + x0_node = in.ReadLong(); + x4_region = in.ReadLong(); + x8_2dWidth = in.ReadFloat(); + xc_oo2dWidth = in.ReadFloat(); } CPFRegion::CPFRegion(CMemoryInStream& in) { - x0_numNodes = in.readUint32Big(); - x4_startNode = reinterpret_cast(in.readUint32Big()); - x8_numLinks = in.readUint32Big(); - xc_startLink = reinterpret_cast(in.readUint32Big()); - x10_flags = in.readUint32Big(); - x14_height = in.readFloatBig(); - x18_normal.readBig(in); - x24_regionIdx = in.readUint32Big(); - x28_centroid.readBig(in); - x34_aabb.readBoundingBoxBig(in); - x4c_regionData = reinterpret_cast(in.readUint32Big()); + x0_numNodes = in.ReadLong(); + x4_startNode = reinterpret_cast(in.ReadLong()); + x8_numLinks = in.ReadLong(); + xc_startLink = reinterpret_cast(in.ReadLong()); + x10_flags = in.ReadLong(); + x14_height = in.ReadFloat(); + x18_normal = in.Get(); + x24_regionIdx = in.ReadLong(); + x28_centroid = in.Get(); + x34_aabb = in.Get(); + x4c_regionData = reinterpret_cast(in.ReadLong()); } const CPFLink* CPFRegion::GetPathLink() const { return &xc_startLink[x4c_regionData->GetPathLink()]; } diff --git a/Runtime/World/CPatternedInfo.cpp b/Runtime/World/CPatternedInfo.cpp index 48052d52a..57b839d5a 100644 --- a/Runtime/World/CPatternedInfo.cpp +++ b/Runtime/World/CPatternedInfo.cpp @@ -5,51 +5,51 @@ namespace metaforce { CPatternedInfo::CPatternedInfo(CInputStream& in, u32 pcount) -: x0_mass(in.readFloatBig()) -, x4_speed(in.readFloatBig()) -, x8_turnSpeed(in.readFloatBig()) -, xc_detectionRange(in.readFloatBig()) -, x10_detectionHeightRange(in.readFloatBig()) -, x14_dectectionAngle(in.readFloatBig()) -, x18_minAttackRange(in.readFloatBig()) -, x1c_maxAttackRange(in.readFloatBig()) -, x20_averageAttackTime(in.readFloatBig()) -, x24_attackTimeVariation(in.readFloatBig()) -, x28_leashRadius(in.readFloatBig()) -, x2c_playerLeashRadius(in.readFloatBig()) -, x30_playerLeashTime(in.readFloatBig()) +: x0_mass(in.ReadFloat()) +, x4_speed(in.ReadFloat()) +, x8_turnSpeed(in.ReadFloat()) +, xc_detectionRange(in.ReadFloat()) +, x10_detectionHeightRange(in.ReadFloat()) +, x14_dectectionAngle(in.ReadFloat()) +, x18_minAttackRange(in.ReadFloat()) +, x1c_maxAttackRange(in.ReadFloat()) +, x20_averageAttackTime(in.ReadFloat()) +, x24_attackTimeVariation(in.ReadFloat()) +, x28_leashRadius(in.ReadFloat()) +, x2c_playerLeashRadius(in.ReadFloat()) +, x30_playerLeashTime(in.ReadFloat()) , x34_contactDamageInfo(in) -, x50_damageWaitTime(in.readFloatBig()) +, x50_damageWaitTime(in.ReadFloat()) , x54_healthInfo(in) , x5c_damageVulnerability(in) -, xc4_halfExtent(in.readFloatBig()) -, xc8_height(in.readFloatBig()) -, xcc_bodyOrigin(zeus::CVector3f::ReadBig(in)) -, xd8_stepUpHeight(in.readFloatBig()) -, xdc_xDamage(in.readFloatBig()) -, xe0_frozenXDamage(in.readFloatBig()) -, xe4_xDamageDelay(in.readFloatBig()) -, xe8_deathSfx(CSfxManager::TranslateSFXID(in.readUint32Big())) +, xc4_halfExtent(in.ReadFloat()) +, xc8_height(in.ReadFloat()) +, xcc_bodyOrigin(in.Get()) +, xd8_stepUpHeight(in.ReadFloat()) +, xdc_xDamage(in.ReadFloat()) +, xe0_frozenXDamage(in.ReadFloat()) +, xe4_xDamageDelay(in.ReadFloat()) +, xe8_deathSfx(CSfxManager::TranslateSFXID(in.ReadLong())) , xec_animParams(in) -, xf8_active(in.readBool()) -, xfc_stateMachineId(in.readUint32Big()) -, x100_intoFreezeDur(in.readFloatBig()) -, x104_outofFreezeDur(in.readFloatBig()) -, x108_freezeDur(in.readFloatBig()) -, x10c_pathfindingIndex(in.readUint32Big()) -, x110_particle1Scale(zeus::CVector3f::ReadBig(in)) +, xf8_active(in.ReadBool()) +, xfc_stateMachineId(in.ReadLong()) +, x100_intoFreezeDur(in.ReadFloat()) +, x104_outofFreezeDur(in.ReadFloat()) +, x108_freezeDur(in.ReadFloat()) +, x10c_pathfindingIndex(in.ReadLong()) +, x110_particle1Scale(in.Get()) , x11c_particle1(in) , x120_electric(in) { if (pcount >= 36) - x124_particle2Scale.readBig(in); + x124_particle2Scale = in.Get(); if (pcount >= 37) - x130_particle2 = CAssetId(in); + x130_particle2 = in.Get(); if (pcount >= 38) - x134_iceShatterSfx = CSfxManager::TranslateSFXID(in.readUint32Big()); + x134_iceShatterSfx = CSfxManager::TranslateSFXID(in.ReadLong()); } std::pair CPatternedInfo::HasCorrectParameterCount(CInputStream& in) { - u32 pcount = in.readUint32Big(); + u32 pcount = in.ReadLong(); return {(pcount >= 35 && pcount <= 38), pcount}; } } // namespace metaforce diff --git a/Runtime/World/CPlayerCameraBob.cpp b/Runtime/World/CPlayerCameraBob.cpp index f7516d96f..c3b429d64 100644 --- a/Runtime/World/CPlayerCameraBob.cpp +++ b/Runtime/World/CPlayerCameraBob.cpp @@ -206,22 +206,19 @@ zeus::CTransform CPlayerCameraBob::CalculateCameraBobTransformation() const { } void CPlayerCameraBob::ReadTweaks(CInputStream& in) { - if (in.hasError()) - return; - - kCameraBobExtentX = in.readFloatBig(); - kCameraBobExtentY = in.readFloatBig(); - kCameraBobPeriod = in.readFloatBig(); - kOrbitBobScale = in.readFloatBig(); - kMaxOrbitBobScale = in.readFloatBig(); - kSlowSpeedPeriodScale = in.readFloatBig(); - kTargetMagnitudeTrackingRate = in.readFloatBig(); - kLandingBobSpringConstant = in.readFloatBig(); - kViewWanderRadius = in.readFloatBig(); - kViewWanderSpeedMin = in.readFloatBig(); - kViewWanderSpeedMax = in.readFloatBig(); - kViewWanderRollVariation = in.readFloatBig(); - kGunBobMagnitude = in.readFloatBig(); - kHelmetBobMagnitude = in.readFloatBig(); + kCameraBobExtentX = in.ReadFloat(); + kCameraBobExtentY = in.ReadFloat(); + kCameraBobPeriod = in.ReadFloat(); + kOrbitBobScale = in.ReadFloat(); + kMaxOrbitBobScale = in.ReadFloat(); + kSlowSpeedPeriodScale = in.ReadFloat(); + kTargetMagnitudeTrackingRate = in.ReadFloat(); + kLandingBobSpringConstant = in.ReadFloat(); + kViewWanderRadius = in.ReadFloat(); + kViewWanderSpeedMin = in.ReadFloat(); + kViewWanderSpeedMax = in.ReadFloat(); + kViewWanderRollVariation = in.ReadFloat(); + kGunBobMagnitude = in.ReadFloat(); + kHelmetBobMagnitude = in.ReadFloat(); } } // namespace metaforce diff --git a/Runtime/World/CScriptGunTurret.cpp b/Runtime/World/CScriptGunTurret.cpp index 46038af36..c483bacda 100644 --- a/Runtime/World/CScriptGunTurret.cpp +++ b/Runtime/World/CScriptGunTurret.cpp @@ -102,43 +102,43 @@ constexpr std::array skStateToLocoTypeLookup{ } // Anonymous namespace CScriptGunTurretData::CScriptGunTurretData(CInputStream& in, s32 propCount) -: x0_intoDeactivateDelay(in.readFloatBig()) -, x4_intoActivateDelay(in.readFloatBig()) -, x8_reloadTime(in.readFloatBig()) -, xc_reloadTimeVariance(in.readFloatBig()) -, x10_panStartTime(in.readFloatBig()) -, x14_panHoldTime(in.readFloatBig()) -, x1c_leftMaxAngle(zeus::degToRad(in.readFloatBig())) -, x20_rightMaxAngle(zeus::degToRad(in.readFloatBig())) -, x24_downMaxAngle(zeus::degToRad(in.readFloatBig())) -, x28_turnSpeed(zeus::degToRad(in.readFloatBig())) -, x2c_detectionRange(in.readFloatBig()) -, x30_detectionZRange(in.readFloatBig()) -, x34_freezeDuration(in.readFloatBig()) -, x38_freezeVariance(in.readFloatBig()) -, x3c_freezeTimeout(propCount >= 48 ? in.readBool() : false) +: x0_intoDeactivateDelay(in.ReadFloat()) +, x4_intoActivateDelay(in.ReadFloat()) +, x8_reloadTime(in.ReadFloat()) +, xc_reloadTimeVariance(in.ReadFloat()) +, x10_panStartTime(in.ReadFloat()) +, x14_panHoldTime(in.ReadFloat()) +, x1c_leftMaxAngle(zeus::degToRad(in.ReadFloat())) +, x20_rightMaxAngle(zeus::degToRad(in.ReadFloat())) +, x24_downMaxAngle(zeus::degToRad(in.ReadFloat())) +, x28_turnSpeed(zeus::degToRad(in.ReadFloat())) +, x2c_detectionRange(in.ReadFloat()) +, x30_detectionZRange(in.ReadFloat()) +, x34_freezeDuration(in.ReadFloat()) +, x38_freezeVariance(in.ReadFloat()) +, x3c_freezeTimeout(propCount >= 48 ? in.ReadBool() : false) , x40_projectileRes(in) , x44_projectileDamage(in) -, x60_idleLightRes(in.readUint32Big()) -, x64_deactivateLightRes(in.readUint32Big()) -, x68_targettingLightRes(in.readUint32Big()) -, x6c_frozenEffectRes(in.readUint32Big()) -, x70_chargingEffectRes(in.readUint32Big()) -, x74_panningEffectRes(in.readUint32Big()) -, x78_visorEffectRes(propCount >= 44 ? in.readUint32Big() : -1) -, x7c_trackingSoundId(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x7e_lockOnSoundId(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x80_unfreezeSoundId(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x82_stopClankSoundId(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x84_chargingSoundId(CSfxManager::TranslateSFXID(u16(in.readUint32Big()))) -, x86_visorSoundId(propCount >= 45 ? CSfxManager::TranslateSFXID(u16(in.readUint32Big())) : u16(0xFFFF)) -, x88_extensionModelResId(in.readUint32Big()) -, x8c_extensionDropDownDist(in.readFloatBig()) -, x90_numInitialShots(in.readUint32Big()) -, x94_initialShotTableIndex(in.readUint32Big()) -, x98_numSubsequentShots(in.readUint32Big()) -, x9c_frenzyDuration(propCount >= 47 ? in.readFloatBig() : 3.f) -, xa0_scriptedStartOnly(propCount >= 46 ? in.readBool() : false) {} +, x60_idleLightRes(in.Get()) +, x64_deactivateLightRes(in.Get()) +, x68_targettingLightRes(in.Get()) +, x6c_frozenEffectRes(in.Get()) +, x70_chargingEffectRes(in.Get()) +, x74_panningEffectRes(in.Get()) +, x78_visorEffectRes(propCount >= 44 ? in.Get() : -1) +, x7c_trackingSoundId(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x7e_lockOnSoundId(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x80_unfreezeSoundId(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x82_stopClankSoundId(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x84_chargingSoundId(CSfxManager::TranslateSFXID(u16(in.ReadLong()))) +, x86_visorSoundId(propCount >= 45 ? CSfxManager::TranslateSFXID(u16(in.ReadLong())) : u16(0xFFFF)) +, x88_extensionModelResId(in.ReadLong()) +, x8c_extensionDropDownDist(in.ReadFloat()) +, x90_numInitialShots(in.ReadLong()) +, x94_initialShotTableIndex(in.ReadLong()) +, x98_numSubsequentShots(in.ReadLong()) +, x9c_frenzyDuration(propCount >= 47 ? in.ReadFloat() : 3.f) +, xa0_scriptedStartOnly(propCount >= 46 ? in.ReadBool() : false) {} CScriptGunTurret::CScriptGunTurret(TUniqueId uid, std::string_view name, ETurretComponent comp, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabb, diff --git a/Runtime/World/CScriptMazeNode.cpp b/Runtime/World/CScriptMazeNode.cpp index 2502d9662..87defbd79 100644 --- a/Runtime/World/CScriptMazeNode.cpp +++ b/Runtime/World/CScriptMazeNode.cpp @@ -200,7 +200,7 @@ void CScriptMazeNode::LoadMazeSeeds() { const std::unique_ptr buf = g_ResFactory->LoadResourceSync(*tag); CMemoryInStream in(buf.get(), resSize); for (auto& seed : sMazeSeeds) { - seed = in.readInt32Big(); + seed = in.ReadInt32(); } } diff --git a/Runtime/World/CScriptSpindleCamera.cpp b/Runtime/World/CScriptSpindleCamera.cpp index 9a3becedd..9bb3228e6 100644 --- a/Runtime/World/CScriptSpindleCamera.cpp +++ b/Runtime/World/CScriptSpindleCamera.cpp @@ -12,12 +12,12 @@ namespace metaforce { SSpindleProperty::SSpindleProperty(CInputStream& in) { - x4_input = ESpindleInput(in.readUint32Big()); + x4_input = ESpindleInput(in.ReadLong()); x0_flags = ScriptLoader::LoadParameterFlags(in); - x8_lowOut = in.readFloatBig(); - xc_highOut = in.readFloatBig(); - x10_lowIn = in.readFloatBig(); - x14_highIn = in.readFloatBig(); + x8_lowOut = in.ReadFloat(); + xc_highOut = in.ReadFloat(); + x10_lowIn = in.ReadFloat(); + x14_highIn = in.ReadFloat(); switch (x4_input) { case ESpindleInput::HintBallAngle: case ESpindleInput::HintBallRightAngle: diff --git a/Runtime/World/CStateMachine.cpp b/Runtime/World/CStateMachine.cpp index 2127ce4ca..5d7c82cfe 100644 --- a/Runtime/World/CStateMachine.cpp +++ b/Runtime/World/CStateMachine.cpp @@ -12,20 +12,27 @@ logvisor::Module Log("metaforce::CStateMachine"); CStateMachine::CStateMachine(CInputStream& in) { CAiTrigger* lastTrig = nullptr; - u32 stateCount = in.readUint32Big(); + u32 stateCount = in.ReadLong(); x0_states.reserve(stateCount); for (u32 i = 0; i < stateCount; ++i) { - std::string name = in.readString(31, false); + std::string name; + while (name.size() < 31) { + const auto chr = in.ReadChar(); + name += chr; + if (chr == '\0') { + break; + } + } CAiStateFunc func = CAi::GetStateFunc(name); x0_states.emplace_back(func, name.c_str()); } - x10_triggers.reserve(in.readUint32Big()); + x10_triggers.reserve(in.ReadLong()); for (u32 i = 0; i < stateCount; ++i) { - x0_states[i].SetNumTriggers(in.readUint32Big()); + x0_states[i].SetNumTriggers(in.ReadLong()); if (x0_states[i].GetNumTriggers() == 0) continue; CAiTrigger* firstTrig = x10_triggers.data() + x10_triggers.size(); @@ -33,13 +40,21 @@ CStateMachine::CStateMachine(CInputStream& in) { x10_triggers.resize(x10_triggers.size() + x0_states[i].GetNumTriggers()); for (s32 j = 0; j < x0_states[i].GetNumTriggers(); ++j) { - const u32 triggerCount = in.readUint32Big(); + const u32 triggerCount = in.ReadLong(); const u32 lastTriggerIdx = triggerCount - 1; for (u32 k = 0; k < triggerCount; ++k) { - std::string name = in.readString(31, false); + std::string name; + while (name.size() < 31) { + const auto chr = in.ReadChar(); + name += chr; + if (chr == '\0') { + break; + } + } + const bool isNot = name.front() == '!'; const CAiTriggerFunc func = CAi::GetTriggerFunc(isNot ? name.c_str() + 1 : name.c_str()); - const float arg = in.readFloatBig(); + const float arg = in.ReadFloat(); CAiTrigger* newTrig; if (k < lastTriggerIdx) { newTrig = &x10_triggers.emplace_back(); @@ -47,7 +62,7 @@ CStateMachine::CStateMachine(CInputStream& in) { newTrig = &firstTrig[j]; } if (k == 0) - newTrig->Setup(func, isNot, arg, &x0_states[in.readUint32Big()]); + newTrig->Setup(func, isNot, arg, &x0_states[in.ReadLong()]); else newTrig->Setup(func, isNot, arg, lastTrig); lastTrig = newTrig; diff --git a/Runtime/World/CTeamAiMgr.cpp b/Runtime/World/CTeamAiMgr.cpp index d3dad318c..852e3e407 100644 --- a/Runtime/World/CTeamAiMgr.cpp +++ b/Runtime/World/CTeamAiMgr.cpp @@ -38,15 +38,15 @@ struct TeamAiRoleSorter { }; CTeamAiData::CTeamAiData(CInputStream& in, s32 propCount) -: x0_aiCount(in.readUint32Big()) -, x4_meleeCount(in.readUint32Big()) -, x8_rangedCount(in.readUint32Big()) -, xc_unknownCount(in.readUint32Big()) -, x10_maxMeleeAttackerCount(in.readUint32Big()) -, x14_maxRangedAttackerCount(in.readUint32Big()) -, x18_positionMode(in.readUint32Big()) -, x1c_meleeTimeInterval(propCount > 8 ? in.readFloatBig() : 0.f) -, x20_rangedTimeInterval(propCount > 8 ? in.readFloatBig() : 0.f) {} +: x0_aiCount(in.ReadLong()) +, x4_meleeCount(in.ReadLong()) +, x8_rangedCount(in.ReadLong()) +, xc_unknownCount(in.ReadLong()) +, x10_maxMeleeAttackerCount(in.ReadLong()) +, x14_maxRangedAttackerCount(in.ReadLong()) +, x18_positionMode(in.ReadLong()) +, x1c_meleeTimeInterval(propCount > 8 ? in.ReadFloat() : 0.f) +, x20_rangedTimeInterval(propCount > 8 ? in.ReadFloat() : 0.f) {} CTeamAiMgr::CTeamAiMgr(TUniqueId uid, std::string_view name, const CEntityInfo& info, const CTeamAiData& data) : CEntity(uid, info, true, name), x34_data(data) { diff --git a/Runtime/World/CVisorFlare.cpp b/Runtime/World/CVisorFlare.cpp index 0e49a8630..d06ce9210 100644 --- a/Runtime/World/CVisorFlare.cpp +++ b/Runtime/World/CVisorFlare.cpp @@ -10,14 +10,14 @@ namespace metaforce { std::optional CVisorFlare::LoadFlareDef(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount != 4) return std::nullopt; - CAssetId txtrId = in.readUint32Big(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - zeus::CColor color = zeus::CColor::ReadRGBABig(in); + CAssetId txtrId = in.Get(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + zeus::CColor color = in.Get(); if (!txtrId.IsValid()) return std::nullopt; diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index b26688dbf..36c9d8c8f 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -61,46 +61,46 @@ TAreaId CDummyWorld::IGetAreaId(CAssetId id) const { } CWorld::CRelay::CRelay(CInputStream& in) { - x0_relay = in.readUint32Big(); - x4_target = in.readUint32Big(); - x8_msg = in.readUint16Big(); - xa_active = in.readBool(); + x0_relay = in.ReadLong(); + x4_target = in.ReadLong(); + x8_msg = in.ReadShort(); + xa_active = in.ReadBool(); } -std::vector CWorld::CRelay::ReadMemoryRelays(athena::io::MemoryReader& r) { +std::vector CWorld::CRelay::ReadMemoryRelays(CInputStream& r) { std::vector ret; - u32 count = r.readUint32Big(); + u32 count = r.ReadLong(); ret.reserve(count); for (u32 i = 0; i < count; ++i) ret.emplace_back(r); return ret; } -std::optional CWorldLayers::ReadWorldLayers(athena::io::MemoryReader& r, int version, CAssetId mlvlId) { +std::optional CWorldLayers::ReadWorldLayers(CInputStream& r, int version, CAssetId mlvlId) { if (version <= 14) { return std::nullopt; } CWorldLayers ret; - u32 areaCount = r.readUint32Big(); + u32 areaCount = r.ReadLong(); ret.m_areas.reserve(areaCount); for (u32 i = 0; i < areaCount; ++i) { auto& area = ret.m_areas.emplace_back(); - area.m_layerCount = r.readUint32Big(); - area.m_layerBits = r.readUint64Big(); + area.m_layerCount = r.ReadLong(); + area.m_layerBits = r.ReadLongLong(); } - const u32 nameCount = r.readUint32Big(); + const u32 nameCount = r.ReadLong(); ret.m_names.reserve(nameCount); for (u32 i = 0; i < nameCount; ++i) { - auto name = r.readString(); + auto name = r.Get(); ret.m_names.emplace_back(name); } - areaCount = r.readUint32Big(); + areaCount = r.ReadLong(); for (u32 i = 0; i < areaCount; ++i) { - ret.m_areas[i].m_startNameIdx = r.readUint32Big(); + ret.m_areas[i].m_startNameIdx = r.ReadLong(); } CWorldState& wldState = g_GameState->StateForWorld(mlvlId); @@ -114,42 +114,42 @@ bool CDummyWorld::ICheckWorldComplete() { case Phase::Loading: { if (!x30_loadToken->IsComplete()) return false; - athena::io::MemoryReader r(x34_loadBuf.get(), x38_bufSz); - r.readUint32Big(); - int version = r.readUint32Big(); - x10_strgId = r.readUint32Big(); + CMemoryInStream r(x34_loadBuf.get(), x38_bufSz, CMemoryInStream::EOwnerShip::NotOwned); + r.ReadLong(); + int version = r.ReadLong(); + x10_strgId = r.ReadLong(); if (version >= 15) - x14_savwId = r.readUint32Big(); + x14_savwId = r.ReadLong(); if (version >= 12) - r.readUint32Big(); + r.ReadLong(); if (version >= 17) CWorld::CRelay::ReadMemoryRelays(r); - u32 areaCount = r.readUint32Big(); - r.readUint32Big(); + u32 areaCount = r.ReadLong(); + r.ReadLong(); x18_areas.reserve(areaCount); for (u32 i = 0; i < areaCount; ++i) x18_areas.emplace_back(r, i, version); - x28_mapWorldId = r.readUint32Big(); + x28_mapWorldId = r.ReadLong(); if (x4_loadMap) x2c_mapWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('MAPW'), x28_mapWorldId}); - r.readByte(); - r.readUint32Big(); + r.ReadInt8(); + r.ReadLong(); if (version > 10) { - u32 audioGroupCount = r.readUint32Big(); + u32 audioGroupCount = r.ReadLong(); for (u32 i = 0; i < audioGroupCount; ++i) { - r.readUint32Big(); - r.readUint32Big(); + r.ReadLong(); + r.ReadLong(); } } if (version > 12) - r.readString(); + r.Get(); m_worldLayers = CWorldLayers::ReadWorldLayers(r, version, xc_mlvlId); @@ -303,23 +303,23 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) case Phase::Loading: { if (!x3c_loadToken->IsComplete()) return false; - athena::io::MemoryReader r(x40_loadBuf.get(), x44_bufSz); - r.readUint32Big(); - int version = r.readUint32Big(); - xc_strgId = r.readUint32Big(); + CMemoryInStream r(x40_loadBuf.get(), x44_bufSz, CMemoryInStream::EOwnerShip::NotOwned); + r.ReadLong(); + int version = r.ReadLong(); + xc_strgId = r.ReadLong(); if (version >= 15) - x10_savwId = r.readUint32Big(); + x10_savwId = r.ReadLong(); if (version >= 12) { - CAssetId skyboxId = r.readUint32Big(); + CAssetId skyboxId = r.ReadLong(); if (skyboxId.IsValid() && mgr) x94_skyboxWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('CMDL'), skyboxId}); } if (version >= 17) x2c_relays = CWorld::CRelay::ReadMemoryRelays(r); - u32 areaCount = r.readUint32Big(); - r.readUint32Big(); + u32 areaCount = r.ReadLong(); + r.ReadLong(); x18_areas.reserve(areaCount); for (u32 i = 0; i < areaCount; ++i) { @@ -336,7 +336,7 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) for (std::unique_ptr& area : x18_areas) MoveToChain(area.get(), EChain::Deallocated); - x24_mapwId = r.readUint32Big(); + x24_mapwId = r.ReadLong(); x28_mapWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('MAPW'), x24_mapwId}); if (mgr) { @@ -346,17 +346,17 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) } if (version > 10) { - u32 audioGroupCount = r.readUint32Big(); + u32 audioGroupCount = r.ReadLong(); x74_soundGroupData.reserve(audioGroupCount); for (u32 i = 0; i < audioGroupCount; ++i) { - int grpId = r.readUint32Big(); - CAssetId agscId = r.readUint32Big(); + int grpId = r.ReadLong(); + CAssetId agscId = r.ReadLong(); x74_soundGroupData.emplace_back(grpId, agscId); } } if (version > 12) { - x84_defAudioTrack = r.readString(); + x84_defAudioTrack = r.Get(); std::string trackKey = fmt::format(FMT_STRING("WorldDefault: {}"), x8_mlvlId); if (g_TweakManager->HasTweakValue(trackKey)) x84_defAudioTrack = g_TweakManager->GetTweakValue(trackKey)->GetAudio().GetFileName(); diff --git a/Runtime/World/CWorld.hpp b/Runtime/World/CWorld.hpp index 5fa32f25c..bec6797fc 100644 --- a/Runtime/World/CWorld.hpp +++ b/Runtime/World/CWorld.hpp @@ -49,7 +49,7 @@ struct CWorldLayers { }; std::vector m_areas; std::vector m_names; - static std::optional ReadWorldLayers(athena::io::MemoryReader& r, int version, CAssetId mlvlId); + static std::optional ReadWorldLayers(CInputStream& r, int version, CAssetId mlvlId); }; class CDummyWorld : public IWorld { @@ -112,7 +112,7 @@ public: s16 GetMessage() const { return x8_msg; } bool GetActive() const { return xa_active; } - static std::vector ReadMemoryRelays(athena::io::MemoryReader& r); + static std::vector ReadMemoryRelays(CInputStream& r); }; struct CSoundGroupData { diff --git a/Runtime/World/CWorldLight.cpp b/Runtime/World/CWorldLight.cpp index 218a1d6c1..07034b7b6 100644 --- a/Runtime/World/CWorldLight.cpp +++ b/Runtime/World/CWorldLight.cpp @@ -1,20 +1,21 @@ #include "Runtime/World/CWorldLight.hpp" +#include "Runtime/IOStreams.hpp" #include namespace metaforce { CWorldLight::CWorldLight(CInputStream& in) -: x0_type(EWorldLightType(in.readUint32Big())) -, x4_color(zeus::CVector3f::ReadBig(in)) -, x10_position(zeus::CVector3f::ReadBig(in)) -, x1c_direction(zeus::CVector3f::ReadBig(in)) -, x28_q(in.readFloatBig()) -, x2c_cutoffAngle(in.readFloatBig()) -, x30_(in.readFloatBig()) -, x34_castShadows(in.readBool()) -, x38_(in.readFloatBig()) -, x3c_falloff(EFalloffType(in.readUint32Big())) -, x40_(in.readFloatBig()) {} +: x0_type(EWorldLightType(in.ReadLong())) +, x4_color(in.Get()) +, x10_position(in.Get()) +, x1c_direction(in.Get()) +, x28_q(in.ReadFloat()) +, x2c_cutoffAngle(in.ReadFloat()) +, x30_(in.ReadFloat()) +, x34_castShadows(in.ReadBool()) +, x38_(in.ReadFloat()) +, x3c_falloff(EFalloffType(in.ReadLong())) +, x40_(in.ReadFloat()) {} std::tuple CalculateLightFalloff(EFalloffType falloff, float q) { float constant = 0.f; diff --git a/Runtime/World/IGameArea.cpp b/Runtime/World/IGameArea.cpp index 82f98e1d9..283f16f0a 100644 --- a/Runtime/World/IGameArea.cpp +++ b/Runtime/World/IGameArea.cpp @@ -1,21 +1,21 @@ #include "Runtime/World/IGameArea.hpp" +#include "Runtime/IOStreams.hpp" namespace metaforce { IGameArea::Dock::Dock(metaforce::CInputStream& in, const zeus::CTransform& xf) { - u32 refCount = in.readUint32Big(); + u32 refCount = in.ReadLong(); x4_dockReferences.reserve(refCount); for (u32 i = 0; i < refCount; i++) { SDockReference ref; - ref.x0_area = in.readUint32Big(); - ref.x4_dock = in.readUint32Big(); + ref.x0_area = in.ReadLong(); + ref.x4_dock = in.ReadLong(); x4_dockReferences.push_back(ref); } - u32 vertCount = in.readUint32Big(); + u32 vertCount = in.ReadLong(); for (u32 i = 0; i < vertCount; i++) { - zeus::CVector3f vert; - vert.readBig(in); + zeus::CVector3f vert = in.Get(); x14_planeVertices.push_back(xf * vert); } } diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 3c59d0b25..235da747c 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -154,18 +154,14 @@ struct SScaledActorHead : SActorHead { }; static zeus::CTransform LoadEditorTransform(CInputStream& in) { - zeus::CVector3f position; - position.readBig(in); - zeus::CVector3f orientation; - orientation.readBig(in); + zeus::CVector3f position = in.Get(); + zeus::CVector3f orientation = in.Get(); return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position); } static zeus::CTransform LoadEditorTransformPivotOnly(CInputStream& in) { - zeus::CVector3f position; - position.readBig(in); - zeus::CVector3f orientation; - orientation.readBig(in); + zeus::CVector3f position = in.Get(); + zeus::CVector3f orientation = in.Get(); orientation.x() = 0.f; orientation.y() = 0.f; return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position); @@ -180,7 +176,7 @@ static SActorHead LoadActorHead(CInputStream& in, CStateManager& stateMgr) { static SScaledActorHead LoadScaledActorHead(CInputStream& in, CStateManager& stateMgr) { SScaledActorHead ret = LoadActorHead(in, stateMgr); - ret.x40_scale.readBig(in); + ret.x40_scale = in.Get(); return ret; } @@ -192,32 +188,32 @@ static zeus::CAABox GetCollisionBox(CStateManager& stateMgr, TAreaId id, const z } u32 ScriptLoader::LoadParameterFlags(CInputStream& in) { - u32 count = in.readUint32Big(); + u32 count = in.ReadLong(); u32 ret = 0; for (u32 i = 0; i < count; ++i) - if (in.readBool()) + if (in.ReadBool()) ret |= 1 << i; return ret; } CGrappleParameters ScriptLoader::LoadGrappleParameters(CInputStream& in) { - float a = in.readFloatBig(); - float b = in.readFloatBig(); - float c = in.readFloatBig(); - float d = in.readFloatBig(); - float e = in.readFloatBig(); - float f = in.readFloatBig(); - float g = in.readFloatBig(); - float h = in.readFloatBig(); - float i = in.readFloatBig(); - float j = in.readFloatBig(); - float k = in.readFloatBig(); - bool l = in.readBool(); + float a = in.ReadFloat(); + float b = in.ReadFloat(); + float c = in.ReadFloat(); + float d = in.ReadFloat(); + float e = in.ReadFloat(); + float f = in.ReadFloat(); + float g = in.ReadFloat(); + float h = in.ReadFloat(); + float i = in.ReadFloat(); + float j = in.ReadFloat(); + float k = in.ReadFloat(); + bool l = in.ReadBool(); return CGrappleParameters(a, b, c, d, e, f, g, h, i, j, k, l); } CActorParameters ScriptLoader::LoadActorParameters(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount >= 5 && propCount <= 0xe) { CLightParameters lParms = ScriptLoader::LoadLightParameters(in); @@ -225,22 +221,22 @@ CActorParameters ScriptLoader::LoadActorParameters(CInputStream& in) { if (propCount > 5) sParams = LoadScannableParameters(in); - CAssetId xrayModel = in.readUint32Big(); - CAssetId xraySkin = in.readUint32Big(); - CAssetId infraModel = in.readUint32Big(); - CAssetId infraSkin = in.readUint32Big(); + CAssetId xrayModel = in.ReadLong(); + CAssetId xraySkin = in.ReadLong(); + CAssetId infraModel = in.ReadLong(); + CAssetId infraSkin = in.ReadLong(); bool globalTimeProvider = true; if (propCount > 7) - globalTimeProvider = in.readBool(); + globalTimeProvider = in.ReadBool(); float fadeInTime = 1.f; if (propCount > 8) - fadeInTime = in.readFloatBig(); + fadeInTime = in.ReadFloat(); float fadeOutTime = 1.f; if (propCount > 9) - fadeOutTime = in.readFloatBig(); + fadeOutTime = in.ReadFloat(); CVisorParameters vParms; if (propCount > 6) @@ -248,19 +244,19 @@ CActorParameters ScriptLoader::LoadActorParameters(CInputStream& in) { bool thermalHeat = false; if (propCount > 10) - thermalHeat = in.readBool(); + thermalHeat = in.ReadBool(); bool renderUnsorted = false; if (propCount > 11) - renderUnsorted = in.readBool(); + renderUnsorted = in.ReadBool(); bool noSortThermal = false; if (propCount > 12) - noSortThermal = in.readBool(); + noSortThermal = in.ReadBool(); float thermalMag = 1.f; if (propCount > 13) - thermalMag = in.readFloatBig(); + thermalMag = in.ReadFloat(); std::pair xray = {}; if (g_ResFactory->GetResourceTypeById(xrayModel).IsValid()) @@ -277,61 +273,59 @@ CActorParameters ScriptLoader::LoadActorParameters(CInputStream& in) { } CVisorParameters ScriptLoader::LoadVisorParameters(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount >= 1 && propCount <= 3) { - bool b1 = in.readBool(); + bool b1 = in.ReadBool(); bool scanPassthrough = false; u8 mask = 0xf; if (propCount > 2) - scanPassthrough = in.readBool(); + scanPassthrough = in.ReadBool(); if (propCount >= 2) - mask = u8(in.readUint32Big()); + mask = u8(in.ReadLong()); return CVisorParameters(mask, b1, scanPassthrough); } return CVisorParameters(); } CScannableParameters ScriptLoader::LoadScannableParameters(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount == 1) - return CScannableParameters(in.readUint32Big()); + return CScannableParameters(in.ReadLong()); return CScannableParameters(); } CLightParameters ScriptLoader::LoadLightParameters(CInputStream& in) { - u32 propCount = in.readUint32Big(); + u32 propCount = in.ReadLong(); if (propCount == 14) { - bool a = in.readBool(); - float b = in.readFloatBig(); - CLightParameters::EShadowTesselation shadowTess = CLightParameters::EShadowTesselation(in.readUint32Big()); - float d = in.readFloatBig(); - float e = in.readFloatBig(); + bool a = in.ReadBool(); + float b = in.ReadFloat(); + CLightParameters::EShadowTesselation shadowTess = CLightParameters::EShadowTesselation(in.ReadLong()); + float d = in.ReadFloat(); + float e = in.ReadFloat(); - zeus::CColor noLightsAmbient; - noLightsAmbient.readRGBABig(in); + zeus::CColor noLightsAmbient = in.Get(); - bool makeLights = in.readBool(); - CLightParameters::EWorldLightingOptions lightOpts = CLightParameters::EWorldLightingOptions(in.readUint32Big()); + bool makeLights = in.ReadBool(); + CLightParameters::EWorldLightingOptions lightOpts = CLightParameters::EWorldLightingOptions(in.ReadLong()); CLightParameters::ELightRecalculationOptions recalcOpts = - CLightParameters::ELightRecalculationOptions(in.readUint32Big()); + CLightParameters::ELightRecalculationOptions(in.ReadLong()); - zeus::CVector3f actorPosBias; - actorPosBias.readBig(in); + zeus::CVector3f actorPosBias = in.Get(); s32 maxDynamicLights = -1; s32 maxAreaLights = -1; if (propCount >= 12) { - maxDynamicLights = in.readUint32Big(); - maxAreaLights = in.readUint32Big(); + maxDynamicLights = in.ReadLong(); + maxAreaLights = in.ReadLong(); } bool ambientChannelOverflow = false; if (propCount >= 13) - ambientChannelOverflow = in.readBool(); + ambientChannelOverflow = in.ReadBool(); s32 layerIdx = 0; if (propCount >= 14) - layerIdx = in.readUint32Big(); + layerIdx = in.ReadLong(); return CLightParameters(a, b, shadowTess, d, e, noLightsAmbient, makeLights, lightOpts, recalcOpts, actorPosBias, maxDynamicLights, maxAreaLights, ambientChannelOverflow, layerIdx); @@ -340,39 +334,39 @@ CLightParameters ScriptLoader::LoadLightParameters(CInputStream& in) { } CAnimationParameters ScriptLoader::LoadAnimationParameters(CInputStream& in) { - CAssetId ancs = in.readUint32Big(); - s32 charIdx = in.readUint32Big(); - u32 defaultAnim = in.readUint32Big(); + CAssetId ancs = in.ReadLong(); + s32 charIdx = in.ReadLong(); + u32 defaultAnim = in.ReadLong(); return CAnimationParameters(ancs, charIdx, defaultAnim); } CFluidUVMotion ScriptLoader::LoadFluidUVMotion(CInputStream& in) { - auto motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); - float a = in.readFloatBig(); - float b = in.readFloatBig(); + auto motion = CFluidUVMotion::EFluidUVMotion(in.ReadLong()); + float a = in.ReadFloat(); + float b = in.ReadFloat(); b = zeus::degToRad(b) - M_PIF; - float c = in.readFloatBig(); - float d = in.readFloatBig(); + float c = in.ReadFloat(); + float d = in.ReadFloat(); CFluidUVMotion::SFluidLayerMotion pattern1Layer(motion, a, b, c, d); - motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); - a = in.readFloatBig(); - b = in.readFloatBig(); + motion = CFluidUVMotion::EFluidUVMotion(in.ReadLong()); + a = in.ReadFloat(); + b = in.ReadFloat(); b = zeus::degToRad(b) - M_PIF; - c = in.readFloatBig(); - d = in.readFloatBig(); + c = in.ReadFloat(); + d = in.ReadFloat(); CFluidUVMotion::SFluidLayerMotion pattern2Layer(motion, a, b, c, d); - motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); - a = in.readFloatBig(); - b = in.readFloatBig(); + motion = CFluidUVMotion::EFluidUVMotion(in.ReadLong()); + a = in.ReadFloat(); + b = in.ReadFloat(); b = zeus::degToRad(b) - M_PIF; - c = in.readFloatBig(); - d = in.readFloatBig(); + c = in.ReadFloat(); + d = in.ReadFloat(); CFluidUVMotion::SFluidLayerMotion colorLayer(motion, a, b, c, d); - a = in.readFloatBig(); - b = in.readFloatBig(); + a = in.ReadFloat(); + b = in.ReadFloat(); b = zeus::degToRad(b) - M_PIF; @@ -393,35 +387,33 @@ CEntity* ScriptLoader::LoadActor(CStateManager& mgr, CInputStream& in, int propC SScaledActorHead head = LoadScaledActorHead(in, mgr); - zeus::CVector3f collisionExtent; - collisionExtent.readBig(in); + zeus::CVector3f collisionExtent = in.Get(); - zeus::CVector3f centroid; - centroid.readBig(in); + zeus::CVector3f centroid = in.Get(); - float mass = in.readFloatBig(); - float zMomentum = in.readFloatBig(); + float mass = in.ReadFloat(); + float zMomentum = in.ReadFloat(); CHealthInfo hInfo(in); CDamageVulnerability dVuln(in); - CAssetId staticId = in.readUint32Big(); + CAssetId staticId = in.ReadLong(); CAnimationParameters aParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - bool looping = in.readBool(); - bool immovable = in.readBool(); - bool solid = in.readBool(); - bool cameraPassthrough = in.readBool(); - bool active = in.readBool(); - u32 shaderIdx = in.readUint32Big(); - float xrayAlpha = in.readFloatBig(); - bool noThermalHotZ = in.readBool(); - bool castsShadow = in.readBool(); - bool scaleAdvancementDelta = in.readBool(); - bool materialFlag54 = in.readBool(); + bool looping = in.ReadBool(); + bool immovable = in.ReadBool(); + bool solid = in.ReadBool(); + bool cameraPassthrough = in.ReadBool(); + bool active = in.ReadBool(); + u32 shaderIdx = in.ReadLong(); + float xrayAlpha = in.ReadFloat(); + bool noThermalHotZ = in.ReadBool(); + bool castsShadow = in.ReadBool(); + bool scaleAdvancementDelta = in.ReadBool(); + bool materialFlag54 = in.ReadBool(); FourCC animType = g_ResFactory->GetResourceTypeById(aParms.GetACSFile()); if (!g_ResFactory->GetResourceTypeById(staticId).IsValid() && !animType.IsValid()) @@ -461,16 +453,16 @@ CEntity* ScriptLoader::LoadWaypoint(CStateManager& mgr, CInputStream& in, int pr SActorHead head = LoadActorHead(in, mgr); - bool active = in.readBool(); - float speed = in.readFloatBig(); - float pause = in.readFloatBig(); - u32 patternTranslate = in.readUint32Big(); - u32 patternOrient = in.readUint32Big(); - u32 patternFit = in.readUint32Big(); - u32 behaviour = in.readUint32Big(); - u32 behaviourOrient = in.readUint32Big(); - u32 behaviourModifiers = in.readUint32Big(); - u32 animation = in.readUint32Big(); + bool active = in.ReadBool(); + float speed = in.ReadFloat(); + float pause = in.ReadFloat(); + u32 patternTranslate = in.ReadLong(); + u32 patternOrient = in.ReadLong(); + u32 patternFit = in.ReadLong(); + u32 behaviour = in.ReadLong(); + u32 behaviourOrient = in.ReadLong(); + u32 behaviourModifiers = in.ReadLong(); + u32 animation = in.ReadLong(); return new CScriptWaypoint(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, active, speed, pause, patternTranslate, patternOrient, patternFit, behaviour, behaviourOrient, @@ -485,17 +477,14 @@ CEntity* ScriptLoader::LoadDoor(CStateManager& mgr, CInputStream& in, int propCo CAnimationParameters aParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - zeus::CVector3f orbitPos; - orbitPos.readBig(in); - zeus::CVector3f collisionExtent; - collisionExtent.readBig(in); - zeus::CVector3f offset; - offset.readBig(in); + zeus::CVector3f orbitPos = in.Get(); + zeus::CVector3f collisionExtent = in.Get(); + zeus::CVector3f offset = in.Get(); - bool active = in.readBool(); - bool open = in.readBool(); - bool projectilesCollide = in.readBool(); - float animationLength = in.readFloatBig(); + bool active = in.ReadBool(); + bool open = in.ReadBool(); + bool projectilesCollide = in.ReadBool(); + float animationLength = in.ReadFloat(); zeus::CAABox aabb = GetCollisionBox(mgr, info.GetAreaId(), collisionExtent, offset); @@ -511,7 +500,7 @@ CEntity* ScriptLoader::LoadDoor(CStateManager& mgr, CInputStream& in, int propCo if (aParms.GetACSFile() == MorphballDoorANCS.id) isMorphballDoor = true; } else if (propCount == 14) - isMorphballDoor = in.readBool(); + isMorphballDoor = in.ReadBool(); return new CScriptDoor(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, std::move(mData), actParms, orbitPos, aabb, active, open, projectilesCollide, animationLength, isMorphballDoor); @@ -523,18 +512,18 @@ CEntity* ScriptLoader::LoadTrigger(CStateManager& mgr, CInputStream& in, int pro std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position = zeus::CVector3f::ReadBig(in); + zeus::CVector3f position = in.Get(); - zeus::CVector3f extent = zeus::CVector3f::ReadBig(in); + zeus::CVector3f extent = in.Get(); CDamageInfo dInfo(in); - zeus::CVector3f forceVec = zeus::CVector3f::ReadBig(in); + zeus::CVector3f forceVec = in.Get(); - ETriggerFlags flags = ETriggerFlags(in.readUint32Big()); - bool active = in.readBool(); - bool b2 = in.readBool(); - bool b3 = in.readBool(); + ETriggerFlags flags = ETriggerFlags(in.ReadLong()); + bool active = in.ReadBool(); + bool b2 = in.ReadBool(); + bool b3 = in.ReadBool(); zeus::CAABox box(-extent * 0.5f, extent * 0.5f); @@ -551,11 +540,11 @@ CEntity* ScriptLoader::LoadTimer(CStateManager& mgr, CInputStream& in, int propC std::string name = mgr.HashInstanceName(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - bool b1 = in.readBool(); - bool b2 = in.readBool(); - bool b3 = in.readBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + bool b1 = in.ReadBool(); + bool b2 = in.ReadBool(); + bool b3 = in.ReadBool(); return new CScriptTimer(mgr.AllocateUniqueId(), name, info, f1, f2, b1, b2, b3); } @@ -566,10 +555,10 @@ CEntity* ScriptLoader::LoadCounter(CStateManager& mgr, CInputStream& in, int pro std::string name = mgr.HashInstanceName(in); - u32 initial = in.readUint32Big(); - u32 max = in.readUint32Big(); - bool autoReset = in.readBool(); - bool active = in.readBool(); + u32 initial = in.ReadLong(); + u32 max = in.ReadLong(); + bool autoReset = in.ReadBool(); + bool active = in.ReadBool(); return new CScriptCounter(mgr.AllocateUniqueId(), name, info, initial, max, autoReset, active); } @@ -582,10 +571,10 @@ CEntity* ScriptLoader::LoadEffect(CStateManager& mgr, CInputStream& in, int prop CAssetId partId(in); CAssetId elscId(in); - bool hotInThermal = in.readBool(); - bool noTimerUnlessAreaOccluded = in.readBool(); - bool rebuildSystemsOnActivate = in.readBool(); - bool active = in.readBool(); + bool hotInThermal = in.ReadBool(); + bool noTimerUnlessAreaOccluded = in.ReadBool(); + bool rebuildSystemsOnActivate = in.ReadBool(); + bool active = in.ReadBool(); if (!partId.IsValid() && !elscId.IsValid()) return nullptr; @@ -593,19 +582,19 @@ CEntity* ScriptLoader::LoadEffect(CStateManager& mgr, CInputStream& in, int prop if (!g_ResFactory->GetResourceTypeById(partId).IsValid() && !g_ResFactory->GetResourceTypeById(elscId).IsValid()) return nullptr; - bool useRateInverseCamDist = in.readBool(); - float rateInverseCamDist = in.readFloatBig(); - float rateInverseCamDistRate = in.readFloatBig(); - float duration = in.readFloatBig(); - float durationResetWhileVisible = in.readFloatBig(); - bool useRateCamDistRange = in.readBool(); - float rateCamDistRangeMin = in.readFloatBig(); - float rateCamDistRangeMax = in.readFloatBig(); - float rateCamDistRangeFarRate = in.readFloatBig(); - bool combatVisorVisible = in.readBool(); - bool thermalVisorVisible = in.readBool(); - bool xrayVisorVisible = in.readBool(); - bool dieWhenSystemsDone = in.readBool(); + bool useRateInverseCamDist = in.ReadBool(); + float rateInverseCamDist = in.ReadFloat(); + float rateInverseCamDistRate = in.ReadFloat(); + float duration = in.ReadFloat(); + float durationResetWhileVisible = in.ReadFloat(); + bool useRateCamDistRange = in.ReadBool(); + float rateCamDistRangeMin = in.ReadFloat(); + float rateCamDistRangeMax = in.ReadFloat(); + float rateCamDistRangeFarRate = in.ReadFloat(); + bool combatVisorVisible = in.ReadBool(); + bool thermalVisorVisible = in.ReadBool(); + bool xrayVisorVisible = in.ReadBool(); + bool dieWhenSystemsDone = in.ReadBool(); CLightParameters lParms = LoadLightParameters(in); @@ -623,30 +612,28 @@ CEntity* ScriptLoader::LoadPlatform(CStateManager& mgr, CInputStream& in, int pr SScaledActorHead head = LoadScaledActorHead(in, mgr); - zeus::CVector3f extent; - extent.readBig(in); + zeus::CVector3f extent = in.Get(); - zeus::CVector3f centroid; - centroid.readBig(in); + zeus::CVector3f centroid = in.Get(); - CAssetId staticId = in.readUint32Big(); + CAssetId staticId = in.Get(); CAnimationParameters aParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - float speed = in.readFloatBig(); - bool active = in.readBool(); - CAssetId dclnId = in.readUint32Big(); + float speed = in.ReadFloat(); + bool active = in.ReadBool(); + CAssetId dclnId = in.ReadLong(); CHealthInfo hInfo(in); CDamageVulnerability dInfo(in); - bool detectCollision = in.readBool(); - float xrayAlpha = in.readFloatBig(); - bool rainSplashes = in.readBool(); - u32 maxRainSplashes = in.readUint32Big(); - u32 rainGenRate = in.readUint32Big(); + bool detectCollision = in.ReadBool(); + float xrayAlpha = in.ReadFloat(); + bool rainSplashes = in.ReadBool(); + u32 maxRainSplashes = in.ReadLong(); + u32 rainGenRate = in.ReadLong(); FourCC animType = g_ResFactory->GetResourceTypeById(aParms.GetACSFile()); if (!g_ResFactory->GetResourceTypeById(staticId).IsValid() && !animType.IsValid()) @@ -682,23 +669,23 @@ CEntity* ScriptLoader::LoadSound(CStateManager& mgr, CInputStream& in, int propC return nullptr; SActorHead head = LoadActorHead(in, mgr); - s32 soundId = in.readInt32Big(); - bool active = in.readBool(); - float maxDist = in.readFloatBig(); - float distComp = in.readFloatBig(); - float startDelay = in.readFloatBig(); - u32 minVol = in.readUint32Big(); - u32 vol = in.readUint32Big(); - u32 prio = in.readUint32Big(); - u32 pan = in.readUint32Big(); - bool loop = in.readBool(); - bool nonEmitter = in.readBool(); - bool autoStart = in.readBool(); - bool occlusionTest = in.readBool(); - bool acoustics = in.readBool(); - bool worldSfx = in.readBool(); - bool allowDuplicates = in.readBool(); - s32 pitch = in.readInt32Big(); + s32 soundId = in.ReadInt32(); + bool active = in.ReadBool(); + float maxDist = in.ReadFloat(); + float distComp = in.ReadFloat(); + float startDelay = in.ReadFloat(); + u32 minVol = in.ReadLong(); + u32 vol = in.ReadLong(); + u32 prio = in.ReadLong(); + u32 pan = in.ReadLong(); + bool loop = in.ReadBool(); + bool nonEmitter = in.ReadBool(); + bool autoStart = in.ReadBool(); + bool occlusionTest = in.ReadBool(); + bool acoustics = in.ReadBool(); + bool worldSfx = in.ReadBool(); + bool allowDuplicates = in.ReadBool(); + s32 pitch = in.ReadInt32(); if (soundId < 0) { Log.report(logvisor::Warning, FMT_STRING("Invalid sound ID specified in Sound {} ({}), dropping..."), head.x0_name, @@ -717,15 +704,15 @@ CEntity* ScriptLoader::LoadGenerator(CStateManager& mgr, CInputStream& in, int p std::string name = mgr.HashInstanceName(in); - u32 spawnCount = in.readUint32Big(); - bool noReuseFollowers = in.readBool(); - bool noInheritXf = in.readBool(); + u32 spawnCount = in.ReadLong(); + bool noReuseFollowers = in.ReadBool(); + bool noInheritXf = in.ReadBool(); - zeus::CVector3f offset = zeus::CVector3f::ReadBig(in); + zeus::CVector3f offset = in.Get(); - bool active = in.readBool(); - float minScale = in.readFloatBig(); - float maxScale = in.readFloatBig(); + bool active = in.ReadBool(); + float minScale = in.ReadFloat(); + float maxScale = in.ReadFloat(); return new CScriptGenerator(mgr.AllocateUniqueId(), name, info, spawnCount, noReuseFollowers, offset, noInheritXf, active, minScale, maxScale); @@ -736,14 +723,12 @@ CEntity* ScriptLoader::LoadDock(CStateManager& mgr, CInputStream& in, int propCo return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - zeus::CVector3f position; - position.readBig(in); - zeus::CVector3f scale; - scale.readBig(in); - u32 dock = in.readUint32Big(); - TAreaId area = in.readUint32Big(); - bool loadConnected = in.readBool(); + bool active = in.ReadBool(); + zeus::CVector3f position = in.Get(); + zeus::CVector3f scale = in.Get(); + u32 dock = in.ReadLong(); + TAreaId area = in.ReadLong(); + bool loadConnected = in.ReadBool(); return new CScriptDock(mgr.AllocateUniqueId(), name, info, position, scale, dock, area, active, 0, loadConnected); } @@ -753,21 +738,21 @@ CEntity* ScriptLoader::LoadCamera(CStateManager& mgr, CInputStream& in, int prop SActorHead head = LoadActorHead(in, mgr); - bool active = in.readBool(); - float shotDuration = in.readFloatBig(); - bool lookAtPlayer = in.readBool(); - bool outOfPlayerEye = in.readBool(); - bool intoPlayerEye = in.readBool(); - bool drawPlayer = in.readBool(); - bool disableInput = in.readBool(); - bool b7 = in.readBool(); - bool finishCineSkip = in.readBool(); - float fov = in.readFloatBig(); - bool checkFailsafe = in.readBool(); + bool active = in.ReadBool(); + float shotDuration = in.ReadFloat(); + bool lookAtPlayer = in.ReadBool(); + bool outOfPlayerEye = in.ReadBool(); + bool intoPlayerEye = in.ReadBool(); + bool drawPlayer = in.ReadBool(); + bool disableInput = in.ReadBool(); + bool b7 = in.ReadBool(); + bool finishCineSkip = in.ReadBool(); + float fov = in.ReadFloat(); + bool checkFailsafe = in.ReadBool(); bool disableOutOfInto = false; if (propCount > 14) - disableOutOfInto = in.readBool(); + disableOutOfInto = in.ReadBool(); s32 flags = s32(lookAtPlayer) | s32(outOfPlayerEye) << 1 | s32(intoPlayerEye) << 2 | s32(b7) << 3 | s32(finishCineSkip) << 4 | s32(disableInput) << 5 | s32(drawPlayer) << 6 | s32(checkFailsafe) << 7 | @@ -785,9 +770,9 @@ CEntity* ScriptLoader::LoadCameraWaypoint(CStateManager& mgr, CInputStream& in, SActorHead head = LoadActorHead(in, mgr); - bool active = in.readBool(); - float f1 = in.readFloatBig(); - u32 w1 = in.readUint32Big(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); + u32 w1 = in.ReadLong(); return new CScriptCameraWaypoint(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, active, f1, w1); } @@ -806,7 +791,7 @@ CEntity* ScriptLoader::LoadNewIntroBoss(CStateManager& mgr, CInputStream& in, in CActorParameters actParms = LoadActorParameters(in); - float minTurnAngle = in.readFloatBig(); + float minTurnAngle = in.ReadFloat(); CAssetId projectile(in); CDamageInfo dInfo(in); @@ -834,22 +819,20 @@ CEntity* ScriptLoader::LoadSpawnPoint(CStateManager& mgr, CInputStream& in, int std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position; - position.readBig(in); + zeus::CVector3f position = in.Get(); - zeus::CVector3f rotation; - rotation.readBig(in); + zeus::CVector3f rotation = in.Get(); rstl::reserved_vector itemCounts; itemCounts.resize(size_t(CPlayerState::EItemType::Max), 0); for (int i = 0; i < propCount - 6; ++i) - itemCounts[i] = in.readUint32Big(); + itemCounts[i] = in.ReadLong(); - bool defaultSpawn = in.readBool(); - bool active = in.readBool(); + bool defaultSpawn = in.ReadBool(); + bool active = in.ReadBool(); bool morphed = false; if (propCount > 34) - morphed = in.readBool(); + morphed = in.ReadBool(); return new CScriptSpawnPoint(mgr.AllocateUniqueId(), name, info, ConvertEditorEulerToTransform4f(rotation, position), itemCounts, defaultSpawn, active, morphed); @@ -863,39 +846,36 @@ CEntity* ScriptLoader::LoadCameraHint(CStateManager& mgr, CInputStream& in, int SActorHead head = LoadActorHead(in, mgr); - bool active = in.readBool(); - u32 prio = in.readUint32Big(); - auto behaviour = CBallCamera::EBallCameraBehaviour(in.readUint32Big()); + bool active = in.ReadBool(); + u32 prio = in.ReadLong(); + auto behaviour = CBallCamera::EBallCameraBehaviour(in.ReadLong()); u32 overrideFlags = LoadParameterFlags(in); - overrideFlags |= in.readBool() << 22; - float minDist = in.readFloatBig(); - overrideFlags |= in.readBool() << 23; - float maxDist = in.readFloatBig(); - overrideFlags |= in.readBool() << 24; - float backwardsDist = in.readFloatBig(); - overrideFlags |= in.readBool() << 25; - zeus::CVector3f lookAtOffset; - lookAtOffset.readBig(in); - overrideFlags |= in.readBool() << 26; - zeus::CVector3f chaseLookAtOffset; - chaseLookAtOffset.readBig(in); - zeus::CVector3f ballToCam; - ballToCam.readBig(in); - overrideFlags |= in.readBool() << 27; - float fov = in.readFloatBig(); - overrideFlags |= in.readBool() << 28; - float attitudeRange = zeus::degToRad(in.readFloatBig()); - overrideFlags |= in.readBool() << 29; - float azimuthRange = zeus::degToRad(in.readFloatBig()); - overrideFlags |= in.readBool() << 30; - float anglePerSecond = zeus::degToRad(in.readFloatBig()); - float clampVelRange = in.readFloatBig(); - float clampRotRange = zeus::degToRad(in.readFloatBig()); - overrideFlags |= in.readBool() << 31; - float elevation = in.readFloatBig(); - float interpolateTime = in.readFloatBig(); - float clampVelTime = in.readFloatBig(); - float controlInterpDur = in.readFloatBig(); + overrideFlags |= in.ReadBool() << 22; + float minDist = in.ReadFloat(); + overrideFlags |= in.ReadBool() << 23; + float maxDist = in.ReadFloat(); + overrideFlags |= in.ReadBool() << 24; + float backwardsDist = in.ReadFloat(); + overrideFlags |= in.ReadBool() << 25; + zeus::CVector3f lookAtOffset = in.Get(); + overrideFlags |= in.ReadBool() << 26; + zeus::CVector3f chaseLookAtOffset = in.Get(); + zeus::CVector3f ballToCam = in.Get(); + overrideFlags |= in.ReadBool() << 27; + float fov = in.ReadFloat(); + overrideFlags |= in.ReadBool() << 28; + float attitudeRange = zeus::degToRad(in.ReadFloat()); + overrideFlags |= in.ReadBool() << 29; + float azimuthRange = zeus::degToRad(in.ReadFloat()); + overrideFlags |= in.ReadBool() << 30; + float anglePerSecond = zeus::degToRad(in.ReadFloat()); + float clampVelRange = in.ReadFloat(); + float clampRotRange = zeus::degToRad(in.ReadFloat()); + overrideFlags |= in.ReadBool() << 31; + float elevation = in.ReadFloat(); + float interpolateTime = in.ReadFloat(); + float clampVelTime = in.ReadFloat(); + float controlInterpDur = in.ReadFloat(); return new CScriptCameraHint(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, active, prio, behaviour, overrideFlags, minDist, maxDist, backwardsDist, lookAtOffset, chaseLookAtOffset, @@ -908,19 +888,19 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop return nullptr; SScaledActorHead head = LoadScaledActorHead(in, mgr); - zeus::CVector3f extent = zeus::CVector3f::ReadBig(in); - zeus::CVector3f offset = zeus::CVector3f::ReadBig(in); - CPlayerState::EItemType itemType = CPlayerState::EItemType(in.readUint32Big()); - u32 capacity = in.readUint32Big(); - u32 amount = in.readUint32Big(); - float possibility = in.readFloatBig(); - float lifeTime = in.readFloatBig(); - float fadeInTime = in.readFloatBig(); - CAssetId staticModel = in.readUint32Big(); + zeus::CVector3f extent = in.Get(); + zeus::CVector3f offset = in.Get(); + CPlayerState::EItemType itemType = CPlayerState::EItemType(in.ReadLong()); + u32 capacity = in.ReadLong(); + u32 amount = in.ReadLong(); + float possibility = in.ReadFloat(); + float lifeTime = in.ReadFloat(); + float fadeInTime = in.ReadFloat(); + CAssetId staticModel = in.ReadLong(); CAnimationParameters animParms = LoadAnimationParameters(in); CActorParameters actorParms = LoadActorParameters(in); - bool active = in.readBool(); - float startDelay = in.readFloatBig(); + bool active = in.ReadBool(); + float startDelay = in.ReadFloat(); CAssetId pickupEffect(in); FourCC acsType = g_ResFactory->GetResourceTypeById(animParms.GetACSFile()); @@ -952,11 +932,11 @@ CEntity* ScriptLoader::LoadMemoryRelay(CStateManager& mgr, CInputStream& in, int return nullptr; std::string name = mgr.HashInstanceName(in); - bool b1 = in.readBool(); - bool b2 = in.readBool(); + bool b1 = in.ReadBool(); + bool b2 = in.ReadBool(); bool b3 = false; if (propCount > 3) - b3 = in.readBool(); + b3 = in.ReadBool(); return new CScriptMemoryRelay(mgr.AllocateUniqueId(), name, info, b1, b2, b3); } @@ -965,10 +945,10 @@ CEntity* ScriptLoader::LoadRandomRelay(CStateManager& mgr, CInputStream& in, int if (!EnsurePropertyCount(propCount, 5, "RandomRelay")) return nullptr; std::string name = mgr.HashInstanceName(in); - u32 sendSetSize = in.readUint32Big(); - u32 sendSetVariance = in.readUint32Big(); - bool percentSize = in.readBool(); - bool active = in.readBool(); + u32 sendSetSize = in.ReadLong(); + u32 sendSetVariance = in.ReadLong(); + bool percentSize = in.ReadBool(); + bool active = in.ReadBool(); return new CScriptRandomRelay(mgr.AllocateUniqueId(), name, info, sendSetSize, sendSetVariance, percentSize, active); } @@ -979,8 +959,8 @@ CEntity* ScriptLoader::LoadRelay(CStateManager& mgr, CInputStream& in, int propC std::string name = mgr.HashInstanceName(in); if (propCount >= 3) - in.readUint32Big(); - bool b1 = in.readBool(); + in.ReadLong(); + bool b1 = in.ReadBool(); return new CScriptRelay(mgr.AllocateUniqueId(), name, info, b1); } @@ -989,9 +969,9 @@ CEntity* ScriptLoader::LoadBeetle(CStateManager& mgr, CInputStream& in, int prop if (!EnsurePropertyCount(propCount, 16, "Beetle")) return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xfrm = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); std::pair pcount = CPatternedInfo::HasCorrectParameterCount(in); if (!pcount.first) return nullptr; @@ -999,14 +979,14 @@ CEntity* ScriptLoader::LoadBeetle(CStateManager& mgr, CInputStream& in, int prop CPatternedInfo pInfo(in, pcount.second); CActorParameters aParams = LoadActorParameters(in); CDamageInfo touchDamage(in); - zeus::CVector3f tailAimReference = zeus::CVector3f::ReadBig(in); - float unused = in.readFloatBig(); + zeus::CVector3f tailAimReference = in.Get(); + float unused = in.ReadFloat(); CDamageVulnerability tailVuln(in); CDamageVulnerability platingVuln(in); - CAssetId tailModel = in.readUint32Big(); - MP1::CBeetle::EEntranceType entranceType = MP1::CBeetle::EEntranceType(in.readUint32Big()); - float initialAttackDelay = in.readFloatBig(); - float retreatTime = in.readFloatBig(); + CAssetId tailModel = in.ReadLong(); + MP1::CBeetle::EEntranceType entranceType = MP1::CBeetle::EEntranceType(in.ReadLong()); + float initialAttackDelay = in.ReadFloat(); + float retreatTime = in.ReadFloat(); FourCC animType = g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()); if (animType != SBIG('ANCS')) @@ -1033,10 +1013,10 @@ CEntity* ScriptLoader::LoadHUDMemo(CStateManager& mgr, CInputStream& in, int pro const CHUDMemoParms hParms(in); auto displayType = CScriptHUDMemo::EDisplayType::MessageBox; if (propCount == 6) { - displayType = CScriptHUDMemo::EDisplayType(in.readUint32Big()); + displayType = CScriptHUDMemo::EDisplayType(in.ReadLong()); } - const CAssetId message = in.readUint32Big(); - const bool active = in.readBool(); + const CAssetId message = in.ReadLong(); + const bool active = in.ReadBool(); return new CScriptHUDMemo(mgr.AllocateUniqueId(), name, info, hParms, displayType, message, active); } @@ -1046,15 +1026,14 @@ CEntity* ScriptLoader::LoadCameraFilterKeyframe(CStateManager& mgr, CInputStream if (!EnsurePropertyCount(propCount, 10, "CameraFilterKeyframe")) return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - EFilterType ftype = EFilterType(in.readUint32Big()); - EFilterShape shape = EFilterShape(in.readUint32Big()); - u32 filterIdx = in.readUint32Big(); - u32 unk = in.readUint32Big(); - zeus::CColor color; - color.readRGBABig(in); - float timeIn = in.readFloatBig(); - float timeOut = in.readFloatBig(); + bool active = in.ReadBool(); + EFilterType ftype = EFilterType(in.ReadLong()); + EFilterShape shape = EFilterShape(in.ReadLong()); + u32 filterIdx = in.ReadLong(); + u32 unk = in.ReadLong(); + zeus::CColor color = in.Get(); + float timeIn = in.ReadFloat(); + float timeOut = in.ReadFloat(); CAssetId txtr(in); return new CScriptCameraFilterKeyframe(mgr.AllocateUniqueId(), name, info, ftype, shape, filterIdx, unk, color, @@ -1067,12 +1046,12 @@ CEntity* ScriptLoader::LoadCameraBlurKeyframe(CStateManager& mgr, CInputStream& return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - EBlurType type = EBlurType(in.readUint32Big()); - float amount = in.readFloatBig(); - u32 unk = in.readUint32Big(); - float timeIn = in.readFloatBig(); - float timeOut = in.readFloatBig(); + bool active = in.ReadBool(); + EBlurType type = EBlurType(in.ReadLong()); + float amount = in.ReadFloat(); + u32 unk = in.ReadLong(); + float timeIn = in.ReadFloat(); + float timeOut = in.ReadFloat(); return new CScriptCameraBlurKeyframe(mgr.AllocateUniqueId(), name, info, type, amount, unk, timeIn, timeOut, active); } @@ -1119,18 +1098,18 @@ CEntity* ScriptLoader::LoadDamageableTrigger(CStateManager& mgr, CInputStream& i return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position(zeus::CVector3f::ReadBig(in)); - zeus::CVector3f volume(zeus::CVector3f::ReadBig(in)); + zeus::CVector3f position( in.Get()); + zeus::CVector3f volume( in.Get()); CHealthInfo hInfo(in); CDamageVulnerability dVuln(in); - u32 triggerFlags = in.readUint32Big(); + u32 triggerFlags = in.ReadLong(); triggerFlags = TransformDamagableTriggerFlags(mgr, info.GetAreaId(), triggerFlags); - CAssetId patternTex1 = in.readUint32Big(); - CAssetId patternTex2 = in.readUint32Big(); - CAssetId colorTex = in.readUint32Big(); - CScriptDamageableTrigger::ECanOrbit canOrbit = CScriptDamageableTrigger::ECanOrbit(in.readBool()); - bool active = in.readBool(); + CAssetId patternTex1 = in.ReadLong(); + CAssetId patternTex2 = in.ReadLong(); + CAssetId colorTex = in.ReadLong(); + CScriptDamageableTrigger::ECanOrbit canOrbit = CScriptDamageableTrigger::ECanOrbit(in.ReadBool()); + bool active = in.ReadBool(); CVisorParameters vParms = LoadVisorParameters(in); return new CScriptDamageableTrigger(mgr.AllocateUniqueId(), name, info, position, volume, hInfo, dVuln, triggerFlags, patternTex1, patternTex2, colorTex, canOrbit, active, vParms); @@ -1141,21 +1120,20 @@ CEntity* ScriptLoader::LoadDebris(CStateManager& mgr, CInputStream& in, int prop return nullptr; const SScaledActorHead head = LoadScaledActorHead(in, mgr); - const float zImpulse = in.readFloatBig(); - const zeus::CVector3f velocity = zeus::CVector3f::ReadBig(in); - zeus::CColor endsColor; - endsColor.readRGBABig(in); - const float mass = in.readFloatBig(); - const float restitution = in.readFloatBig(); - const float duration = in.readFloatBig(); - const auto scaleType = CScriptDebris::EScaleType(in.readUint32Big()); - const bool randomAngImpulse = in.readBool(); - const CAssetId model = in.readUint32Big(); + const float zImpulse = in.ReadFloat(); + const zeus::CVector3f velocity = in.Get(); + zeus::CColor endsColor = in.Get(); + const float mass = in.ReadFloat(); + const float restitution = in.ReadFloat(); + const float duration = in.ReadFloat(); + const auto scaleType = CScriptDebris::EScaleType(in.ReadLong()); + const bool randomAngImpulse = in.ReadBool(); + const CAssetId model = in.ReadLong(); const CActorParameters aParams = LoadActorParameters(in); - const CAssetId particleId = in.readUint32Big(); - const zeus::CVector3f particleScale = zeus::CVector3f::ReadBig(in); - const bool b1 = in.readBool(); - const bool active = in.readBool(); + const CAssetId particleId = in.ReadLong(); + const zeus::CVector3f particleScale = in.Get(); + const bool b1 = in.ReadBool(); + const bool active = in.ReadBool(); if (!g_ResFactory->GetResourceTypeById(model).IsValid()) { return nullptr; @@ -1172,7 +1150,7 @@ CEntity* ScriptLoader::LoadCameraShaker(CStateManager& mgr, CInputStream& in, in std::string name = mgr.HashInstanceName(in); CCameraShakeData shakeData = CCameraShakeData::LoadCameraShakeData(in); - bool active = in.readBool(); + bool active = in.ReadBool(); return new CScriptCameraShaker(mgr.AllocateUniqueId(), name, info, active, shakeData); } @@ -1182,12 +1160,12 @@ CEntity* ScriptLoader::LoadActorKeyframe(CStateManager& mgr, CInputStream& in, i return nullptr; std::string name = mgr.HashInstanceName(in); - s32 animId = in.readInt32Big(); - bool looping = in.readBool(); - float lifetime = in.readFloatBig(); - bool active = in.readBool(); - u32 fadeOut = in.readUint32Big(); - float totalPlayback = in.readFloatBig(); + s32 animId = in.ReadInt32(); + bool looping = in.ReadBool(); + float lifetime = in.ReadFloat(); + bool active = in.ReadBool(); + u32 fadeOut = in.ReadLong(); + float totalPlayback = in.ReadFloat(); if (animId == -1) return nullptr; @@ -1201,94 +1179,87 @@ CEntity* ScriptLoader::LoadWater(CStateManager& mgr, CInputStream& in, int propC return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position; - position.readBig(in); - zeus::CVector3f extent; - extent.readBig(in); + zeus::CVector3f position = in.Get(); + zeus::CVector3f extent = in.Get(); CDamageInfo dInfo(in); - zeus::CVector3f orientedForce; - orientedForce.readBig(in); - ETriggerFlags triggerFlags = ETriggerFlags(in.readUint32Big()) | ETriggerFlags::DetectProjectiles1 | + zeus::CVector3f orientedForce = in.Get(); + ETriggerFlags triggerFlags = ETriggerFlags(in.ReadLong()) | ETriggerFlags::DetectProjectiles1 | ETriggerFlags::DetectProjectiles2 | ETriggerFlags::DetectProjectiles3 | ETriggerFlags::DetectProjectiles4 | ETriggerFlags::DetectBombs | ETriggerFlags::DetectPowerBombs | ETriggerFlags::DetectProjectiles5 | ETriggerFlags::DetectProjectiles6 | ETriggerFlags::DetectProjectiles7; - bool thermalCold = in.readBool(); - bool displaySurface = in.readBool(); - CAssetId patternMap1 = in.readUint32Big(); - CAssetId patternMap2 = in.readUint32Big(); - CAssetId colorMap = in.readUint32Big(); - CAssetId bumpMap = in.readUint32Big(); - CAssetId _envMap = in.readUint32Big(); - CAssetId _envBumpMap = in.readUint32Big(); - zeus::CVector3f _bumpLightDir; - _bumpLightDir.readBig(in); + bool thermalCold = in.ReadBool(); + bool displaySurface = in.ReadBool(); + CAssetId patternMap1 = in.ReadLong(); + CAssetId patternMap2 = in.ReadLong(); + CAssetId colorMap = in.ReadLong(); + CAssetId bumpMap = in.ReadLong(); + CAssetId _envMap = in.ReadLong(); + CAssetId _envBumpMap = in.ReadLong(); + zeus::CVector3f _bumpLightDir =in.Get(); zeus::CVector3f bumpLightDir = _bumpLightDir; if (!bumpLightDir.canBeNormalized()) bumpLightDir.assign(0.f, 0.f, -1.f); - float bumpScale = 1.f / in.readFloatBig(); - float morphInTime = in.readFloatBig(); - float morphOutTime = in.readFloatBig(); - bool active = in.readBool(); - auto fluidType = EFluidType(in.readUint32Big()); - bool b4 = in.readBool(); - float alpha = in.readFloatBig(); + float bumpScale = 1.f / in.ReadFloat(); + float morphInTime = in.ReadFloat(); + float morphOutTime = in.ReadFloat(); + bool active = in.ReadBool(); + auto fluidType = EFluidType(in.ReadLong()); + bool b4 = in.ReadBool(); + float alpha = in.ReadFloat(); CFluidUVMotion uvMotion = LoadFluidUVMotion(in); - float turbSpeed = in.readFloatBig(); - float turbDistance = in.readFloatBig(); - float turbFreqMax = in.readFloatBig(); - float turbFreqMin = in.readFloatBig(); - float turbPhaseMax = zeus::degToRad(in.readFloatBig()); - float turbPhaseMin = zeus::degToRad(in.readFloatBig()); - float turbAmplitudeMax = in.readFloatBig(); - float turbAmplitudeMin = in.readFloatBig(); - zeus::CColor splashColor; - splashColor.readRGBABig(in); - zeus::CColor insideFogColor; - insideFogColor.readRGBABig(in); - CAssetId splashParticle1 = in.readUint32Big(); - CAssetId splashParticle2 = in.readUint32Big(); - CAssetId splashParticle3 = in.readUint32Big(); - CAssetId visorRunoffParticle = in.readUint32Big(); - CAssetId unmorphVisorRunoffParticle = in.readUint32Big(); - u32 visorRunoffSfx = in.readUint32Big(); - u32 unmorphVisorRunoffSfx = in.readUint32Big(); - u32 splashSfx1 = in.readUint32Big(); - u32 splashSfx2 = in.readUint32Big(); - u32 splashSfx3 = in.readUint32Big(); - float tileSize = in.readFloatBig(); - u32 tileSubdivisions = in.readUint32Big(); - float specularMin = in.readFloatBig(); - float specularMax = in.readFloatBig(); - float reflectionSize = in.readFloatBig(); - float rippleIntensity = in.readFloatBig(); - float reflectionBlend = in.readFloatBig(); - float fogBias = in.readFloatBig(); - float fogMagnitude = in.readFloatBig(); - float fogSpeed = in.readFloatBig(); - zeus::CColor fogColor; - fogColor.readRGBABig(in); - CAssetId lightmap = in.readUint32Big(); - float unitsPerLightmapTexel = in.readFloatBig(); - float alphaInTime = in.readFloatBig(); - float alphaOutTime = in.readFloatBig(); - u32 w21 = in.readUint32Big(); - u32 w22 = in.readUint32Big(); - bool b5 = in.readBool(); + float turbSpeed = in.ReadFloat(); + float turbDistance = in.ReadFloat(); + float turbFreqMax = in.ReadFloat(); + float turbFreqMin = in.ReadFloat(); + float turbPhaseMax = zeus::degToRad(in.ReadFloat()); + float turbPhaseMin = zeus::degToRad(in.ReadFloat()); + float turbAmplitudeMax = in.ReadFloat(); + float turbAmplitudeMin = in.ReadFloat(); + zeus::CColor splashColor = in.Get(); + zeus::CColor insideFogColor = in.Get(); + CAssetId splashParticle1 = in.ReadLong(); + CAssetId splashParticle2 = in.ReadLong(); + CAssetId splashParticle3 = in.ReadLong(); + CAssetId visorRunoffParticle = in.ReadLong(); + CAssetId unmorphVisorRunoffParticle = in.ReadLong(); + u32 visorRunoffSfx = in.ReadLong(); + u32 unmorphVisorRunoffSfx = in.ReadLong(); + u32 splashSfx1 = in.ReadLong(); + u32 splashSfx2 = in.ReadLong(); + u32 splashSfx3 = in.ReadLong(); + float tileSize = in.ReadFloat(); + u32 tileSubdivisions = in.ReadLong(); + float specularMin = in.ReadFloat(); + float specularMax = in.ReadFloat(); + float reflectionSize = in.ReadFloat(); + float rippleIntensity = in.ReadFloat(); + float reflectionBlend = in.ReadFloat(); + float fogBias = in.ReadFloat(); + float fogMagnitude = in.ReadFloat(); + float fogSpeed = in.ReadFloat(); + zeus::CColor fogColor = in.Get(); + CAssetId lightmap = in.ReadLong(); + float unitsPerLightmapTexel = in.ReadFloat(); + float alphaInTime = in.ReadFloat(); + float alphaOutTime = in.ReadFloat(); + u32 w21 = in.ReadLong(); + u32 w22 = in.ReadLong(); + bool b5 = in.ReadBool(); std::unique_ptr bitset; u32 bitVal0 = 0; u32 bitVal1 = 0; if (b5) { - bitVal0 = in.readUint16Big(); - bitVal1 = in.readUint16Big(); + bitVal0 = in.ReadShort(); + bitVal1 = in.ReadShort(); u32 len = ((bitVal0 * bitVal1) + 31) / 31; bitset.reset(new u32[len]); - in.readBytesToBuf(bitset.get(), len * 4); + in.Get(reinterpret_cast(bitset.get()), len * 4); } zeus::CAABox box(-extent * 0.5f, extent * 0.5f); @@ -1318,10 +1289,9 @@ CEntity* ScriptLoader::LoadWarWasp(CStateManager& mgr, CInputStream& in, int pro return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransformPivotOnly(in); - zeus::CVector3f scale; - scale.readBig(in); + zeus::CVector3f scale = in.Get(); std::pair verifyPair = CPatternedInfo::HasCorrectParameterCount(in); if (!verifyPair.first) @@ -1329,12 +1299,12 @@ CEntity* ScriptLoader::LoadWarWasp(CStateManager& mgr, CInputStream& in, int pro CPatternedInfo pInfo(in, verifyPair.second); CActorParameters actorParms = LoadActorParameters(in); - CPatterned::EColliderType collider = CPatterned::EColliderType(in.readBool()); + CPatterned::EColliderType collider = CPatterned::EColliderType(in.ReadBool()); CDamageInfo damageInfo1(in); - CAssetId projectileWeapon = in.readUint32Big(); + CAssetId projectileWeapon = in.ReadLong(); CDamageInfo projectileDamage(in); - CAssetId projectileVisorParticle = in.readUint32Big(); - u32 projectileVisorSfx = in.readUint32Big(); + CAssetId projectileVisorParticle = in.ReadLong(); + u32 projectileVisorSfx = in.ReadLong(); const CAnimationParameters& aParms = pInfo.GetAnimationParameters(); FourCC animType = g_ResFactory->GetResourceTypeById(aParms.GetACSFile()); @@ -1430,7 +1400,7 @@ CEntity* ScriptLoader::LoadMetroidBeta(CStateManager& mgr, CInputStream& in, int #if 0 std::string name = mgr.HashInstanceName(in); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) return nullptr; @@ -1464,10 +1434,10 @@ CEntity* ScriptLoader::LoadChozoGhost(CStateManager& mgr, CInputStream& in, int CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); CAssetId wpsc1(in); CDamageInfo dInfo1(in); CAssetId wpsc2(in); @@ -1475,20 +1445,20 @@ CEntity* ScriptLoader::LoadChozoGhost(CStateManager& mgr, CInputStream& in, int MP1::CChozoGhost::CBehaveChance behaveChance1(in); MP1::CChozoGhost::CBehaveChance behaveChance2(in); MP1::CChozoGhost::CBehaveChance behaveChance3(in); - s16 sId1 = CSfxManager::TranslateSFXID(in.readUint32Big()); - float f5 = in.readFloatBig(); - s16 sId2 = CSfxManager::TranslateSFXID(in.readUint32Big()); - s16 sId3 = CSfxManager::TranslateSFXID(in.readUint32Big()); - u32 w1 = in.readUint32Big(); - float f6 = in.readFloatBig(); - u32 w2 = in.readUint32Big(); - float f7 = in.readFloatBig(); + s16 sId1 = CSfxManager::TranslateSFXID(in.ReadLong()); + float f5 = in.ReadFloat(); + s16 sId2 = CSfxManager::TranslateSFXID(in.ReadLong()); + s16 sId3 = CSfxManager::TranslateSFXID(in.ReadLong()); + u32 w1 = in.ReadLong(); + float f6 = in.ReadFloat(); + u32 w2 = in.ReadLong(); + float f7 = in.ReadFloat(); CAssetId partId(in); - s16 sId4 = CSfxManager::TranslateSFXID(in.readUint32Big()); - float f8 = in.readFloatBig(); - float f9 = in.readFloatBig(); - u32 w3 = in.readUint32Big(); - u32 w4 = in.readUint32Big(); + s16 sId4 = CSfxManager::TranslateSFXID(in.ReadLong()); + float f8 = in.ReadFloat(); + float f9 = in.ReadFloat(); + u32 w3 = in.ReadLong(); + u32 w4 = in.ReadLong(); const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); if (g_ResFactory->GetResourceTypeById(animParms.GetACSFile()) != SBIG('ANCS')) @@ -1507,12 +1477,12 @@ CEntity* ScriptLoader::LoadCoverPoint(CStateManager& mgr, CInputStream& in, int return nullptr; SActorHead head = LoadActorHead(in, mgr); - bool active = in.readBool(); - u32 flags = in.readUint32Big(); - bool crouch = in.readBool(); - float horizontalAngle = in.readFloatBig(); - float verticalAngle = in.readFloatBig(); - float coverTime = in.readFloatBig(); + bool active = in.ReadBool(); + u32 flags = in.ReadLong(); + bool crouch = in.ReadBool(); + float horizontalAngle = in.ReadFloat(); + float verticalAngle = in.ReadFloat(); + float coverTime = in.ReadFloat(); return new CScriptCoverPoint(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, active, flags, crouch, horizontalAngle, verticalAngle, coverTime); @@ -1524,8 +1494,8 @@ CEntity* ScriptLoader::LoadSpiderBallWaypoint(CStateManager& mgr, CInputStream& return nullptr; SActorHead actHead = LoadActorHead(in, mgr); - bool active = in.readBool(); - u32 w1 = in.readUint32Big(); + bool active = in.ReadBool(); + u32 w1 = in.ReadLong(); return new CScriptSpiderBallWaypoint(mgr.AllocateUniqueId(), actHead.x0_name, info, actHead.x10_transform, active, w1); @@ -1551,9 +1521,9 @@ CEntity* ScriptLoader::LoadBloodFlower(CStateManager& mgr, CInputStream& in, int CAssetId partId2(in); CAssetId partId3(in); CAssetId partId4(in); - float f1 = in.readFloatBig(); + float f1 = in.ReadFloat(); CAssetId partId5(in); - u32 soundId = in.readUint32Big(); + u32 soundId = in.ReadLong(); if (g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()) != SBIG('ANCS')) return nullptr; @@ -1571,18 +1541,18 @@ CEntity* ScriptLoader::LoadFlickerBat(CStateManager& mgr, CInputStream& in, int return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) return nullptr; CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - bool collider = in.readBool(); - bool excludePlayer = in.readBool(); - bool enableLineOfSight = in.readBool(); + bool collider = in.ReadBool(); + bool excludePlayer = in.ReadBool(); + bool enableLineOfSight = in.ReadBool(); if (g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()) != SBIG('ANCS')) return nullptr; @@ -1600,14 +1570,14 @@ CEntity* ScriptLoader::LoadPathCamera(CStateManager& mgr, CInputStream& in, int } SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); u32 flags = LoadParameterFlags(in); - float lengthExtent = in.readFloatBig(); - float filterMag = in.readFloatBig(); - float filterProportion = in.readFloatBig(); - CPathCamera::EInitialSplinePosition initPos = CPathCamera::EInitialSplinePosition(in.readUint32Big()); - float minEaseDist = in.readFloatBig(); - float maxEaseDist = in.readFloatBig(); + float lengthExtent = in.ReadFloat(); + float filterMag = in.ReadFloat(); + float filterProportion = in.ReadFloat(); + CPathCamera::EInitialSplinePosition initPos = CPathCamera::EInitialSplinePosition(in.ReadLong()); + float minEaseDist = in.ReadFloat(); + float maxEaseDist = in.ReadFloat(); return new CPathCamera(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, lengthExtent, filterMag, filterProportion, minEaseDist, maxEaseDist, flags, initPos); @@ -1619,7 +1589,7 @@ CEntity* ScriptLoader::LoadGrapplePoint(CStateManager& mgr, CInputStream& in, in std::string name = mgr.HashInstanceName(in); zeus::CTransform grappleXf = LoadEditorTransform(in); - bool active = in.readBool(); + bool active = in.ReadBool(); CGrappleParameters parameters = LoadGrappleParameters(in); return new CScriptGrapplePoint(mgr.AllocateUniqueId(), name, info, grappleXf, active, parameters); } @@ -1629,9 +1599,9 @@ CEntity* ScriptLoader::LoadPuddleSpore(CStateManager& mgr, CInputStream& in, int return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) @@ -1639,13 +1609,13 @@ CEntity* ScriptLoader::LoadPuddleSpore(CStateManager& mgr, CInputStream& in, int CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - bool b1 = in.readBool(); + bool b1 = in.ReadBool(); CAssetId w1(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); CAssetId w2(in); CDamageInfo dInfo(in); @@ -1665,7 +1635,7 @@ CEntity* ScriptLoader::LoadDebugCameraWaypoint(CStateManager& mgr, CInputStream& return nullptr; SActorHead actHead = LoadActorHead(in, mgr); - u32 w1 = in.readUint32Big(); + u32 w1 = in.ReadLong(); return new CScriptDebugCameraWaypoint(mgr.AllocateUniqueId(), actHead.x0_name, info, actHead.x10_transform, w1); } @@ -1674,7 +1644,7 @@ CEntity* ScriptLoader::LoadSpiderBallAttractionSurface(CStateManager& mgr, CInpu if (!EnsurePropertyCount(propCount, 5, "SpiderBallAttractionSurface")) return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); return new CScriptSpiderBallAttractionSurface(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, aHead.x40_scale, active); } @@ -1685,22 +1655,22 @@ CEntity* ScriptLoader::LoadPuddleToadGamma(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) return nullptr; CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - float suckForceMultiplier = in.readFloatBig(); - float suckAngle = in.readFloatBig(); - float playerSuckRange = in.readFloatBig(); - zeus::CVector3f localShootDir = zeus::CVector3f::ReadBig(in); - float playerShootSpeed = in.readFloatBig(); - float shouldAttackWaitTime = in.readFloatBig(); - float spotPlayerWaitTime = in.readFloatBig(); + float suckForceMultiplier = in.ReadFloat(); + float suckAngle = in.ReadFloat(); + float playerSuckRange = in.ReadFloat(); + zeus::CVector3f localShootDir = in.Get(); + float playerShootSpeed = in.ReadFloat(); + float shouldAttackWaitTime = in.ReadFloat(); + float spotPlayerWaitTime = in.ReadFloat(); CDamageInfo playerShootDamage(in); CDamageInfo dInfo2(in); CAssetId collisionData(in); @@ -1717,16 +1687,13 @@ CEntity* ScriptLoader::LoadDistanceFog(CStateManager& mgr, CInputStream& in, int return nullptr; std::string name = mgr.HashInstanceName(in); - u32 mode = in.readUint32Big(); - zeus::CColor color; - color.readRGBABig(in); - zeus::CVector2f range; - range.readBig(in); - float colorDelta = in.readFloatBig(); - zeus::CVector2f rangeDelta; - rangeDelta.readBig(in); - bool expl = in.readBool(); - bool active = in.readBool(); + u32 mode = in.ReadLong(); + zeus::CColor color = in.Get(); + zeus::CVector2f range = in.Get(); + float colorDelta = in.ReadFloat(); + zeus::CVector2f rangeDelta = in.Get(); + bool expl = in.ReadBool(); + bool active = in.ReadBool(); ERglFogMode realMode = ERglFogMode::None; if (mode == 0) @@ -1757,9 +1724,9 @@ CEntity* ScriptLoader::LoadFireFlea(CStateManager& mgr, CInputStream& in, int pr CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - in.readBool(); - in.readBool(); - float f1 = in.readFloatBig(); + in.ReadBool(); + in.ReadBool(); + float f1 = in.ReadFloat(); if (!pInfo.GetAnimationParameters().GetACSFile().IsValid()) return nullptr; @@ -1777,7 +1744,7 @@ CEntity* ScriptLoader::LoadMetaree(CStateManager& mgr, CInputStream& in, int pro std::string name = mgr.HashInstanceName(in); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) @@ -1786,15 +1753,15 @@ CEntity* ScriptLoader::LoadMetaree(CStateManager& mgr, CInputStream& in, int pro CPatternedInfo pInfo(in, pair.second); CActorParameters aParms = LoadActorParameters(in); CDamageInfo dInfo(in); - float f1 = in.readFloatBig(); - zeus::CVector3f vec = zeus::CVector3f::ReadBig(in); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); + float f1 = in.ReadFloat(); + zeus::CVector3f vec = in.Get(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); if (g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()) != SBIG('ANCS')) return nullptr; - float f4 = in.readFloatBig(); + float f4 = in.ReadFloat(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -1808,8 +1775,8 @@ CEntity* ScriptLoader::LoadDockAreaChange(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - s32 w1 = in.readInt32Big(); - bool active = in.readBool(); + s32 w1 = in.ReadInt32(); + bool active = in.ReadBool(); return new CScriptDockAreaChange(mgr.AllocateUniqueId(), name, info, w1, active); } @@ -1819,11 +1786,11 @@ CEntity* ScriptLoader::LoadActorRotate(CStateManager& mgr, CInputStream& in, int return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f rotation = zeus::CVector3f::ReadBig(in); - float scale = in.readFloatBig(); - bool updateActors = in.readBool(); - bool updateOnCreation = in.readBool(); - bool active = in.readBool(); + zeus::CVector3f rotation = in.Get(); + float scale = in.ReadFloat(); + bool updateActors = in.ReadBool(); + bool updateOnCreation = in.ReadBool(); + bool active = in.ReadBool(); return new CScriptActorRotate(mgr.AllocateUniqueId(), name, info, rotation, scale, updateActors, updateOnCreation, active); @@ -1836,19 +1803,19 @@ CEntity* ScriptLoader::LoadSpecialFunction(CStateManager& mgr, CInputStream& in, SActorHead head = LoadActorHead(in, mgr); CScriptSpecialFunction::ESpecialFunction specialFunction = - CScriptSpecialFunction::ESpecialFunction(in.readUint32Big()); - std::string str = in.readString(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - u32 w2 = in.readUint32Big(); - u32 w3 = in.readUint32Big(); - CPlayerState::EItemType w4 = CPlayerState::EItemType(in.readUint32Big()); - bool active1 = in.readBool(); - float f4 = in.readFloatBig(); - s16 w5 = in.readUint32Big() & 0xFFFF; - s16 w6 = in.readUint32Big() & 0xFFFF; - s16 w7 = in.readUint32Big() & 0xFFFF; + CScriptSpecialFunction::ESpecialFunction(in.ReadLong()); + std::string str = in.Get(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + u32 w2 = in.ReadLong(); + u32 w3 = in.ReadLong(); + CPlayerState::EItemType w4 = CPlayerState::EItemType(in.ReadLong()); + bool active1 = in.ReadBool(); + float f4 = in.ReadFloat(); + s16 w5 = in.ReadLong() & 0xFFFF; + s16 w6 = in.ReadLong() & 0xFFFF; + s16 w7 = in.ReadLong() & 0xFFFF; if (specialFunction == CScriptSpecialFunction::ESpecialFunction::FogVolume || specialFunction == CScriptSpecialFunction::ESpecialFunction::RadialDamage) return nullptr; @@ -1868,11 +1835,11 @@ CEntity* ScriptLoader::LoadSpankWeed(CStateManager& mgr, CInputStream& in, int p CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - in.readBool(); - float maxDetectionRange = in.readFloatBig(); - float maxHearingRange = in.readFloatBig(); - float maxSightRange = in.readFloatBig(); - float hideTime = in.readFloatBig(); + in.ReadBool(); + float maxDetectionRange = in.ReadFloat(); + float maxHearingRange = in.ReadFloat(); + float maxSightRange = in.ReadFloat(); + float hideTime = in.ReadFloat(); const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); if (!animParms.GetACSFile().IsValid()) @@ -1889,9 +1856,9 @@ CEntity* ScriptLoader::LoadParasite(CStateManager& mgr, CInputStream& in, int pr return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); std::pair pcount = CPatternedInfo::HasCorrectParameterCount(in); if (!pcount.first) @@ -1899,24 +1866,24 @@ CEntity* ScriptLoader::LoadParasite(CStateManager& mgr, CInputStream& in, int pr CPatternedInfo pInfo(in, pcount.second); CActorParameters aParms = LoadActorParameters(in); - float maxTelegraphReactDist = in.readFloatBig(); - float advanceWpRadius = in.readFloatBig(); - float f3 = in.readFloatBig(); - float alignAngVel = in.readFloatBig(); - float f5 = in.readFloatBig(); - float stuckTimeThreshold = in.readFloatBig(); - float collisionCloseMargin = in.readFloatBig(); - float parasiteSearchRadius = in.readFloatBig(); - float parasiteSeparationDist = in.readFloatBig(); - float parasiteSeparationWeight = in.readFloatBig(); - float parasiteAlignmentWeight = in.readFloatBig(); - float parasiteCohesionWeight = in.readFloatBig(); - float destinationSeekWeight = in.readFloatBig(); - float forwardMoveWeight = in.readFloatBig(); - float playerSeparationDist = in.readFloatBig(); - float playerSeparationWeight = in.readFloatBig(); - float playerObstructionMinDist = in.readFloatBig(); - bool disableMove = in.readBool(); + float maxTelegraphReactDist = in.ReadFloat(); + float advanceWpRadius = in.ReadFloat(); + float f3 = in.ReadFloat(); + float alignAngVel = in.ReadFloat(); + float f5 = in.ReadFloat(); + float stuckTimeThreshold = in.ReadFloat(); + float collisionCloseMargin = in.ReadFloat(); + float parasiteSearchRadius = in.ReadFloat(); + float parasiteSeparationDist = in.ReadFloat(); + float parasiteSeparationWeight = in.ReadFloat(); + float parasiteAlignmentWeight = in.ReadFloat(); + float parasiteCohesionWeight = in.ReadFloat(); + float destinationSeekWeight = in.ReadFloat(); + float forwardMoveWeight = in.ReadFloat(); + float playerSeparationDist = in.ReadFloat(); + float playerSeparationWeight = in.ReadFloat(); + float playerObstructionMinDist = in.ReadFloat(); + bool disableMove = in.ReadBool(); if (g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()) != SBIG('ANCS')) return nullptr; @@ -1937,9 +1904,9 @@ CEntity* ScriptLoader::LoadPlayerHint(CStateManager& mgr, CInputStream& in, int return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); u32 overrideFlags = LoadParameterFlags(in); - u32 priority = in.readUint32Big(); + u32 priority = in.ReadLong(); return new CScriptPlayerHint(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, priority, overrideFlags); @@ -1950,9 +1917,9 @@ CEntity* ScriptLoader::LoadRipper(CStateManager& mgr, CInputStream& in, int prop return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType type = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType type = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) return nullptr; @@ -1977,9 +1944,9 @@ CEntity* ScriptLoader::LoadPickupGenerator(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); - float f1 = in.readFloatBig(); + zeus::CVector3f pos = in.Get(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); return new CScriptPickupGenerator(mgr.AllocateUniqueId(), name, info, pos, f1, active); } @@ -1997,20 +1964,20 @@ CEntity* ScriptLoader::LoadPointOfInterest(CStateManager& mgr, CInputStream& in, return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); CScannableParameters sParms = LoadScannableParameters(in); - float pointSize = in.readFloatBig(); + float pointSize = in.ReadFloat(); return new CScriptPointOfInterest(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, sParms, pointSize); } std::optional LoadFlareDef(CInputStream& in) { - if (in.readUint32Big() == 4) { + if (in.ReadLong() == 4) { CAssetId textureId(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - zeus::CColor color = zeus::CColor::ReadRGBABig(in); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + zeus::CColor color = in.Get(); if (textureId.IsValid()) { return {CVisorFlare::CFlareDef(g_SimplePool->GetObj({SBIG('TXTR'), textureId}), f1, f2, color)}; } @@ -2024,20 +1991,20 @@ CEntity* ScriptLoader::LoadDrone(CStateManager& mgr, CInputStream& in, int propC return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); - float f1 = in.readFloatBig(); + zeus::CVector3f scale = in.Get(); + float f1 = in.ReadFloat(); const auto [patternedValid, patternedPropCount] = CPatternedInfo::HasCorrectParameterCount(in); if (!patternedValid) return nullptr; CPatternedInfo pInfo(in, patternedPropCount); CActorParameters actParms = LoadActorParameters(in); CDamageInfo dInfo1(in); - u32 w1 = in.readUint32Big(); + u32 w1 = in.ReadLong(); CDamageInfo dInfo2(in); CAssetId aId1(in); - in.seek(4); // Unused + in.ReadLong(); CAssetId aId2(in); std::optional def1 = LoadFlareDef(in); std::optional def2 = LoadFlareDef(in); @@ -2060,32 +2027,32 @@ CEntity* ScriptLoader::LoadDrone(CStateManager& mgr, CInputStream& in, int propC if (g_ResFactory->GetResourceTypeById(animParms.GetACSFile()) != SBIG('ANCS')) return nullptr; - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); - float f7 = in.readFloatBig(); - float f8 = in.readFloatBig(); - float f9 = in.readFloatBig(); - float f10 = in.readFloatBig(); - float f11 = in.readFloatBig(); - float f12 = in.readFloatBig(); - float f13 = in.readFloatBig(); - float f14 = in.readFloatBig(); - float f15 = in.readFloatBig(); - float f16 = in.readFloatBig(); - float f17 = in.readFloatBig(); - float f18 = in.readFloatBig(); - float f19 = in.readFloatBig(); - float f20 = in.readFloatBig(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); + float f7 = in.ReadFloat(); + float f8 = in.ReadFloat(); + float f9 = in.ReadFloat(); + float f10 = in.ReadFloat(); + float f11 = in.ReadFloat(); + float f12 = in.ReadFloat(); + float f13 = in.ReadFloat(); + float f14 = in.ReadFloat(); + float f15 = in.ReadFloat(); + float f16 = in.ReadFloat(); + float f17 = in.ReadFloat(); + float f18 = in.ReadFloat(); + float f19 = in.ReadFloat(); + float f20 = in.ReadFloat(); CAssetId crscId(in); - float f21 = in.readFloatBig(); - float f22 = in.readFloatBig(); - float f23 = in.readFloatBig(); - float f24 = in.readFloatBig(); - s32 soundId = in.readUint32Big(); - bool b1 = in.readBool(); + float f21 = in.ReadFloat(); + float f22 = in.ReadFloat(); + float f23 = in.ReadFloat(); + float f24 = in.ReadFloat(); + s32 soundId = in.ReadLong(); + bool b1 = in.ReadBool(); CModelData mData( CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), scale, animParms.GetInitialAnimation(), true)); return new MP1::CDrone(mgr.AllocateUniqueId(), name, flavor, info, xf, f1, std::move(mData), pInfo, actParms, @@ -2099,9 +2066,9 @@ CEntity* ScriptLoader::LoadMetroid(CStateManager& mgr, CInputStream& in, int pro return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) return nullptr; @@ -2126,52 +2093,52 @@ CEntity* ScriptLoader::LoadDebrisExtended(CStateManager& mgr, CInputStream& in, SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - float linConeAngle = in.readFloatBig(); - float linMinMag = in.readFloatBig(); - float linMaxMag = in.readFloatBig(); - float angMinMag = in.readFloatBig(); - float angMaxMag = in.readFloatBig(); - float minDuration = in.readFloatBig(); - float maxDuration = in.readFloatBig(); - float colorInT = in.readFloatBig(); - float colorOutT = in.readFloatBig(); + float linConeAngle = in.ReadFloat(); + float linMinMag = in.ReadFloat(); + float linMaxMag = in.ReadFloat(); + float angMinMag = in.ReadFloat(); + float angMaxMag = in.ReadFloat(); + float minDuration = in.ReadFloat(); + float maxDuration = in.ReadFloat(); + float colorInT = in.ReadFloat(); + float colorOutT = in.ReadFloat(); - zeus::CColor color = zeus::CColor::ReadRGBABig(in); - zeus::CColor endsColor = zeus::CColor::ReadRGBABig(in); + zeus::CColor color = in.Get(); + zeus::CColor endsColor = in.Get(); - float scaleOutT = in.readFloatBig(); + float scaleOutT = in.ReadFloat(); - zeus::CVector3f endScale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f endScale = in.Get(); - float restitution = in.readFloatBig(); - float downwardSpeed = in.readFloatBig(); + float restitution = in.ReadFloat(); + float downwardSpeed = in.ReadFloat(); - zeus::CVector3f localOffset = zeus::CVector3f::ReadBig(in); + zeus::CVector3f localOffset = in.Get(); - CAssetId model = in.readUint32Big(); + CAssetId model = in.ReadLong(); CActorParameters aParam = LoadActorParameters(in); - CAssetId particle1 = in.readUint32Big(); - zeus::CVector3f particle1Scale = zeus::CVector3f::ReadBig(in); - bool particle1GlobalTranslation = in.readBool(); - bool deferDeleteTillParticle1Done = in.readBool(); - CScriptDebris::EOrientationType particle1Or = CScriptDebris::EOrientationType(in.readUint32Big()); + CAssetId particle1 = in.ReadLong(); + zeus::CVector3f particle1Scale = in.Get(); + bool particle1GlobalTranslation = in.ReadBool(); + bool deferDeleteTillParticle1Done = in.ReadBool(); + CScriptDebris::EOrientationType particle1Or = CScriptDebris::EOrientationType(in.ReadLong()); - CAssetId particle2 = in.readUint32Big(); - zeus::CVector3f particle2Scale = zeus::CVector3f::ReadBig(in); - bool particle2GlobalTranslation = in.readBool(); - bool deferDeleteTillParticle2Done = in.readBool(); - CScriptDebris::EOrientationType particle2Or = CScriptDebris::EOrientationType(in.readUint32Big()); + CAssetId particle2 = in.ReadLong(); + zeus::CVector3f particle2Scale = in.Get(); + bool particle2GlobalTranslation = in.ReadBool(); + bool deferDeleteTillParticle2Done = in.ReadBool(); + CScriptDebris::EOrientationType particle2Or = CScriptDebris::EOrientationType(in.ReadLong()); - CAssetId particle3 = in.readUint32Big(); - /*zeus::CVector3f particle3Scale =*/(void)zeus::CVector3f::ReadBig(in); /* Not actually used, go figure */ - CScriptDebris::EOrientationType particle3Or = CScriptDebris::EOrientationType(in.readUint32Big()); + CAssetId particle3 = in.ReadLong(); + /*zeus::CVector3f particle3Scale =*/(void) in.Get(); /* Not actually used, go figure */ + CScriptDebris::EOrientationType particle3Or = CScriptDebris::EOrientationType(in.ReadLong()); - bool solid = in.readBool(); - bool dieOnProjectile = in.readBool(); - bool noBounce = in.readBool(); - bool active = in.readBool(); + bool solid = in.ReadBool(); + bool dieOnProjectile = in.ReadBool(); + bool noBounce = in.ReadBool(); + bool active = in.ReadBool(); CModelData modelData; if (g_ResFactory->GetResourceTypeById(model).IsValid()) @@ -2192,21 +2159,21 @@ CEntity* ScriptLoader::LoadSteam(CStateManager& mgr, CInputStream& in, int propC std::string name = mgr.HashInstanceName(in); - zeus::CVector3f v1 = zeus::CVector3f::ReadBig(in); - zeus::CVector3f v2 = zeus::CVector3f::ReadBig(in); + zeus::CVector3f v1 = in.Get(); + zeus::CVector3f v2 = in.Get(); CDamageInfo dInfo(in); - zeus::CVector3f v3 = zeus::CVector3f::ReadBig(in); + zeus::CVector3f v3 = in.Get(); - ETriggerFlags w1 = ETriggerFlags(in.readUint32Big()); - bool b1 = in.readBool(); - u32 w2 = in.readUint32Big(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - bool b2 = in.readBool(); + ETriggerFlags w1 = ETriggerFlags(in.ReadLong()); + bool b1 = in.ReadBool(); + u32 w2 = in.ReadLong(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + bool b2 = in.ReadBool(); zeus::CAABox aabb(-v2 * 0.5f, v2 * 0.5f); @@ -2217,9 +2184,9 @@ CEntity* ScriptLoader::LoadRipple(CStateManager& mgr, CInputStream& in, int prop if (!EnsurePropertyCount(propCount, 4, "Ripple")) return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f center = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); - float mag = in.readFloatBig(); + zeus::CVector3f center = in.Get(); + bool active = in.ReadBool(); + float mag = in.ReadFloat(); return new CScriptRipple(mgr.AllocateUniqueId(), name, info, center, active, mag); } @@ -2227,16 +2194,16 @@ CEntity* ScriptLoader::LoadBallTrigger(CStateManager& mgr, CInputStream& in, int if (!EnsurePropertyCount(propCount, 9, "BallTrigger")) return nullptr; - std::string name = in.readString(); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + std::string name = in.Get(); + zeus::CVector3f pos = in.Get(); + zeus::CVector3f scale = in.Get(); - bool b1 = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - zeus::CVector3f vec = zeus::CVector3f::ReadBig(in); - bool b2 = in.readBool(); + bool b1 = in.ReadBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + zeus::CVector3f vec = in.Get(); + bool b2 = in.ReadBool(); return new CScriptBallTrigger(mgr.AllocateUniqueId(), name, info, pos, scale, b1, f1, f2, f3, vec, b2); } @@ -2246,7 +2213,7 @@ CEntity* ScriptLoader::LoadTargetingPoint(CStateManager& mgr, CInputStream& in, return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); return new CScriptTargetingPoint(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active); } @@ -2256,14 +2223,14 @@ CEntity* ScriptLoader::LoadEMPulse(CStateManager& mgr, CInputStream& in, int pro return nullptr; SActorHead actorHead = LoadActorHead(in, mgr); - bool active = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); - float f7 = in.readFloatBig(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); + float f7 = in.ReadFloat(); CAssetId particleId(in); return new CScriptEMPulse(mgr.AllocateUniqueId(), actorHead.x0_name, info, actorHead.x10_transform, active, f1, f2, @@ -2297,21 +2264,21 @@ CEntity* ScriptLoader::LoadPlayerActor(CStateManager& mgr, CInputStream& in, int return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - zeus::CVector3f extents = zeus::CVector3f::ReadBig(in); - zeus::CVector3f offset = zeus::CVector3f::ReadBig(in); - float mass = in.readFloatBig(); - float zMomentum = in.readFloatBig(); + zeus::CVector3f extents = in.Get(); + zeus::CVector3f offset = in.Get(); + float mass = in.ReadFloat(); + float zMomentum = in.ReadFloat(); CHealthInfo hInfo(in); CDamageVulnerability dVuln(in); - in.readUint32Big(); + in.ReadLong(); CAnimationParameters animParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - bool loop = in.readBool(); - bool snow = in.readBool(); - bool solid = in.readBool(); - bool active = in.readBool(); + bool loop = in.ReadBool(); + bool snow = in.ReadBool(); + bool solid = in.ReadBool(); + bool active = in.ReadBool(); u32 flags = LoadParameterFlags(in); - CPlayerState::EBeamId beam = CPlayerState::EBeamId(in.readUint32Big() - 1); + CPlayerState::EBeamId beam = CPlayerState::EBeamId(in.ReadLong() - 1); FourCC fcc = g_ResFactory->GetResourceTypeById(animParms.GetACSFile()); if (!fcc.IsValid() || fcc != SBIG('ANCS')) @@ -2369,18 +2336,18 @@ CEntity* ScriptLoader::LoadAreaAttributes(CStateManager& mgr, CInputStream& in, if (!EnsurePropertyCount(propCount, 9, "AreaAttributes")) return nullptr; - bool load = in.readUint32Big() != 0; + bool load = in.ReadLong() != 0; if (!load) return nullptr; - bool showSkybox = in.readBool(); - EEnvFxType fxType = EEnvFxType(in.readUint32Big()); - float envFxDensity = in.readFloatBig(); - float thermalHeat = in.readFloatBig(); - float xrayFogDistance = in.readFloatBig(); - float worldLightingLevel = in.readFloatBig(); - CAssetId skybox = in.readUint32Big(); - EPhazonType phazonType = EPhazonType(in.readUint32Big()); + bool showSkybox = in.ReadBool(); + EEnvFxType fxType = EEnvFxType(in.ReadLong()); + float envFxDensity = in.ReadFloat(); + float thermalHeat = in.ReadFloat(); + float xrayFogDistance = in.ReadFloat(); + float worldLightingLevel = in.ReadFloat(); + CAssetId skybox = in.ReadLong(); + EPhazonType phazonType = EPhazonType(in.ReadLong()); return new CScriptAreaAttributes(mgr.AllocateUniqueId(), info, showSkybox, fxType, envFxDensity, thermalHeat, xrayFogDistance, worldLightingLevel, skybox, phazonType); @@ -2390,42 +2357,42 @@ CEntity* ScriptLoader::LoadFishCloud(CStateManager& mgr, CInputStream& in, int p if (!EnsurePropertyCount(propCount, 36, "FishCloud")) return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); CAssetId model(in); CAnimationParameters animParms(in); - u32 numBoids = u32(in.readFloatBig()); - float speed = in.readFloatBig(); - float separationRadius = in.readFloatBig(); - float cohesionMagnitude = in.readFloatBig(); - float alignmentWeight = in.readFloatBig(); - float separationMagnitude = in.readFloatBig(); - float weaponRepelMagnitude = in.readFloatBig(); - float playerRepelMagnitude = in.readFloatBig(); - float containmentMagnitude = in.readFloatBig(); - float scatterVel = in.readFloatBig(); - float maxScatterAngle = in.readFloatBig(); - float weaponRepelDampingSpeed = in.readFloatBig(); - float playerRepelDampingSpeed = in.readFloatBig(); - float containmentRadius = in.readFloatBig(); - u32 updateShift = in.readUint32Big(); + u32 numBoids = u32(in.ReadFloat()); + float speed = in.ReadFloat(); + float separationRadius = in.ReadFloat(); + float cohesionMagnitude = in.ReadFloat(); + float alignmentWeight = in.ReadFloat(); + float separationMagnitude = in.ReadFloat(); + float weaponRepelMagnitude = in.ReadFloat(); + float playerRepelMagnitude = in.ReadFloat(); + float containmentMagnitude = in.ReadFloat(); + float scatterVel = in.ReadFloat(); + float maxScatterAngle = in.ReadFloat(); + float weaponRepelDampingSpeed = in.ReadFloat(); + float playerRepelDampingSpeed = in.ReadFloat(); + float containmentRadius = in.ReadFloat(); + u32 updateShift = in.ReadLong(); if (!g_ResFactory->GetResourceTypeById(model).IsValid()) return nullptr; - zeus::CColor color = zeus::CColor::ReadRGBABig(in); - bool killable = in.readBool(); - float weaponKillRadius = in.readFloatBig(); - CAssetId part1 = in.readUint32Big(); - u32 partCount1 = in.readUint32Big(); - CAssetId part2 = in.readUint32Big(); - u32 partCount2 = in.readUint32Big(); - CAssetId part3 = in.readUint32Big(); - u32 partCount3 = in.readUint32Big(); - CAssetId part4 = in.readUint32Big(); - u32 partCount4 = in.readUint32Big(); - u32 deathSfx = in.readUint32Big(); - bool repelFromThreats = in.readBool(); - bool hotInThermal = in.readBool(); + zeus::CColor color = in.Get(); + bool killable = in.ReadBool(); + float weaponKillRadius = in.ReadFloat(); + CAssetId part1 = in.ReadLong(); + u32 partCount1 = in.ReadLong(); + CAssetId part2 = in.ReadLong(); + u32 partCount2 = in.ReadLong(); + CAssetId part3 = in.ReadLong(); + u32 partCount3 = in.ReadLong(); + CAssetId part4 = in.ReadLong(); + u32 partCount4 = in.ReadLong(); + u32 deathSfx = in.ReadLong(); + bool repelFromThreats = in.ReadBool(); + bool hotInThermal = in.ReadBool(); CModelData mData(CStaticRes(model, zeus::skOne3f)); CAnimRes animRes(animParms.GetACSFile(), animParms.GetCharacter(), zeus::skOne3f, animParms.GetInitialAnimation(), @@ -2445,12 +2412,12 @@ CEntity* ScriptLoader::LoadFishCloudModifier(CStateManager& mgr, CInputStream& i return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); - bool repulsor = in.readBool(); - bool swirl = propCount > 6 ? in.readBool() : false; - float radius = in.readFloatBig(); - float priority = in.readFloatBig(); + zeus::CVector3f pos = in.Get(); + bool active = in.ReadBool(); + bool repulsor = in.ReadBool(); + bool swirl = propCount > 6 ? in.ReadBool() : false; + float radius = in.ReadFloat(); + float priority = in.ReadFloat(); return new CFishCloudModifier(mgr.AllocateUniqueId(), active, name, info, pos, repulsor, swirl, radius, priority); } @@ -2461,14 +2428,14 @@ CEntity* ScriptLoader::LoadVisorFlare(CStateManager& mgr, CInputStream& in, int } const std::string name = mgr.HashInstanceName(in); - const zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - const bool b1 = in.readBool(); - const auto w1 = CVisorFlare::EBlendMode(in.readUint32Big()); - const bool b2 = in.readBool(); - const float f1 = in.readFloatBig(); - const float f2 = in.readFloatBig(); - const float f3 = in.readFloatBig(); - const u32 w2 = in.readUint32Big(); + const zeus::CVector3f pos = in.Get(); + const bool b1 = in.ReadBool(); + const auto w1 = CVisorFlare::EBlendMode(in.ReadLong()); + const bool b2 = in.ReadBool(); + const float f1 = in.ReadFloat(); + const float f2 = in.ReadFloat(); + const float f3 = in.ReadFloat(); + const u32 w2 = in.ReadLong(); std::vector flares; flares.reserve(5); @@ -2490,36 +2457,36 @@ CEntity* ScriptLoader::LoadWorldTeleporter(CStateManager& mgr, CInputStream& in, } std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - CAssetId worldId = in.readUint32Big(); - CAssetId areaId = in.readUint32Big(); + bool active = in.ReadBool(); + CAssetId worldId = in.ReadLong(); + CAssetId areaId = in.ReadLong(); if (propCount == 4) return new CScriptWorldTeleporter(mgr.AllocateUniqueId(), name, info, active, worldId, areaId); CAnimationParameters animParms = LoadAnimationParameters(in); - zeus::CVector3f playerScale = zeus::CVector3f::ReadBig(in); - CAssetId platformModel = in.readUint32Big(); - zeus::CVector3f platformScale = zeus::CVector3f::ReadBig(in); - CAssetId backgroundModel = in.readUint32Big(); - zeus::CVector3f backgroundScale = zeus::CVector3f::ReadBig(in); - bool upElevator = in.readBool(); + zeus::CVector3f playerScale = in.Get(); + CAssetId platformModel = in.ReadLong(); + zeus::CVector3f platformScale = in.Get(); + CAssetId backgroundModel = in.ReadLong(); + zeus::CVector3f backgroundScale = in.Get(); + bool upElevator = in.ReadBool(); - s16 elevatorSound = (propCount < 12 ? s16(-1) : s16(in.readUint32Big())); - u8 volume = (propCount < 13 ? u8(127) : u8(in.readUint32Big())); - u8 panning = (propCount < 14 ? u8(64) : u8(in.readUint32Big())); - bool showText = (propCount < 15 ? false : in.readBool()); - CAssetId fontId = (propCount < 16 ? CAssetId() : in.readUint32Big()); - CAssetId stringId = (propCount < 17 ? CAssetId() : in.readUint32Big()); - bool fadeWhite = (propCount < 18 ? false : in.readBool()); - float charFadeInTime = (propCount < 19 ? 0.1f : in.readFloatBig()); - float charsPerSecond = (propCount < 20 ? 16.f : in.readFloatBig()); - float showDelay = (propCount < 21 ? 0.f : in.readFloatBig()); - std::string str1 = (propCount < 22 ? "" : in.readString()); - std::string str2 = (propCount < 23 ? "" : in.readString()); - /*float f1 =*/(propCount < 24 ? 0.f : in.readFloatBig()); - /*float f2 =*/(propCount < 25 ? 0.f : in.readFloatBig()); - /*float f3 =*/(propCount < 26 ? 0.f : in.readFloatBig()); + s16 elevatorSound = (propCount < 12 ? s16(-1) : s16(in.ReadLong())); + u8 volume = (propCount < 13 ? u8(127) : u8(in.ReadLong())); + u8 panning = (propCount < 14 ? u8(64) : u8(in.ReadLong())); + bool showText = (propCount < 15 ? false : in.ReadBool()); + CAssetId fontId = (propCount < 16 ? CAssetId() : in.ReadLong()); + CAssetId stringId = (propCount < 17 ? CAssetId() : in.ReadLong()); + bool fadeWhite = (propCount < 18 ? false : in.ReadBool()); + float charFadeInTime = (propCount < 19 ? 0.1f : in.ReadFloat()); + float charsPerSecond = (propCount < 20 ? 16.f : in.ReadFloat()); + float showDelay = (propCount < 21 ? 0.f : in.ReadFloat()); + std::string str1 = (propCount < 22 ? "" : in.Get()); + std::string str2 = (propCount < 23 ? "" : in.Get()); + /*float f1 =*/(propCount < 24 ? 0.f : in.ReadFloat()); + /*float f2 =*/(propCount < 25 ? 0.f : in.ReadFloat()); + /*float f3 =*/(propCount < 26 ? 0.f : in.ReadFloat()); if (showText) return new CScriptWorldTeleporter(mgr.AllocateUniqueId(), name, info, active, worldId, areaId, elevatorSound, @@ -2537,19 +2504,17 @@ CEntity* ScriptLoader::LoadVisorGoo(CStateManager& mgr, CInputStream& in, int pr return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position; - position.readBig(in); + zeus::CVector3f position = in.Get(); zeus::CTransform xf = zeus::CTransform::Translate(position); CAssetId particle(in); CAssetId electric(in); - float minDist = in.readFloatBig(); - float maxDist = in.readFloatBig(); - float nearProb = in.readFloatBig(); - float farProb = in.readFloatBig(); - zeus::CColor color; - color.readRGBABig(in); - s32 sfx = in.readInt32Big(); - bool forceShow = in.readBool(); + float minDist = in.ReadFloat(); + float maxDist = in.ReadFloat(); + float nearProb = in.ReadFloat(); + float farProb = in.ReadFloat(); + zeus::CColor color = in.Get(); + s32 sfx = in.ReadInt32(); + bool forceShow = in.ReadBool(); if (!particle.IsValid() && !electric.IsValid()) return nullptr; @@ -2571,19 +2536,19 @@ CEntity* ScriptLoader::LoadJellyZap(CStateManager& mgr, CInputStream& in, int pr CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); CDamageInfo dInfo(in); - float attackRadius = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); - float f7 = in.readFloatBig(); - float f8 = in.readFloatBig(); - float priority = in.readFloatBig(); - float repulseRadius = in.readFloatBig(); - float attractRadius = in.readFloatBig(); - float f12 = in.readFloatBig(); - bool b1 = in.readBool(); + float attackRadius = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); + float f7 = in.ReadFloat(); + float f8 = in.ReadFloat(); + float priority = in.ReadFloat(); + float repulseRadius = in.ReadFloat(); + float attractRadius = in.ReadFloat(); + float f12 = in.ReadFloat(); + bool b1 = in.ReadBool(); const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); if (g_ResFactory->GetResourceTypeById(animParms.GetACSFile()) != SBIG('ANCS')) { @@ -2603,15 +2568,15 @@ CEntity* ScriptLoader::LoadControllerAction(CStateManager& mgr, CInputStream& in return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - ControlMapper::ECommands w1 = ControlMapper::ECommands(in.readUint32Big()); + bool active = in.ReadBool(); + ControlMapper::ECommands w1 = ControlMapper::ECommands(in.ReadLong()); bool b1 = false; u32 w2 = 0; if (propCount == 6) { - b1 = in.readBool(); - w2 = in.readUint32Big(); + b1 = in.ReadBool(); + w2 = in.ReadLong(); } - bool b2 = in.readBool(); + bool b2 = in.ReadBool(); return new CScriptControllerAction(mgr.AllocateUniqueId(), name, info, active, w1, b1, w2, b2); } @@ -2621,9 +2586,9 @@ CEntity* ScriptLoader::LoadSwitch(CStateManager& mgr, CInputStream& in, int prop return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - bool b2 = in.readBool(); - bool b3 = in.readBool(); + bool active = in.ReadBool(); + bool b2 = in.ReadBool(); + bool b3 = in.ReadBool(); return new CScriptSwitch(mgr.AllocateUniqueId(), name, info, active, b2, b3); } @@ -2634,13 +2599,13 @@ CEntity* ScriptLoader::LoadPlayerStateChange(CStateManager& mgr, CInputStream& i return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - s32 itemType = in.readUint32Big(); - s32 itemCount = in.readInt32Big(); - s32 itemCapacity = in.readInt32Big(); - CScriptPlayerStateChange::EControl ctrl = CScriptPlayerStateChange::EControl(in.readUint32Big()); + bool active = in.ReadBool(); + s32 itemType = in.ReadLong(); + s32 itemCount = in.ReadInt32(); + s32 itemCapacity = in.ReadInt32(); + CScriptPlayerStateChange::EControl ctrl = CScriptPlayerStateChange::EControl(in.ReadLong()); CScriptPlayerStateChange::EControlCommandOption ctrlCmdOpt = - CScriptPlayerStateChange::EControlCommandOption(in.readUint32Big()); + CScriptPlayerStateChange::EControlCommandOption(in.ReadLong()); return new CScriptPlayerStateChange(mgr.AllocateUniqueId(), name, info, active, itemType, itemCount, itemCapacity, ctrl, ctrlCmdOpt); } @@ -2658,8 +2623,8 @@ CEntity* ScriptLoader::LoadThardus(CStateManager& mgr, CInputStream& in, int pro CPatternedInfo pInfo(in, patternedCount); CActorParameters actParms = LoadActorParameters(in); - in.readBool(); - in.readBool(); + in.ReadBool(); + in.ReadBool(); const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); if (!animParms.GetACSFile().IsValid()) return nullptr; @@ -2688,18 +2653,18 @@ CEntity* ScriptLoader::LoadThardus(CStateManager& mgr, CInputStream& in, int pro CAssetId particle7(in); CAssetId particle8(in); CAssetId particle9(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); CAssetId texture(in); - int sfxID1 = in.readUint32Big(); + int sfxID1 = in.ReadLong(); CAssetId particle10 = (propCount < 44) ? CAssetId() : CAssetId(in); - int sfxID2 = in.readUint32Big(); - int sfxID3 = in.readUint32Big(); - int sfxID4 = in.readUint32Big(); + int sfxID2 = in.ReadLong(); + int sfxID3 = in.ReadLong(); + int sfxID4 = in.ReadLong(); std::vector mData1(std::rbegin(staticRes[0]), std::rend(staticRes[0])); std::vector mData2(std::rbegin(staticRes[1]), std::rend(staticRes[1])); @@ -2716,43 +2681,43 @@ CEntity* ScriptLoader::LoadWallCrawlerSwarm(CStateManager& mgr, CInputStream& in return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); CActorParameters aParams = LoadActorParameters(in); - CWallCrawlerSwarm::EFlavor flavor = CWallCrawlerSwarm::EFlavor(in.readUint32Big()); - u32 actor = in.readUint32Big(); - u32 charIdx = in.readUint32Big(); - u32 defaultAnim = in.readUint32Big(); - u32 launchAnim = in.readUint32Big(); - u32 attractAnim = in.readUint32Big(); - u32 part1 = in.readUint32Big(); - u32 part2 = in.readUint32Big(); - u32 part3 = in.readUint32Big(); - u32 part4 = in.readUint32Big(); + CWallCrawlerSwarm::EFlavor flavor = CWallCrawlerSwarm::EFlavor(in.ReadLong()); + u32 actor = in.ReadLong(); + u32 charIdx = in.ReadLong(); + u32 defaultAnim = in.ReadLong(); + u32 launchAnim = in.ReadLong(); + u32 attractAnim = in.ReadLong(); + u32 part1 = in.ReadLong(); + u32 part2 = in.ReadLong(); + u32 part3 = in.ReadLong(); + u32 part4 = in.ReadLong(); CDamageInfo crabDamage(in); - float crabDamageCooldown = in.readFloatBig(); + float crabDamageCooldown = in.ReadFloat(); CDamageInfo scarabExplodeDamage(in); - float boidRadius = in.readFloatBig(); - float touchRadius = in.readFloatBig(); - float playerTouchRadius = in.readFloatBig(); - float animPlaybackSpeed = in.readFloatBig(); - u32 numBoids = in.readUint32Big(); - u32 maxCreatedBoids = in.readUint32Big(); - float separationRadius = in.readFloatBig(); - float cohesionMagnitude = in.readFloatBig(); - float alignmentWeight = in.readFloatBig(); - float separationMagnitude = in.readFloatBig(); - float moveToWaypointWeight = in.readFloatBig(); - float attractionMagnitude = in.readFloatBig(); - float attractionRadius = in.readFloatBig(); - float boidGenRate = in.readFloatBig(); - u32 maxLaunches = in.readUint32Big(); - float scarabBoxMargin = in.readFloatBig(); - float scarabScatterXYVelocity = in.readFloatBig(); - float scarabTimeToExplode = in.readFloatBig(); + float boidRadius = in.ReadFloat(); + float touchRadius = in.ReadFloat(); + float playerTouchRadius = in.ReadFloat(); + float animPlaybackSpeed = in.ReadFloat(); + u32 numBoids = in.ReadLong(); + u32 maxCreatedBoids = in.ReadLong(); + float separationRadius = in.ReadFloat(); + float cohesionMagnitude = in.ReadFloat(); + float alignmentWeight = in.ReadFloat(); + float separationMagnitude = in.ReadFloat(); + float moveToWaypointWeight = in.ReadFloat(); + float attractionMagnitude = in.ReadFloat(); + float attractionRadius = in.ReadFloat(); + float boidGenRate = in.ReadFloat(); + u32 maxLaunches = in.ReadLong(); + float scarabBoxMargin = in.ReadFloat(); + float scarabScatterXYVelocity = in.ReadFloat(); + float scarabTimeToExplode = in.ReadFloat(); CHealthInfo hInfo(in); CDamageVulnerability dVulns(in); - u32 launchSfx = in.readUint32Big(); - u32 scatterSfx = in.readUint32Big(); + u32 launchSfx = in.ReadLong(); + u32 scatterSfx = in.ReadLong(); return new CWallCrawlerSwarm( mgr.AllocateUniqueId(), active, aHead.x0_name, info, aHead.x40_scale, aHead.x10_transform, flavor, @@ -2768,8 +2733,8 @@ CEntity* ScriptLoader::LoadAiJumpPoint(CStateManager& mgr, CInputStream& in, int return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); - float apex = in.readFloat(); + bool active = in.ReadBool(); + float apex = in.ReadFloat(); return new CScriptAiJumpPoint(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, apex); } @@ -2803,37 +2768,37 @@ CEntity* ScriptLoader::LoadRoomAcoustics(CStateManager& mgr, CInputStream& in, i return nullptr; std::string name = mgr.HashInstanceName(in); - bool a = in.readBool(); - u32 b = in.readUint32Big(); - bool c = in.readBool(); - bool d = in.readBool(); - float e = in.readFloatBig(); - float f = in.readFloatBig(); - float g = in.readFloatBig(); - float h = in.readFloatBig(); - float i = in.readFloatBig(); - float j = in.readFloatBig(); - bool k = in.readBool(); - float l = in.readFloatBig(); - float m = in.readFloatBig(); - float n = in.readFloatBig(); - bool o = in.readBool(); - bool p = in.readBool(); - float q = in.readFloatBig(); - float r = in.readFloatBig(); - float s = in.readFloatBig(); - float t = in.readFloatBig(); - float u = in.readFloatBig(); - bool v = in.readBool(); - u32 w = in.readUint32Big(); - u32 x = in.readUint32Big(); - u32 y = in.readUint32Big(); - u32 z = in.readUint32Big(); - u32 _a = in.readUint32Big(); - u32 _b = in.readUint32Big(); - u32 _c = in.readUint32Big(); - u32 _d = in.readUint32Big(); - u32 _e = in.readUint32Big(); + bool a = in.ReadBool(); + u32 b = in.ReadLong(); + bool c = in.ReadBool(); + bool d = in.ReadBool(); + float e = in.ReadFloat(); + float f = in.ReadFloat(); + float g = in.ReadFloat(); + float h = in.ReadFloat(); + float i = in.ReadFloat(); + float j = in.ReadFloat(); + bool k = in.ReadBool(); + float l = in.ReadFloat(); + float m = in.ReadFloat(); + float n = in.ReadFloat(); + bool o = in.ReadBool(); + bool p = in.ReadBool(); + float q = in.ReadFloat(); + float r = in.ReadFloat(); + float s = in.ReadFloat(); + float t = in.ReadFloat(); + float u = in.ReadFloat(); + bool v = in.ReadBool(); + u32 w = in.ReadLong(); + u32 x = in.ReadLong(); + u32 y = in.ReadLong(); + u32 z = in.ReadLong(); + u32 _a = in.ReadLong(); + u32 _b = in.ReadLong(); + u32 _c = in.ReadLong(); + u32 _d = in.ReadLong(); + u32 _e = in.ReadLong(); return new CScriptRoomAcoustics(mgr.AllocateUniqueId(), name, info, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _a, _b, _c, _d, _e); @@ -2844,19 +2809,17 @@ CEntity* ScriptLoader::LoadColorModulate(CStateManager& mgr, CInputStream& in, i return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CColor colorA; - colorA.readRGBABig(in); - zeus::CColor colorB; - colorB.readRGBABig(in); - CScriptColorModulate::EBlendMode blendMode = CScriptColorModulate::EBlendMode(in.readUint32Big()); - float timeA2B = in.readFloatBig(); - float timeB2A = in.readFloatBig(); - bool doReverse = in.readBool(); - bool resetTargetWhenDone = in.readBool(); - bool depthCompare = in.readBool(); - bool depthUpdate = in.readBool(); - bool depthBackwards = in.readBool(); - bool active = in.readBool(); + zeus::CColor colorA = in.Get(); + zeus::CColor colorB = in.Get(); + CScriptColorModulate::EBlendMode blendMode = CScriptColorModulate::EBlendMode(in.ReadLong()); + float timeA2B = in.ReadFloat(); + float timeB2A = in.ReadFloat(); + bool doReverse = in.ReadBool(); + bool resetTargetWhenDone = in.ReadBool(); + bool depthCompare = in.ReadBool(); + bool depthUpdate = in.ReadBool(); + bool depthBackwards = in.ReadBool(); + bool active = in.ReadBool(); return new CScriptColorModulate(mgr.AllocateUniqueId(), name, info, colorA, colorB, blendMode, timeA2B, timeB2A, doReverse, resetTargetWhenDone, depthCompare, depthUpdate, depthBackwards, active); } @@ -2873,9 +2836,9 @@ CEntity* ScriptLoader::LoadThardusRockProjectile(CStateManager& mgr, CInputStrea CPatternedInfo pInfo(in, pInfoCount); CActorParameters actParms = LoadActorParameters(in); - in.readBool(); - in.readBool(); - float f1 = in.readFloatBig(); + in.ReadBool(); + in.ReadBool(); + float f1 = in.ReadFloat(); CAssetId modelId(in); CAssetId stateMachine(in); if (!pInfo.GetAnimationParameters().GetACSFile().IsValid()) @@ -2895,11 +2858,11 @@ CEntity* ScriptLoader::LoadMidi(CStateManager& mgr, CInputStream& in, int propCo return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - u32 csng = in.readUint32Big(); - float fadeIn = in.readFloatBig(); - float fadeOut = in.readFloatBig(); - u32 vol = in.readUint32Big(); + bool active = in.ReadBool(); + u32 csng = in.ReadLong(); + float fadeIn = in.ReadFloat(); + float fadeOut = in.ReadFloat(); + u32 vol = in.ReadLong(); return new CScriptMidi(mgr.AllocateUniqueId(), info, name, active, csng, fadeIn, fadeOut, vol); } @@ -2908,14 +2871,14 @@ CEntity* ScriptLoader::LoadStreamedAudio(CStateManager& mgr, CInputStream& in, i return nullptr; const std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - std::string fileName = in.readString(); - bool noStopOnDeactivate = in.readBool(); - float fadeIn = in.readFloatBig(); - float fadeOut = in.readFloatBig(); - u32 volume = in.readUint32Big(); - u32 oneShot = in.readUint32Big(); - bool music = in.readBool(); + bool active = in.ReadBool(); + std::string fileName = in.Get(); + bool noStopOnDeactivate = in.ReadBool(); + float fadeIn = in.ReadFloat(); + float fadeOut = in.ReadFloat(); + u32 volume = in.ReadLong(); + u32 oneShot = in.ReadLong(); + bool music = in.ReadBool(); return new CScriptStreamedMusic(mgr.AllocateUniqueId(), info, name, active, fileName, noStopOnDeactivate, fadeIn, fadeOut, volume, !oneShot, music); @@ -2926,9 +2889,9 @@ CEntity* ScriptLoader::LoadRepulsor(CStateManager& mgr, CInputStream& in, int pr return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f center = in.readVec3fBig(); - bool active = in.readBool(); - float radius = in.readFloatBig(); + zeus::CVector3f center = in.Get(); + bool active = in.ReadBool(); + float radius = in.ReadFloat(); return new CRepulsor(mgr.AllocateUniqueId(), active, name, info, center, radius); } @@ -2938,11 +2901,11 @@ CEntity* ScriptLoader::LoadGunTurret(CStateManager& mgr, CInputStream& in, int p return nullptr; std::string name = mgr.HashInstanceName(in); - CScriptGunTurret::ETurretComponent component = CScriptGunTurret::ETurretComponent(in.readUint32Big()); + CScriptGunTurret::ETurretComponent component = CScriptGunTurret::ETurretComponent(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); - zeus::CVector3f collisionExtent = zeus::CVector3f::ReadBig(in); - zeus::CVector3f collisionOffset = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); + zeus::CVector3f collisionExtent = in.Get(); + zeus::CVector3f collisionOffset = in.Get(); CAnimationParameters animParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); CHealthInfo hInfo(in); @@ -2968,12 +2931,12 @@ CEntity* ScriptLoader::LoadFogVolume(CStateManager& mgr, CInputStream& in, int p return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f center = zeus::CVector3f::ReadBig(in); - zeus::CVector3f volume = zeus::CVector3f::ReadBig(in); - float flickerSpeed = in.readFloatBig(); - float f2 = in.readFloatBig(); - zeus::CColor fogColor = zeus::CColor::ReadRGBABig(in); - bool active = in.readBool(); + zeus::CVector3f center = in.Get(); + zeus::CVector3f volume = in.Get(); + float flickerSpeed = in.ReadFloat(); + float f2 = in.ReadFloat(); + zeus::CColor fogColor = in.Get(); + bool active = in.ReadBool(); volume.x() = std::fabs(volume.x()); volume.y() = std::fabs(volume.y()); @@ -3012,9 +2975,9 @@ CEntity* ScriptLoader::LoadEyeball(CStateManager& mgr, CInputStream& in, int pro return nullptr; std::string name = mgr.HashInstanceName(in); - CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.readUint32Big()); + CPatterned::EFlavorType flavor = CPatterned::EFlavorType(in.ReadLong()); zeus::CTransform xf = LoadEditorTransform(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); + zeus::CVector3f scale = in.Get(); auto pair = CPatternedInfo::HasCorrectParameterCount(in); if (!pair.first) @@ -3022,24 +2985,24 @@ CEntity* ScriptLoader::LoadEyeball(CStateManager& mgr, CInputStream& in, int pro CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - float attackDelay = in.readFloatBig(); - float attackStartTime = in.readFloatBig(); + float attackDelay = in.ReadFloat(); + float attackStartTime = in.ReadFloat(); CAssetId wpsc(in); CDamageInfo dInfo(in); CAssetId beamContactFxId(in); CAssetId beamPulseFxId(in); CAssetId beamTextureId(in); CAssetId beamGlowTextureId(in); - u32 anim0 = in.readUint32Big(); - u32 anim1 = in.readUint32Big(); - u32 anim2 = in.readUint32Big(); - u32 anim3 = in.readUint32Big(); - u32 beamSfx = in.readUint32Big(); + u32 anim0 = in.ReadLong(); + u32 anim1 = in.ReadLong(); + u32 anim2 = in.ReadLong(); + u32 anim3 = in.ReadLong(); + u32 beamSfx = in.ReadLong(); if (g_ResFactory->GetResourceTypeById(pInfo.GetAnimationParameters().GetACSFile()) != SBIG('ANCS')) return nullptr; - bool attackDisabled = in.readBool(); + bool attackDisabled = in.ReadBool(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3054,10 +3017,10 @@ CEntity* ScriptLoader::LoadRadialDamage(CStateManager& mgr, CInputStream& in, in return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f center = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); + zeus::CVector3f center = in.Get(); + bool active = in.ReadBool(); CDamageInfo dInfo(in); - float radius = in.readFloatBig(); + float radius = in.ReadFloat(); zeus::CTransform xf = ConvertEditorEulerToTransform4f(zeus::skZero3f, center); return new CScriptSpecialFunction( @@ -3071,10 +3034,10 @@ CEntity* ScriptLoader::LoadCameraPitchVolume(CStateManager& mgr, CInputStream& i return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); - zeus::CRelAngle upPitch = zeus::CRelAngle::FromDegrees(in.readFloatBig()); - zeus::CRelAngle downPitch = zeus::CRelAngle::FromDegrees(in.readFloatBig()); - float scale = in.readFloatBig(); + bool active = in.ReadBool(); + zeus::CRelAngle upPitch = zeus::CRelAngle::FromDegrees(in.ReadFloat()); + zeus::CRelAngle downPitch = zeus::CRelAngle::FromDegrees(in.ReadFloat()); + float scale = in.ReadFloat(); return new CScriptCameraPitchVolume(mgr.AllocateUniqueId(), active, aHead.x0_name, info, aHead.x40_scale, aHead.x10_transform, upPitch, downPitch, scale); @@ -3086,9 +3049,9 @@ CEntity* ScriptLoader::LoadEnvFxDensityController(CStateManager& mgr, CInputStre return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - float density = in.readFloatBig(); - u32 maxDensityDeltaSpeed = in.readUint32Big(); + bool active = in.ReadBool(); + float density = in.ReadFloat(); + u32 maxDensityDeltaSpeed = in.ReadLong(); return new CScriptSpecialFunction(mgr.AllocateUniqueId(), name, info, zeus::CTransform(), CScriptSpecialFunction::ESpecialFunction::EnvFxDensityController, "", density, @@ -3114,22 +3077,22 @@ CEntity* ScriptLoader::LoadMagdolite(CStateManager& mgr, CInputStream& in, int p return nullptr; } - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); CDamageInfo damageInfo1(in); CDamageInfo damageInfo2(in); CDamageVulnerability damageVulnerability1(in); CDamageVulnerability damageVulnerability2(in); CAssetId modelId(in); CAssetId skinId(in); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); CFlameInfo flameInfo(in); - float f7 = in.readFloatBig(); - float f8 = in.readFloatBig(); - float f9 = in.readFloatBig(); + float f7 = in.ReadFloat(); + float f8 = in.ReadFloat(); + float f9 = in.ReadFloat(); CModelData modelData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), actorHead.x40_scale, @@ -3156,34 +3119,34 @@ CEntity* ScriptLoader::LoadSnakeWeedSwarm(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - zeus::CVector3f scale = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); + zeus::CVector3f pos = in.Get(); + zeus::CVector3f scale = in.Get(); + bool active = in.ReadBool(); CAnimationParameters animParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - float spacing = in.readFloatBig(); - float height = in.readFloatBig(); - float f3 = in.readFloatBig(); - float weaponDamageRadius = in.readFloatBig(); - float maxPlayerDistance = in.readFloatBig(); - float loweredTime = in.readFloatBig(); - float loweredTimeVariation = in.readFloatBig(); - float maxZOffset = in.readFloatBig(); - float speed = in.readFloatBig(); - float speedVariation = in.readFloatBig(); - float f11 = in.readFloatBig(); - float scaleMin = in.readFloatBig(); - float scaleMax = in.readFloatBig(); - float distanceBelowGround = in.readFloatBig(); + float spacing = in.ReadFloat(); + float height = in.ReadFloat(); + float f3 = in.ReadFloat(); + float weaponDamageRadius = in.ReadFloat(); + float maxPlayerDistance = in.ReadFloat(); + float loweredTime = in.ReadFloat(); + float loweredTimeVariation = in.ReadFloat(); + float maxZOffset = in.ReadFloat(); + float speed = in.ReadFloat(); + float speedVariation = in.ReadFloat(); + float f11 = in.ReadFloat(); + float scaleMin = in.ReadFloat(); + float scaleMax = in.ReadFloat(); + float distanceBelowGround = in.ReadFloat(); CDamageInfo dInfo(in); - float unused = in.readFloatBig(); - u32 sfxId1 = in.readUint32Big(); - u32 sfxId2 = in.readUint32Big(); - u32 sfxId3 = in.readUint32Big(); + float unused = in.ReadFloat(); + u32 sfxId1 = in.ReadLong(); + u32 sfxId2 = in.ReadLong(); + u32 sfxId3 = in.ReadLong(); CAssetId particleGenDesc1 = (propCount < 29 ? CAssetId() : CAssetId(in)); - u32 w5 = (propCount < 29 ? 0 : in.readUint32Big()); + u32 w5 = (propCount < 29 ? 0 : in.ReadLong()); CAssetId particleGenDesc2 = (propCount < 29 ? CAssetId() : CAssetId(in)); - float f16 = (propCount < 29 ? 0.f : in.readFloatBig()); + float f16 = (propCount < 29 ? 0.f : in.ReadFloat()); CAnimRes animRes(animParms.GetACSFile(), animParms.GetCharacter(), zeus::skOne3f, animParms.GetInitialAnimation(), true); @@ -3199,17 +3162,17 @@ CEntity* ScriptLoader::LoadActorContraption(CStateManager& mgr, CInputStream& in return nullptr; SScaledActorHead head = LoadScaledActorHead(in, mgr); - zeus::CVector3f collisionExtent = zeus::CVector3f::ReadBig(in); - zeus::CVector3f collisionOrigin = zeus::CVector3f::ReadBig(in); - float mass = in.readFloatBig(); - float zMomentum = in.readFloatBig(); + zeus::CVector3f collisionExtent = in.Get(); + zeus::CVector3f collisionOrigin = in.Get(); + float mass = in.ReadFloat(); + float zMomentum = in.ReadFloat(); CHealthInfo hInfo(in); CDamageVulnerability dVuln(in); CAnimationParameters animParams(in); CActorParameters actParams = LoadActorParameters(in); - CAssetId flameFxId = in.readUint32Big(); + CAssetId flameFxId = in.ReadLong(); CDamageInfo dInfo(in); - bool active = in.readBool(); + bool active = in.ReadBool(); if (!g_ResFactory->GetResourceTypeById(animParams.GetACSFile()).IsValid()) return nullptr; @@ -3242,14 +3205,14 @@ CEntity* ScriptLoader::LoadOculus(CStateManager& mgr, CInputStream& in, int prop if (!pInfo.GetAnimationParameters().GetACSFile().IsValid()) return nullptr; - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); CDamageVulnerability dVuln(in); - float f7 = in.readFloatBig(); + float f7 = in.ReadFloat(); CDamageInfo dInfo(in); const CAnimationParameters animParms = pInfo.GetAnimationParameters(); CModelData mData(CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), aHead.x40_scale, @@ -3276,16 +3239,16 @@ CEntity* ScriptLoader::LoadGeemer(CStateManager& mgr, CInputStream& in, int prop if (pInfo.GetAnimationParameters().GetACSFile() == CAssetId()) return nullptr; - float advanceWpRadius = in.readFloatBig(); - float f2 = in.readFloatBig(); - float alignAngVel = in.readFloatBig(); - float f4 = in.readFloatBig(); - float playerObstructionMinDist = in.readFloatBig(); - float haltDelay = in.readFloatBig(); - float forwardMoveWeight = in.readFloatBig(); - u16 haltSfx = in.readUint32Big() & 0xFFFF; - u16 getUpSfx = in.readUint32Big() & 0xFFFF; - u16 crouchSfx = in.readUint32Big() & 0xFFFF; + float advanceWpRadius = in.ReadFloat(); + float f2 = in.ReadFloat(); + float alignAngVel = in.ReadFloat(); + float f4 = in.ReadFloat(); + float playerObstructionMinDist = in.ReadFloat(); + float haltDelay = in.ReadFloat(); + float forwardMoveWeight = in.ReadFloat(); + u16 haltSfx = in.ReadLong() & 0xFFFF; + u16 getUpSfx = in.ReadLong() & 0xFFFF; + u16 crouchSfx = in.ReadLong() & 0xFFFF; CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), actHead.x40_scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3303,12 +3266,12 @@ CEntity* ScriptLoader::LoadSpindleCamera(CStateManager& mgr, CInputStream& in, i return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); u32 flags = LoadParameterFlags(in); - float hintToCamDistMin = in.readFloatBig(); - float hintToCamDistMax = in.readFloatBig(); - float hintToCamVOffMin = in.readFloatBig(); - float hintToCamVOffMax = in.readFloatBig(); + float hintToCamDistMin = in.ReadFloat(); + float hintToCamDistMax = in.ReadFloat(); + float hintToCamVOffMin = in.ReadFloat(); + float hintToCamVOffMax = in.ReadFloat(); SSpindleProperty targetHintToCamDeltaAngleVel(in); targetHintToCamDeltaAngleVel.FixupAngles(); @@ -3358,11 +3321,11 @@ CEntity* ScriptLoader::LoadAtomicAlpha(CStateManager& mgr, CInputStream& in, int CAssetId wpsc(in); CAssetId model(in); CDamageInfo dInfo(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - bool b1 = in.readBool(); - bool b2 = in.readBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + bool b1 = in.ReadBool(); + bool b2 = in.ReadBool(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), actHead.x40_scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3377,10 +3340,10 @@ CEntity* ScriptLoader::LoadCameraHintTrigger(CStateManager& mgr, CInputStream& i return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - zeus::CVector3f scale = 0.5f * zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); - bool deactivateOnEnter = in.readBool(); - bool deactivateOnExit = in.readBool(); + zeus::CVector3f scale = 0.5f * in.Get(); + bool active = in.ReadBool(); + bool deactivateOnEnter = in.ReadBool(); + bool deactivateOnExit = in.ReadBool(); zeus::CTransform xfRot = aHead.x10_transform.getRotation(); if (xfRot == zeus::CTransform()) @@ -3397,11 +3360,10 @@ CEntity* ScriptLoader::LoadRumbleEffect(CStateManager& mgr, CInputStream& in, in return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position; - position.readBig(in); - bool active = in.readBool(); - float f1 = in.readFloatBig(); - u32 w1 = in.readUint32Big(); + zeus::CVector3f position = in.Get(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); + u32 w1 = in.ReadLong(); u32 pFlags = LoadParameterFlags(in); return new CScriptSpecialFunction( @@ -3415,18 +3377,18 @@ CEntity* ScriptLoader::LoadAmbientAI(CStateManager& mgr, CInputStream& in, int p return nullptr; SScaledActorHead head = LoadScaledActorHead(in, mgr); - zeus::CVector3f collisionExtent = zeus::CVector3f::ReadBig(in); - zeus::CVector3f collisionOffset = zeus::CVector3f::ReadBig(in); - float mass = in.readFloatBig(); + zeus::CVector3f collisionExtent = in.Get(); + zeus::CVector3f collisionOffset = in.Get(); + float mass = in.ReadFloat(); CHealthInfo hInfo(in); CDamageVulnerability dVuln(in); CAnimationParameters animParms = LoadAnimationParameters(in); CActorParameters actParms = LoadActorParameters(in); - float alertRange = in.readFloatBig(); - float impactRange = in.readFloatBig(); - s32 alertAnim = in.readInt32Big(); - s32 impactAnim = in.readInt32Big(); - bool active = in.readBool(); + float alertRange = in.ReadFloat(); + float impactRange = in.ReadFloat(); + s32 alertAnim = in.ReadInt32(); + s32 impactAnim = in.ReadInt32(); + bool active = in.ReadBool(); if (!g_ResFactory->GetResourceTypeById(animParms.GetACSFile()).IsValid()) return nullptr; @@ -3457,17 +3419,17 @@ CEntity* ScriptLoader::LoadAtomicBeta(CStateManager& mgr, CInputStream& in, int CAssetId weaponId(in); CDamageInfo dInfo(in); CAssetId particleId(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); CDamageVulnerability dVuln(in); - float f4 = in.readFloatBig(); - float f5 = in.readFloatBig(); - float f6 = in.readFloatBig(); - s16 sId1 = s16(in.readInt32Big() & 0xFFFF); - s16 sId2 = s16(in.readInt32Big() & 0xFFFF); - s16 sId3 = s16(in.readInt32Big() & 0xFFFF); - float f7 = in.readFloatBig(); + float f4 = in.ReadFloat(); + float f5 = in.ReadFloat(); + float f6 = in.ReadFloat(); + s16 sId1 = s16(in.ReadInt32() & 0xFFFF); + s16 sId2 = s16(in.ReadInt32() & 0xFFFF); + s16 sId3 = s16(in.ReadInt32() & 0xFFFF); + float f7 = in.ReadFloat(); const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); CModelData mData(CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), aHead.x40_scale, animParms.GetInitialAnimation(), true)); @@ -3490,16 +3452,16 @@ CEntity* ScriptLoader::LoadIceZoomer(CStateManager& mgr, CInputStream& in, int p if (!animParms.GetACSFile().IsValid()) return nullptr; - float advanceWpRadius = in.readFloatBig(); - float f2 = in.readFloatBig(); - float alignAngleVel = in.readFloatBig(); - float f4 = in.readFloatBig(); - float playerObstructionMinDist = in.readFloatBig(); - float moveFowardWeight = in.readFloatBig(); - CAssetId modelRes(in.readUint32Big()); - CAssetId skinRes(in.readUint32Big()); + float advanceWpRadius = in.ReadFloat(); + float f2 = in.ReadFloat(); + float alignAngleVel = in.ReadFloat(); + float f4 = in.ReadFloat(); + float playerObstructionMinDist = in.ReadFloat(); + float moveFowardWeight = in.ReadFloat(); + CAssetId modelRes(in.ReadLong()); + CAssetId skinRes(in.ReadLong()); CDamageVulnerability dVuln(in); - float iceZoomerJointHP = in.readFloatBig(); + float iceZoomerJointHP = in.ReadFloat(); CModelData mData(CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), actHead.x40_scale, animParms.GetInitialAnimation(), true)); @@ -3524,16 +3486,16 @@ CEntity* ScriptLoader::LoadPuffer(CStateManager& mgr, CInputStream& in, int prop return nullptr; CActorParameters actorParameters = LoadActorParameters(in); - float hoverSpeed = in.readFloatBig(); + float hoverSpeed = in.ReadFloat(); CAssetId cloudEffect(in); CDamageInfo cloudDamage(in); CAssetId cloudSteam(in); - float f2 = in.readFloatBig(); - bool b1 = in.readBool(); - bool b2 = in.readBool(); - bool b3 = in.readBool(); + float f2 = in.ReadFloat(); + bool b1 = in.ReadBool(); + bool b2 = in.ReadBool(); + bool b3 = in.ReadBool(); CDamageInfo explosionDamage(in); - s16 sfxId = in.readUint16Big(); + s16 sfxId = in.ReadShort(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), aHead.x40_scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3558,10 +3520,10 @@ CEntity* ScriptLoader::LoadTryclops(CStateManager& mgr, CInputStream& in, int pr return nullptr; CActorParameters actorParameters = LoadActorParameters(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), actorHead.x40_scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3609,10 +3571,10 @@ CEntity* ScriptLoader::LoadSeedling(CStateManager& mgr, CInputStream& in, int pr CAssetId weaponId(in); CDamageInfo dInfo1(in); CDamageInfo dInfo2(in); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), aHead.x40_scale, pInfo.GetAnimationParameters().GetInitialAnimation(), true)); @@ -3626,9 +3588,9 @@ CEntity* ScriptLoader::LoadThermalHeatFader(CStateManager& mgr, CInputStream& in return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - float fadedLevel = in.readFloatBig(); - float initialLevel = in.readFloatBig(); + bool active = in.ReadBool(); + float fadedLevel = in.ReadFloat(); + float initialLevel = in.ReadFloat(); return new CScriptDistanceFog(mgr.AllocateUniqueId(), name, info, ERglFogMode::None, zeus::skBlack, zeus::CVector2f(), 0.f, zeus::CVector2f(), false, active, fadedLevel, initialLevel, 0.f, 0.f); } @@ -3654,7 +3616,7 @@ CEntity* ScriptLoader::LoadBurrower(CStateManager& mgr, CInputStream& in, int pr CDamageInfo dInfo(in); CAssetId w4(in); - u32 w5 = in.readUint32Big(); + u32 w5 = in.ReadLong(); CAssetId w6(in); CModelData mData(CAnimRes(pInfo.GetAnimationParameters().GetACSFile(), pInfo.GetAnimationParameters().GetCharacter(), @@ -3669,8 +3631,8 @@ CEntity* ScriptLoader::LoadBeam(CStateManager& mgr, CInputStream& in, int propCo return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); - u32 weaponDescId = in.readUint32Big(); + bool active = in.ReadBool(); + u32 weaponDescId = in.ReadLong(); if (!g_ResFactory->GetResourceTypeById(weaponDescId).IsValid()) return nullptr; @@ -3688,9 +3650,9 @@ CEntity* ScriptLoader::LoadWorldLightFader(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - bool active = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); return new CScriptDistanceFog(mgr.AllocateUniqueId(), name, info, ERglFogMode::None, zeus::skBlack, zeus::skZero2f, 0.f, zeus::skZero2f, false, active, 0.f, 0.f, f1, f2); @@ -3712,7 +3674,7 @@ CEntity* ScriptLoader::LoadMetroidPrimeEssence(CStateManager& mgr, CInputStream& CAssetId particle1{in}; CDamageInfo dInfo{in}; CAssetId electric{in}; - u32 w3 = in.readUint32Big(); + u32 w3 = in.ReadLong(); CAssetId particle2{in}; const CAnimationParameters& animParms = pInfo.GetAnimationParameters(); @@ -3727,26 +3689,26 @@ CEntity* ScriptLoader::LoadMetroidPrimeStage1(CStateManager& mgr, CInputStream& const CEntityInfo& info) { if (!EnsurePropertyCount(propCount, 22, "MetroidPrimeStage1")) return nullptr; - u32 version = in.readUint32Big(); + u32 version = in.ReadLong(); if (version != 3) return nullptr; SScaledActorHead aHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - u32 w1 = in.readUint32Big(); - bool b1 = in.readBool(); - u32 w2 = in.readUint32Big(); + bool active = in.ReadBool(); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + u32 w1 = in.ReadLong(); + bool b1 = in.ReadBool(); + u32 w2 = in.ReadLong(); CHealthInfo hInfo1(in); CHealthInfo hInfo2(in); - u32 w3 = in.readUint32Big(); + u32 w3 = in.ReadLong(); rstl::reserved_vector roomParms; for (int i = 0; i < 4; ++i) roomParms.emplace_back(in); - u32 w4 = in.readUint32Big(); - u32 w5 = in.readUint32Big(); + u32 w4 = in.ReadLong(); + u32 w5 = in.ReadLong(); MP1::SPrimeExoParameters primeParms(in); return new MP1::CMetroidPrimeRelay(mgr.AllocateUniqueId(), aHead.x0_name, info, active, aHead.x10_transform, @@ -3759,13 +3721,13 @@ CEntity* ScriptLoader::LoadMazeNode(CStateManager& mgr, CInputStream& in, int pr return nullptr; SActorHead aHead = LoadActorHead(in, mgr); - bool active = in.readBool(); - u32 col = in.readUint32Big(); - u32 row = in.readUint32Big(); - u32 side = in.readUint32Big(); - zeus::CVector3f actorPos = zeus::CVector3f::ReadBig(in); - zeus::CVector3f triggerPos = zeus::CVector3f::ReadBig(in); - zeus::CVector3f effectPos = zeus::CVector3f::ReadBig(in); + bool active = in.ReadBool(); + u32 col = in.ReadLong(); + u32 row = in.ReadLong(); + u32 side = in.ReadLong(); + zeus::CVector3f actorPos = in.Get(); + zeus::CVector3f triggerPos = in.Get(); + zeus::CVector3f effectPos = in.Get(); return new CScriptMazeNode(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, col, row, side, actorPos, triggerPos, effectPos); @@ -3806,20 +3768,20 @@ CEntity* ScriptLoader::LoadPhazonPool(CStateManager& mgr, CInputStream& in, int } SScaledActorHead actHead = LoadScaledActorHead(in, mgr); - bool active = in.readBool(); + bool active = in.ReadBool(); CAssetId w1{in}; CAssetId w2{in}; CAssetId w3{in}; CAssetId w4{in}; - u32 u1 = in.readUint32Big(); + u32 u1 = in.ReadLong(); CDamageInfo dInfo{in}; - zeus::CVector3f orientedForce{in.readVec3f()}; - ETriggerFlags triggerFlags = static_cast(in.readUint32Big()); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - bool b2 = in.readBool(); - float f4 = in.readFloatBig(); + zeus::CVector3f orientedForce = in.Get(); + ETriggerFlags triggerFlags = static_cast(in.ReadLong()); + float f1 = in.ReadFloat(); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + bool b2 = in.ReadBool(); + float f4 = in.ReadFloat(); return new MP1::CPhazonPool(mgr.AllocateUniqueId(), actHead.x0_name, info, zeus::CTransform::Translate(actHead.x10_transform.origin), actHead.x40_scale, active, w1, @@ -3841,9 +3803,9 @@ CEntity* ScriptLoader::LoadPhazonHealingNodule(CStateManager& mgr, CInputStream& CPatternedInfo pInfo(in, pair.second); CActorParameters actParms = LoadActorParameters(in); - in.readBool(); + in.ReadBool(); CAssetId w1{in}; - std::string w2 = in.readString(); + std::string w2 = in.Get(); if (!pInfo.GetAnimationParameters().GetACSFile().IsValid()) { return nullptr; @@ -3862,11 +3824,11 @@ CEntity* ScriptLoader::LoadNewCameraShaker(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f sfxPos = zeus::CVector3f::ReadBig(in); - bool active = in.readBool(); + zeus::CVector3f sfxPos = in.Get(); + bool active = in.ReadBool(); u32 flags = LoadParameterFlags(in); - float duration = in.readFloatBig(); - float sfxDist = in.readFloatBig(); + float duration = in.ReadFloat(); + float sfxDist = in.ReadFloat(); CCameraShakerComponent shakerX = CCameraShakerComponent::LoadNewCameraShakerComponent(in); CCameraShakerComponent shakerY = CCameraShakerComponent::LoadNewCameraShakerComponent(in); CCameraShakerComponent shakerZ = CCameraShakerComponent::LoadNewCameraShakerComponent(in); @@ -3882,15 +3844,15 @@ CEntity* ScriptLoader::LoadShadowProjector(CStateManager& mgr, CInputStream& in, return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CVector3f position(zeus::CVector3f::ReadBig(in)); - bool b1 = in.readBool(); - float f1 = in.readFloatBig(); - zeus::CVector3f vec2(zeus::CVector3f::ReadBig(in)); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); - bool b2 = in.readBool(); - u32 w1 = in.readUint32Big(); + zeus::CVector3f position( in.Get()); + bool b1 = in.ReadBool(); + float f1 = in.ReadFloat(); + zeus::CVector3f vec2( in.Get()); + float f2 = in.ReadFloat(); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); + bool b2 = in.ReadBool(); + u32 w1 = in.ReadLong(); return new CScriptShadowProjector(mgr.AllocateUniqueId(), name, info, zeus::CTransform::Translate(position), b1, vec2, b2, f1, f2, f3, f4, w1); } @@ -3910,21 +3872,21 @@ CEntity* ScriptLoader::LoadEnergyBall(CStateManager& mgr, CInputStream& in, int return nullptr; CActorParameters actParms = LoadActorParameters(in); - u32 w1 = in.readUint32Big(); - float f1 = in.readFloatBig(); + u32 w1 = in.ReadLong(); + float f1 = in.ReadFloat(); CDamageInfo dInfo1(in); - float f2 = in.readFloatBig(); + float f2 = in.ReadFloat(); CAssetId a1(in); - s16 sfxId1 = CSfxManager::TranslateSFXID(in.readUint32Big()); + s16 sfxId1 = CSfxManager::TranslateSFXID(in.ReadLong()); CAssetId a2(in); CAssetId a3(in); - s16 sfxId2 = CSfxManager::TranslateSFXID(in.readUint32Big()); - float f3 = in.readFloatBig(); - float f4 = in.readFloatBig(); + s16 sfxId2 = CSfxManager::TranslateSFXID(in.ReadLong()); + float f3 = in.ReadFloat(); + float f4 = in.ReadFloat(); CAssetId a4(in); CDamageInfo dInfo2 = propCount >= 19 ? CDamageInfo(in) : CDamageInfo(); - float f5 = propCount >= 20 ? in.readFloatBig() : 3.0f; + float f5 = propCount >= 20 ? in.ReadFloat() : 3.0f; CModelData mData(CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), actorHead.x40_scale, animParms.GetInitialAnimation(), true));