From c614d2d2d1057f378f3a8fa030b99fba8370201b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 17 Apr 2016 19:33:23 -1000 Subject: [PATCH] ScriptLoader support imps --- DataSpec/DNAMP1/ScriptObjects/Actor.hpp | 4 +- Runtime/CStateManager.cpp | 4 +- Runtime/CStateManager.hpp | 2 +- Runtime/World/CAi.hpp | 51 +++++ Runtime/World/CAnimationParameters.hpp | 21 ++ Runtime/World/CGrappleParameters.hpp | 31 +-- Runtime/World/CMakeLists.txt | 3 +- Runtime/World/CScannableParameters.hpp | 2 + Runtime/World/CVisorParameters.hpp | 10 +- Runtime/World/ScriptLoader.cpp | 253 ++++++++++++++++++++++-- Runtime/World/ScriptLoader.hpp | 22 ++- Runtime/World/ScriptObjectSupport.hpp | 2 +- 12 files changed, 366 insertions(+), 39 deletions(-) create mode 100644 Runtime/World/CAnimationParameters.hpp diff --git a/DataSpec/DNAMP1/ScriptObjects/Actor.hpp b/DataSpec/DNAMP1/ScriptObjects/Actor.hpp index c51f988cc..49ffcbbec 100644 --- a/DataSpec/DNAMP1/ScriptObjects/Actor.hpp +++ b/DataSpec/DNAMP1/ScriptObjects/Actor.hpp @@ -15,8 +15,8 @@ struct Actor : IScriptObject Value location; Value orientation; Value scale; - Value unkown1; - Value scanOffset; + Value collisionExtent; + Value centroid; Value unknown2; Value unknown3; HealthInfo healthInfo; diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index de6846a9d..ca04b5670 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -98,7 +98,7 @@ CStateManager::CStateManager(const std::weak_ptr&, x904_loaderFuncs[int(EScriptObjectType::Ripple)] = ScriptLoader::LoadRipple; x904_loaderFuncs[int(EScriptObjectType::BallTrigger)] = ScriptLoader::LoadBallTrigger; x904_loaderFuncs[int(EScriptObjectType::TargetingPoint)] = ScriptLoader::LoadTargetingPoint; - x904_loaderFuncs[int(EScriptObjectType::ElectroMagneticPulse)] = ScriptLoader::LoadElectroMagneticPulse; + x904_loaderFuncs[int(EScriptObjectType::EMPulse)] = ScriptLoader::LoadEMPulse; x904_loaderFuncs[int(EScriptObjectType::IceSheegoth)] = ScriptLoader::LoadIceSheegoth; x904_loaderFuncs[int(EScriptObjectType::PlayerActor)] = ScriptLoader::LoadPlayerActor; x904_loaderFuncs[int(EScriptObjectType::Flaahgra)] = ScriptLoader::LoadFlaahgra; @@ -211,7 +211,7 @@ void CStateManager::MurderScriptInstanceNames() { } -void CStateManager::HashInstanceName(CInputStream& in) +const std::string* CStateManager::HashInstanceName(CInputStream& in) { } diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 5f743e91b..18dcfb1e3 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -147,7 +147,7 @@ public: void ResetEscapeSequenceTimer(float); void SetupParticleHook(const CActor& actor) const; void MurderScriptInstanceNames(); - void HashInstanceName(CInputStream& in); + const std::string* HashInstanceName(CInputStream& in); void SetActorAreaId(CActor& actor, TAreaId); void TouchSky() const; void DrawSpaceWarp(const zeus::CVector3f&, float) const; diff --git a/Runtime/World/CAi.hpp b/Runtime/World/CAi.hpp index 350ab51ea..5c7f0ccc1 100644 --- a/Runtime/World/CAi.hpp +++ b/Runtime/World/CAi.hpp @@ -30,11 +30,62 @@ class CAiFuncMap /* TODO: Move these */ class CHealthInfo +{ + float x0_; + float x4_; +public: + CHealthInfo(CInputStream& in) : x0_(in.readFloatBig()), x4_(in.readFloatBig()) {} +}; + +enum class EVulnerability { }; class CDamageVulnerability { + EVulnerability x0_power; + EVulnerability x4_ice; + EVulnerability x8_wave; + EVulnerability xc_plasma; + EVulnerability x10_bomb; + EVulnerability x14_powerbomb; + EVulnerability x18_missile; + EVulnerability x1c_boostBall; + EVulnerability x20_phazon; + EVulnerability x24_enemyWp1; + EVulnerability x28_enemyWp2Poison; + EVulnerability x2c_enemyWp3Lava; + EVulnerability x30_enemyWp4; + EVulnerability x34_unk1; + EVulnerability x38_unk2; + EVulnerability x3c_unk3; + +#if 0 + struct ChargedBeams : BigYAML + { + DECL_YAML + Value propertyCount; + Value power; + Value ice; + Value wave; + Value plasma; + Value phazon; + } chargedBeams; + + struct BeamCombos : BigYAML + { + DECL_YAML + Value propertyCount; + Value superMissiles; + Value iceSpreader; + Value wavebuster; + Value flameThrower; + Value phazonCombo; + } beamCombos; +#endif + +public: + CDamageVulnerability(CInputStream& in) {} }; class CStateManager; diff --git a/Runtime/World/CAnimationParameters.hpp b/Runtime/World/CAnimationParameters.hpp new file mode 100644 index 000000000..df7b50178 --- /dev/null +++ b/Runtime/World/CAnimationParameters.hpp @@ -0,0 +1,21 @@ +#ifndef __URDE_CANIMATIONPARAMETERS_HPP__ +#define __URDE_CANIMATIONPARAMETERS_HPP__ + +#include "RetroTypes.hpp" + +namespace urde +{ + +class CAnimationParameters +{ + ResId x0_ancs; + s32 x4_charIdx; + u32 x8_defaultAnim; +public: + CAnimationParameters(ResId ancs, s32 charIdx, u32 defaultAnim) + : x0_ancs(ancs), x4_charIdx(charIdx), x8_defaultAnim(defaultAnim) {} +}; + +} + +#endif // __URDE_CANIMATIONPARAMETERS_HPP__ diff --git a/Runtime/World/CGrappleParameters.hpp b/Runtime/World/CGrappleParameters.hpp index fd93fd5d3..aa8aef4d6 100644 --- a/Runtime/World/CGrappleParameters.hpp +++ b/Runtime/World/CGrappleParameters.hpp @@ -6,18 +6,25 @@ namespace urde class CGrappleParameters { - float x0_; - float x4_; - float x8_; - float xc_; - float x10_; - float x14_; - float x18_; - float x1c_; - float x20_; - float x24_; - float x28_; - bool x2c_; + float x0_a; + float x4_b; + float x8_c; + float xc_d; + float x10_e; + float x14_f; + float x18_g; + float x1c_h; + float x20_i; + float x24_j; + float x28_k; + bool x2c_l; +public: + CGrappleParameters(float a, float b, float c, float d, + float e, float f, float g, float h, + float i, float j, float k, bool l) + : x0_a(a), x4_b(b), x8_c(c), xc_d(d), + x10_e(e), x14_f(f), x18_g(g), x1c_h(h), + x20_i(i), x24_j(j), x28_k(k), x2c_l(l) {} }; } diff --git a/Runtime/World/CMakeLists.txt b/Runtime/World/CMakeLists.txt index e724e2866..5bb37b23a 100644 --- a/Runtime/World/CMakeLists.txt +++ b/Runtime/World/CMakeLists.txt @@ -19,4 +19,5 @@ add_library(RuntimeCommonWorld CActorParameters.hpp CLightParameters.hpp CScannableParameters.hpp - CVisorParameters.hpp) + CVisorParameters.hpp + CAnimationParameters.hpp) diff --git a/Runtime/World/CScannableParameters.hpp b/Runtime/World/CScannableParameters.hpp index 3518fd8ff..0aa4d7654 100644 --- a/Runtime/World/CScannableParameters.hpp +++ b/Runtime/World/CScannableParameters.hpp @@ -10,6 +10,8 @@ class CScannableParameters { ResId x0_scanId = -1; public: + CScannableParameters() = default; + CScannableParameters(ResId id) : x0_scanId(id) {} }; } diff --git a/Runtime/World/CVisorParameters.hpp b/Runtime/World/CVisorParameters.hpp index 79bfa28b8..02097a1dd 100644 --- a/Runtime/World/CVisorParameters.hpp +++ b/Runtime/World/CVisorParameters.hpp @@ -8,12 +8,14 @@ namespace urde class CVisorParameters { - u8 mask : 4; - bool b1 : 1; - bool b2 : 1; + u8 x0_mask : 4; + bool x0_4_b1 : 1; + bool x0_5_b2 : 1; public: CVisorParameters() - : mask(0xf), b1(false), b2(false) {} + : x0_mask(0xf), x0_4_b1(false), x0_5_b2(false) {} + CVisorParameters(u8 mask, bool b1, bool b2) + : x0_mask(mask), x0_4_b1(b1), x0_5_b2(b2) {} }; } diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index a5e40cec3..b6cef48df 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -1,4 +1,12 @@ #include "ScriptLoader.hpp" +#include "CStateManager.hpp" +#include "CGrappleParameters.hpp" +#include "CActorParameters.hpp" +#include "CVisorParameters.hpp" +#include "CScannableParameters.hpp" +#include "CLightParameters.hpp" +#include "CAnimationParameters.hpp" +#include "GameGlobalObjects.hpp" #include "logvisor/logvisor.hpp" namespace urde @@ -16,12 +24,245 @@ static bool EnsurePropertyCount(int count, int expected, const char* structName) return true; } +struct SActorHead +{ + std::string x0_name; + zeus::CTransform x10_transform; +}; + +struct SScaledActorHead : SActorHead +{ + zeus::CVector3f x40_scale; + SScaledActorHead(SActorHead&& head) : SActorHead(std::move(head)) {} +}; + +static zeus::CTransform LoadEditorTransform(CInputStream& in) +{ + zeus::CVector3f position; + position.readBig(in); + zeus::CVector3f orientation; + orientation.readBig(in); + return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position); +} + +static zeus::CTransform LoadEditorTransformPivotOnly(CInputStream& in) +{ + zeus::CVector3f position; + position.readBig(in); + zeus::CVector3f orientation; + orientation.readBig(in); + orientation.x = 0.f; + orientation.y = 0.f; + return ScriptLoader::ConvertEditorEulerToTransform4f(orientation, position); +} + +static SActorHead LoadActorHead(CInputStream& in, CStateManager& stateMgr) +{ + SActorHead ret; + ret.x0_name = *stateMgr.HashInstanceName(in); + ret.x10_transform = LoadEditorTransform(in); + return ret; +} + +static SScaledActorHead LoadScaledActorHead(CInputStream& in, CStateManager& stateMgr) +{ + SScaledActorHead ret = LoadActorHead(in, stateMgr); + ret.x40_scale.readBig(in); + return ret; +} + +u32 ScriptLoader::LoadParameterFlags(CInputStream& in) +{ + u32 count = in.readUint32Big(); + u32 ret = 0; + for (u32 i=0 ; i= 5 && propCount <= 0xe) + { + CLightParameters lParms = ScriptLoader::LoadLightParameters(in); + + CScannableParameters sParams; + if (propCount > 5) + sParams = LoadScannableParameters(in); + + ResId xrayModel = in.readUint32Big(); + ResId xraySkin = in.readUint32Big(); + ResId infraModel = in.readUint32Big(); + ResId infraSkin = in.readUint32Big(); + + bool b1 = true; + if (propCount > 7) + b1 = in.readBool(); + + float f1 = 1.f; + if (propCount > 8) + f1 = in.readFloatBig(); + + float f2 = 1.f; + if (propCount > 9) + f2 = in.readFloatBig(); + + CVisorParameters vParms; + if (propCount > 6) + vParms = LoadVisorParameters(in); + + bool b2 = false; + if (propCount > 10) + b2 = in.readBool(); + + bool b3 = false; + if (propCount > 11) + b3 = in.readBool(); + + bool b4 = false; + if (propCount > 12) + b4 = in.readBool(); + + float f3 = 1.f; + if (propCount > 13) + f3 = in.readFloatBig(); + + std::pair xray = {}; + if (g_ResFactory->GetResourceTypeById(xrayModel)) + xray = {xrayModel, xraySkin}; + + std::pair infra = {}; + if (g_ResFactory->GetResourceTypeById(infraModel)) + infra = {infraModel, infraSkin}; + + return CActorParameters(lParms, sParams, xray, infra, vParms, b1, b2, b3, b4); + } + return CActorParameters::None(); +} + +CVisorParameters ScriptLoader::LoadVisorParameters(CInputStream& in) +{ + u32 propCount = in.readUint32Big(); + if (propCount >= 1 && propCount <= 3) + { + bool b1 = in.readBool(); + bool b2 = false; + u8 mask = 0xf; + if (propCount > 1) + b2 = in.readBool(); + if (propCount > 2) + mask = in.readUint32Big(); + return CVisorParameters(mask, b1, b2); + } + return CVisorParameters(); +} + +CScannableParameters ScriptLoader::LoadScannableParameters(CInputStream& in) +{ + u32 propCount = in.readUint32Big(); + if (propCount == 1) + return CScannableParameters(in.readUint32Big()); + return CScannableParameters(); +} + +CLightParameters ScriptLoader::LoadLightParameters(CInputStream& in) +{ + u32 propCount = in.readUint32Big(); + if (propCount == 14) + { + bool a = in.readBool(); + float b = in.readFloatBig(); + u32 c = in.readUint32Big(); + float d = in.readFloatBig(); + float e = in.readFloatBig(); + + zeus::CColor col; + col.readRGBABig(in); + + bool f = in.readBool(); + u32 g = in.readUint32Big(); + u32 h = in.readUint32Big(); + + zeus::CVector3f vec; + vec.readBig(in); + + s32 w1 = -1; + s32 w2 = -1; + if (propCount >= 0xc) + { + w1 = in.readUint32Big(); + w2 = in.readUint32Big(); + } + + bool b1 = false; + if (propCount >= 0xd) + b1 = in.readBool(); + + s32 w3 = 0; + if (propCount >= 0xe) + w3 = in.readUint32Big(); + + return CLightParameters(a, b, c, d, e, col, f, g, h, vec, w1, w2, b1, w3); + } + return CLightParameters::None(); +} + +CAnimationParameters ScriptLoader::LoadAnimationParameters(CInputStream& in) +{ + ResId ancs = in.readUint32Big(); + s32 charIdx = in.readUint32Big(); + u32 defaultAnim = in.readUint32Big(); + return CAnimationParameters(ancs, charIdx, defaultAnim); +} + +zeus::CTransform ScriptLoader::ConvertEditorEulerToTransform4f(const zeus::CVector3f& orientation, + const zeus::CVector3f& position) +{ + return zeus::CTransform::RotateZ(zeus::degToRad(orientation.z)) * + zeus::CTransform::RotateY(zeus::degToRad(orientation.y)) * + zeus::CTransform::RotateX(zeus::degToRad(orientation.x)) + position; +} + CEntity* ScriptLoader::LoadActor(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { if (!EnsurePropertyCount(propCount, 24, "Actor")) return nullptr; + SScaledActorHead head = LoadScaledActorHead(in, mgr); + zeus::CVector3f collisionExtent; + collisionExtent.readBig(in); + + zeus::CVector3f centroid; + centroid.readBig(in); + + float f1 = in.readFloatBig(); + float f2 = in.readFloatBig(); + + CHealthInfo hInfo(in); + + CDamageVulnerability dInfo(in); + + // TODO: Finish } CEntity* ScriptLoader::LoadWaypoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) @@ -280,7 +521,7 @@ CEntity* ScriptLoader::LoadTargetingPoint(CStateManager& mgr, CInputStream& in, { } -CEntity* ScriptLoader::LoadElectroMagneticPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) +CEntity* ScriptLoader::LoadEMPulse(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { } @@ -528,14 +769,4 @@ CEntity* ScriptLoader::LoadEnergyBall(CStateManager& mgr, CInputStream& in, int { } -u32 ScriptLoader::LoadParameterFlags(CInputStream& in) -{ - u32 count = in.readUint32Big(); - u32 ret = 0; - for (u32 i=0 ; i; @@ -16,6 +22,16 @@ using FScriptLoader = std::function