diff --git a/DataSpec/DNAMP1/ScriptObjects/Water.hpp b/DataSpec/DNAMP1/ScriptObjects/Water.hpp index 4052d9ec8..52f52d6b9 100644 --- a/DataSpec/DNAMP1/ScriptObjects/Water.hpp +++ b/DataSpec/DNAMP1/ScriptObjects/Water.hpp @@ -37,23 +37,22 @@ struct Water : IScriptObject struct FluidUVMotion : BigYAML { DECL_YAML - Value unknown1; + struct FluidLayerMotion : BigYAML + { + DECL_YAML + Value unknown1; + Value unknown2; + Value unknown3; + Value unknown4; + Value unknown5; + }; + + /* BIG FAT WARNING: Do NOT re-order these, even if they seem incorrect */ + FluidLayerMotion layer2; + FluidLayerMotion layer3; + FluidLayerMotion layer1; + Value unknown1; Value unknown2; - Value unknown3; - Value unknown4; - Value unknown5; - Value unknown6; - Value unknown7; - Value unknown8; - Value unknown9; - Value unknown10; - Value unknown11; - Value unknown12; - Value unknown13; - Value unknown14; - Value unknown15; - Value unknown16; - Value unknown17; } fluidUVMotion; Value unknown13; diff --git a/Runtime/World/CFluidPlane.hpp b/Runtime/World/CFluidPlane.hpp new file mode 100644 index 000000000..f96ea4e2e --- /dev/null +++ b/Runtime/World/CFluidPlane.hpp @@ -0,0 +1,14 @@ +#ifndef __URDE_CFLUIDPLANE_HPP__ +#define __URDE_CFLUIDPLANE_HPP__ + +namespace urde +{ +class CFluidPlane +{ +public: + enum class EFluidType + {}; +}; +} + +#endif // __URDE_CFLUIDPLANE_HPP__ diff --git a/Runtime/World/CFluidUVMotion.cpp b/Runtime/World/CFluidUVMotion.cpp new file mode 100644 index 000000000..1962f73d1 --- /dev/null +++ b/Runtime/World/CFluidUVMotion.cpp @@ -0,0 +1,16 @@ +#include "CFluidUVMotion.hpp" + +namespace urde +{ + +CFluidUVMotion::CFluidUVMotion(float a, float b, const urde::CFluidUVMotion::SFluidLayerMotion& c, const urde::CFluidUVMotion::SFluidLayerMotion& d, const urde::CFluidUVMotion::SFluidLayerMotion& e) +{ + x4c_ = 1.f / a; + x50_ = b; + x0_fluidLayers.resize(3); + x0_fluidLayers[0] = c; + x0_fluidLayers[1] = d; + x0_fluidLayers[2] = e; +} + +} diff --git a/Runtime/World/CFluidUVMotion.hpp b/Runtime/World/CFluidUVMotion.hpp new file mode 100644 index 000000000..7493a36d5 --- /dev/null +++ b/Runtime/World/CFluidUVMotion.hpp @@ -0,0 +1,40 @@ +#ifndef __URDE_CFLUIDUVMOTION_HPP__ +#define __URDE_CFLUIDUVMOTION_HPP__ + +#include "rstl.hpp" + +namespace urde +{ +class CFluidUVMotion +{ +public: + enum class EFluidUVMotion + { + Zero + }; + + struct SFluidLayerMotion + { + EFluidUVMotion x0_motion = EFluidUVMotion::Zero; + float x4_a = 0.f; + float x8_b = 0.f; + float xc_c = 0.f; + float x10_d = 0.f; + float x14_e = 0.f; + + SFluidLayerMotion() = default; + SFluidLayerMotion(EFluidUVMotion motion, float a, float b, float c, float d) + : x0_motion(motion), x4_a(1.f / a), x8_b(b), xc_c(c), x10_d(d), x14_e(1.f / d) + { + } + }; + +private: + rstl::reserved_vector x0_fluidLayers; + float x4c_; + float x50_; +public: + CFluidUVMotion(float a, float b, const SFluidLayerMotion& c, const SFluidLayerMotion& d, const SFluidLayerMotion& e); +}; +} +#endif // __URDE_CFLUIDUVMOTION_HPP__ diff --git a/Runtime/World/CMakeLists.txt b/Runtime/World/CMakeLists.txt index 810be39c5..91e09aca6 100644 --- a/Runtime/World/CMakeLists.txt +++ b/Runtime/World/CMakeLists.txt @@ -28,4 +28,6 @@ add_library(RuntimeCommonWorld CVisorParameters.hpp CAnimationParameters.hpp CDamageInfo.hpp - CDamageVulnerability.hpp) + CDamageVulnerability.hpp + CFluidUVMotion.hpp CFluidUVMotion.cpp + CFluidPlane.hpp) diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index e4b0562f1..d1caa19ad 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -9,7 +9,7 @@ namespace urde CScriptTrigger::CScriptTrigger(TUniqueId uid, const std::string& name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox&, const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, - u32, bool active, bool, bool) + u32 triggerFlags, bool active, bool, bool) : CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(), CMaterialList(34), CActorParameters::None(), kInvalidUniqueId) { diff --git a/Runtime/World/CScriptTrigger.hpp b/Runtime/World/CScriptTrigger.hpp index 3a5a8a3fc..f1ea113c2 100644 --- a/Runtime/World/CScriptTrigger.hpp +++ b/Runtime/World/CScriptTrigger.hpp @@ -13,7 +13,7 @@ public: CScriptTrigger(TUniqueId, const std::string& name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox&, const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, - u32, bool, bool, bool); + u32 triggerFlags, bool, bool, bool); }; } diff --git a/Runtime/World/CScriptWater.cpp b/Runtime/World/CScriptWater.cpp index e69de29bb..5fe20c944 100644 --- a/Runtime/World/CScriptWater.cpp +++ b/Runtime/World/CScriptWater.cpp @@ -0,0 +1,21 @@ +#include "CScriptWater.hpp" +#include "CStateManager.hpp" + +namespace urde +{ + +CScriptWater::CScriptWater(CStateManager& mgr, TUniqueId uid, const std::string& name, + const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& box, + const urde::CDamageInfo& dInfo, zeus::CVector3f& orientedForce, u32 triggerFlags, + bool b1, bool b2, ResId, ResId, ResId, ResId, ResId, ResId, ResId, + const zeus::CVector3f&, float, float, float, bool active, CFluidPlane::EFluidType, + bool, float, const CFluidUVMotion&, + float, float, float, float, float, float, float, float, + const zeus::CColor&, const zeus::CColor&, ResId, ResId, ResId, ResId, + ResId, s32, s32, s32, s32, s32, float, u32, float, float, float, float, float, float, float, float, + const zeus::CColor&, urde::ResId, float, float, float, u32, u32, bool, s32, s32, const u32*) + : CScriptTrigger(uid, name, info, pos, box, dInfo, orientedForce, triggerFlags, active, false, false) +{ +} + +} diff --git a/Runtime/World/CScriptWater.hpp b/Runtime/World/CScriptWater.hpp index d910d3947..4cc52245a 100644 --- a/Runtime/World/CScriptWater.hpp +++ b/Runtime/World/CScriptWater.hpp @@ -1,13 +1,26 @@ #ifndef __URDE_CSCRIPTWATER_HPP__ #define __URDE_CSCRIPTWATER_HPP__ -#include "CActor.hpp" +#include "CScriptTrigger.hpp" +#include "CFluidPlane.hpp" namespace urde { -class CScriptWater : public CActor +class CDamageInfo; +class CFluidUVMotion; + +class CScriptWater : public CScriptTrigger { +public: + CScriptWater(CStateManager &,TUniqueId, const std::string& name, const CEntityInfo&, const zeus::CVector3f&, + const zeus::CAABox&, CDamageInfo const &, zeus::CVector3f&, u32, bool, bool, + ResId, ResId, ResId, ResId, ResId, ResId, ResId, + const zeus::CVector3f&, float, float, float, bool, CFluidPlane::EFluidType, bool, float, const CFluidUVMotion&, + float, float, float, float, float, float, float, float, const zeus::CColor&, const zeus::CColor&, + ResId, ResId, ResId, ResId, ResId, s32, s32, s32, s32, s32, + float, u32, float, float, float, float, float, float, float, float, + const zeus::CColor&, ResId, float, float, float, u32, u32, bool, s32, s32, const u32*); }; } diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 032f0d2fa..77088eb49 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -6,6 +6,7 @@ #include "CScannableParameters.hpp" #include "CLightParameters.hpp" #include "CAnimationParameters.hpp" +#include "CFluidUVMotion.hpp" #include "GameGlobalObjects.hpp" #include "CWorld.hpp" #include "Character/CModelData.hpp" @@ -17,6 +18,7 @@ #include "CScriptTrigger.hpp" #include "CScriptTimer.hpp" #include "CScriptCounter.hpp" +#include "CScriptWater.hpp" #include "CSimplePool.hpp" #include "Editor/ProjectResourceFactoryMP1.hpp" #include "logvisor/logvisor.hpp" @@ -263,6 +265,40 @@ CAnimationParameters ScriptLoader::LoadAnimationParameters(CInputStream& in) return CAnimationParameters(ancs, charIdx, defaultAnim); } +CFluidUVMotion ScriptLoader::LoadFluidUVMotion(CInputStream& in) +{ + CFluidUVMotion::EFluidUVMotion motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); + float a = in.readFloatBig(); + float b = in.readFloatBig(); + b = ((M_PIF * b) / 180.f) - M_PIF; + float c = in.readFloatBig(); + float d = in.readFloatBig(); + CFluidUVMotion::SFluidLayerMotion motionLayer2(motion, a, b, c, d); + + motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); + a = in.readFloatBig(); + b = in.readFloatBig(); + b = ((M_PIF * b) / 180.f) - M_PIF; + c = in.readFloatBig(); + d = in.readFloatBig(); + CFluidUVMotion::SFluidLayerMotion motionLayer3(motion, a, b, c, d); + + motion = CFluidUVMotion::EFluidUVMotion(in.readUint32Big()); + a = in.readFloatBig(); + b = in.readFloatBig(); + b = ((M_PIF * b) / 180.f) - M_PIF; + c = in.readFloatBig(); + d = in.readFloatBig(); + CFluidUVMotion::SFluidLayerMotion motionLayer1(motion, a, b, c, d); + + a = in.readFloatBig(); + b = in.readFloatBig(); + + b = ((M_PIF * b) / 180.f) - M_PIF; + + return CFluidUVMotion(a, b, motionLayer1, motionLayer2, motionLayer3); +} + zeus::CTransform ScriptLoader::ConvertEditorEulerToTransform4f(const zeus::CVector3f& orientation, const zeus::CVector3f& position) { @@ -608,6 +644,113 @@ CEntity* ScriptLoader::LoadActorKeyframe(CStateManager& mgr, CInputStream& in, CEntity* ScriptLoader::LoadWater(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { + if (!EnsurePropertyCount(propCount, 63, "Water")) + return nullptr; + + std::string name = *mgr.HashInstanceName(in); + zeus::CVector3f position; + position.readBig(in); + zeus::CVector3f extent; + extent.readBig(in); + CDamageInfo dInfo(in); + zeus::CVector3f orientedForce; + orientedForce.readBig(in); + u32 triggerFlags = in.readUint32Big() | 2044; + bool b1 = in.readBool(); + bool b2 = in.readBool(); + ResId textureId1 = in.readUint32Big(); + ResId textureId2 = in.readUint32Big(); + ResId textureId3 = in.readUint32Big(); + ResId textureId4 = in.readUint32Big(); + ResId textureId5 = in.readUint32Big(); + ResId textureId6 = in.readUint32Big(); + zeus::CVector3f v2; + v2.readBig(in); + + zeus::CVector3f otherV2 = v2; + if (otherV2.canBeNormalized()) + otherV2.assign(0.f, 0.f, -1.f); + + float f1 = 1.f / in.readFloatBig(); + float f2 = in.readFloatBig(); + float f3 = in.readFloatBig(); + bool active = in.readBool(); + CFluidPlane::EFluidType fluidType = CFluidPlane::EFluidType(in.readUint32Big()); + bool b4 = in.readBool(); + float f4 = in.readFloatBig(); + CFluidUVMotion fluidMotion = LoadFluidUVMotion(in); + + float f5 = in.readFloatBig(); + float f6 = in.readFloatBig(); + float f7 = in.readFloatBig(); + float f8 = in.readFloatBig(); + float f9 = zeus::degToRad(in.readFloatBig()); + float f10 = zeus::degToRad(in.readFloatBig()); + float f11 = in.readFloatBig(); + float f12 = in.readFloatBig(); + zeus::CColor c1; + c1.readRGBABig(in); + zeus::CColor c2; + c2.readRGBABig(in); + ResId partId1 = in.readUint32Big(); + ResId partId2 = in.readUint32Big(); + ResId partId3 = in.readUint32Big(); + ResId partId4 = in.readUint32Big(); + ResId partId5 = in.readUint32Big(); + u32 soundId1 = in.readUint32Big(); + u32 soundId2 = in.readUint32Big(); + u32 soundId3 = in.readUint32Big(); + u32 soundId4 = in.readUint32Big(); + u32 soundId5 = in.readUint32Big(); + float f13 = in.readFloatBig(); + u32 w19 = in.readUint32Big(); + 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 f21 = in.readFloatBig(); + zeus::CColor c3; + c3.readRGBABig(in); + ResId lightmap = in.readUint32Big(); + float f22 = in.readFloatBig(); + float f23 = in.readFloatBig(); + float f24 = in.readFloatBig(); + u32 w21 = in.readUint32Big(); + u32 w22 = in.readUint32Big(); + bool b5 = in.readBool(); + + u32* bitset = nullptr; + u32 bitVal0 = 0; + u32 bitVal1 = 0; + + if (b5) + { + bitVal0 = in.readUint16Big(); + bitVal1 = in.readUint16Big(); + u32 len = ((bitVal0 * bitVal1) + 31) / 31; + bitset = new u32[len]; + in.readBytesToBuf(&bitset, len * 4); + } + + zeus::CAABox box(-extent * 0.5f, extent * 0.5f); + + ResId realTextureId6 = -1; + if (textureId4 == -1) + realTextureId6 = textureId6; + + ResId realTextureId5 = -1; + if (textureId4 == -1) + realTextureId5 = textureId5; + + return new CScriptWater(mgr, mgr.AllocateUniqueId(), name, info, position, box, dInfo, orientedForce, triggerFlags, b1, b2, + textureId1, textureId2, textureId3, textureId4, realTextureId5, realTextureId6, -1, otherV2, f1, f2, + f3, active, fluidType, b4, f4, fluidMotion, f5, f6, f7, f8, f9, f10, f11, f12, c1, c2, partId1, + partId2, partId3, partId4, partId5, soundId1, soundId2, soundId3, soundId4, soundId5, + f13, w19, f14, f15, f16, f17, f18, f19, f20, f21, c3, lightmap, f22, f23, f24, + w21, w22, b5, bitVal0, bitVal0, bitset); } CEntity* ScriptLoader::LoadWarwasp(CStateManager& mgr, CInputStream& in, diff --git a/Runtime/World/ScriptLoader.hpp b/Runtime/World/ScriptLoader.hpp index 9395b175f..ee38d2344 100644 --- a/Runtime/World/ScriptLoader.hpp +++ b/Runtime/World/ScriptLoader.hpp @@ -15,6 +15,7 @@ class CVisorParameters; class CScannableParameters; class CLightParameters; class CAnimationParameters; +class CFluidUVMotion; using FScriptLoader = std::function; @@ -29,6 +30,7 @@ public: static CScannableParameters LoadScannableParameters(CInputStream& in); static CLightParameters LoadLightParameters(CInputStream& in); static CAnimationParameters LoadAnimationParameters(CInputStream& in); + static CFluidUVMotion LoadFluidUVMotion(CInputStream& in); static zeus::CTransform ConvertEditorEulerToTransform4f(const zeus::CVector3f& orientation, const zeus::CVector3f& position);