Skip to content

Commit

Permalink
Fix various Oblivion 20.0.0.5 and 10.1.0.1xx issues
Browse files Browse the repository at this point in the history
Add more fields and version checks. Fix NiDynamicEffect condition.
  • Loading branch information
ousnius committed Sep 16, 2024
1 parent 862e6ae commit 5b202d9
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 95 deletions.
87 changes: 54 additions & 33 deletions include/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ See the included GPLv3 LICENSE file
#include "Keys.hpp"

namespace nifly {
struct QuatTransform {
Vector3 translation;
Quaternion rotation;
float scale = 1.0f;
bool trsValid[3]{};

void Sync(NiStreamReversible& stream) {
stream.Sync(translation);
stream.Sync(rotation);
stream.Sync(scale);

if (stream.GetVersion().File() < V10_1_0_110)
stream.Sync(trsValid);
}
};

class NiKeyframeData : public NiCloneableStreamable<NiKeyframeData, NiObject> {
public:
NiKeyType rotationType = NO_INTERP;
Expand Down Expand Up @@ -176,6 +192,7 @@ class InterpBlendItem {
NiBlockRef<NiInterpolator> interpolatorRef;
float weight = 0.0f;
float normalizedWeight = 0.0f;
uint32_t priorityInt = 0;
uint8_t priority = 0;
float easeSpinner = 0.0f;

Expand All @@ -185,20 +202,30 @@ class InterpBlendItem {
class NiBlendInterpolator : public NiCloneableStreamable<NiBlendInterpolator, NiInterpolator> {
public:
InterpBlendFlags flags = INTERP_BLEND_MANAGER_CONTROLLED;
uint8_t arraySize = 0;
uint16_t arraySize = 0;
uint16_t arrayGrowBy = 0;
float weightThreshold = 0.0f;

uint8_t interpCount = 0;
uint16_t interpCount = 0;
uint8_t singleIndex = NiByteMax;
uint16_t singleIndexShort = NiUShortMax;
char highPriority = NiCharMin;
int highPriorityInt = NiIntMin;
char nextHighPriority = NiCharMin;
int nextHighPriorityInt = NiIntMin;
float singleTime = NiFloatMin;
float highWeightsSum = NiFloatMin;
float nextHighWeightsSum = NiFloatMin;
float highEaseSpinner = NiFloatMin;
std::vector<InterpBlendItem> interpItems;

bool managerControlled = false;
bool onlyUseHighestWeight = false;
NiBlockRef<NiInterpolator> singleInterpolatorRef;

void Sync(NiStreamReversible& stream);
void GetChildRefs(std::set<NiRef*>& refs) override;
void GetChildIndices(std::vector<uint32_t>& indices) override;
};

class NiBlendBoolInterpolator : public NiCloneableStreamable<NiBlendBoolInterpolator, NiBlendInterpolator> {
Expand Down Expand Up @@ -235,10 +262,12 @@ class NiBlendPoint3Interpolator
class NiBlendTransformInterpolator
: public NiCloneableStreamable<NiBlendTransformInterpolator, NiBlendInterpolator> {
public:
QuatTransform value;

static constexpr const char* BlockName = "NiBlendTransformInterpolator";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible&) {}
void Sync(NiStreamReversible& stream);
};

class NiKeyBasedInterpolator : public NiInterpolator {};
Expand Down Expand Up @@ -570,10 +599,16 @@ class NiBSBoneLODController : public NiCloneable<NiBSBoneLODController, NiBoneLO

struct Morph {
NiStringRef frameName;
float legacyWeight = 0.0f;
std::vector<Vector3> vectors;

void Sync(NiStreamReversible& stream, uint32_t numVerts) {
frameName.Sync(stream);
if (stream.GetVersion().File() >= V10_1_0_106)
frameName.Sync(stream);

if (stream.GetVersion().File() >= V10_1_0_104 && stream.GetVersion().File() < V20_1_0_3 && stream.GetVersion().Stream() < 10)
stream.Sync(legacyWeight);

vectors.resize(numVerts);
for (uint32_t i = 0; i < numVerts; i++)
stream.Sync(vectors[i]);
Expand Down Expand Up @@ -601,7 +636,12 @@ class NiMorphData : public NiCloneableStreamable<NiMorphData, NiObject> {
void SetMorphs(const uint32_t numVerts, const std::vector<Morph>& m);
};

class NiInterpController : public NiCloneable<NiInterpController, NiTimeController> {};
class NiInterpController : public NiCloneableStreamable<NiInterpController, NiTimeController> {
public:
bool managerControlled = false;

void Sync(NiStreamReversible& stream);
};

class MorphWeight {
public:
Expand Down Expand Up @@ -797,10 +837,16 @@ class BSNiAlphaPropertyTestRefController
const char* GetBlockName() override { return BlockName; }
};

class NiKeyframeController : public NiCloneable<NiKeyframeController, NiSingleInterpController> {
class NiKeyframeController : public NiCloneableStreamable<NiKeyframeController, NiSingleInterpController> {
public:
NiBlockRef<NiKeyframeData> dataRef;

static constexpr const char* BlockName = "NiKeyframeController";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible& stream);
void GetChildRefs(std::set<NiRef*>& refs) override;
void GetChildIndices(std::vector<uint32_t>& indices) override;
};

class NiTransformController : public NiCloneable<NiTransformController, NiKeyframeController> {
Expand Down Expand Up @@ -1027,33 +1073,6 @@ class NiPSysEmitterPlanarAngleVarCtlr
const char* GetBlockName() override { return BlockName; }
};

class NiPSysEmitterCtlr : public NiCloneableStreamable<NiPSysEmitterCtlr, NiPSysModifierCtlr> {
public:
NiBlockRef<NiInterpolator> visInterpolatorRef;

static constexpr const char* BlockName = "NiPSysEmitterCtlr";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible& stream);
void GetChildRefs(std::set<NiRef*>& refs) override;
void GetChildIndices(std::vector<uint32_t>& indices) override;
};

class BSMasterParticleSystem;

class BSPSysMultiTargetEmitterCtlr
: public NiCloneableStreamable<BSPSysMultiTargetEmitterCtlr, NiPSysEmitterCtlr> {
public:
uint16_t maxEmitters = 0;
NiBlockPtr<BSMasterParticleSystem> masterParticleSystemRef;

static constexpr const char* BlockName = "BSPSysMultiTargetEmitterCtlr";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible& stream);
void GetPtrs(std::set<NiPtr*>& ptrs) override;
};

class NiStringPalette : public NiCloneableStreamable<NiStringPalette, NiObject> {
public:
NiString palette;
Expand Down Expand Up @@ -1203,8 +1222,10 @@ class NiControllerSequence : public NiCloneableStreamable<NiControllerSequence,
NiBlockRef<NiTextKeyExtraData> textKeyRef;
CycleType cycleType = CYCLE_LOOP;
float frequency = 0.0f;
float phase = 0.0f;
float startTime = 0.0f;
float stopTime = 0.0f;
bool playBackwards = false;
NiBlockPtr<NiControllerManager> managerRef;
NiStringRef accumRootName;

Expand Down
6 changes: 5 additions & 1 deletion include/BasicTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ constexpr auto NiByteMin = std::numeric_limits<uint8_t>::min();
constexpr auto NiByteMax = std::numeric_limits<uint8_t>::max();
constexpr auto NiUShortMin = std::numeric_limits<uint16_t>::min();
constexpr auto NiUShortMax = std::numeric_limits<uint16_t>::max();
constexpr auto NiIntMin = std::numeric_limits<int32_t>::min();
constexpr auto NiIntMax = std::numeric_limits<int32_t>::max();
constexpr auto NiUIntMin = std::numeric_limits<uint32_t>::min();
constexpr auto NiUIntMax = std::numeric_limits<uint32_t>::max();
constexpr auto NiFloatMin = std::numeric_limits<float>::lowest();
Expand Down Expand Up @@ -57,8 +59,10 @@ enum NiFileVersion : uint32_t {
V10_1_0_0 = 0x0A010000,
V10_1_0_101 = 0x0A010065,
V10_1_0_104 = 0x0A010068,
V10_1_0_110 = 0x0A01006E,
V10_1_0_106 = 0x0A01006A,
V10_1_0_108 = 0x0A01006C,
V10_1_0_110 = 0x0A01006E,
V10_1_0_112 = 0x0A010070,
V10_1_0_113 = 0x0A010071,
V10_1_0_114 = 0x0A010072,
V10_2_0_0 = 0x0A020000,
Expand Down
6 changes: 0 additions & 6 deletions include/Object3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,12 +1009,6 @@ struct QuaternionXYZW {
};


struct QuatTransform {
Vector3 translation;
Quaternion rotation;
float scale = 1.0f;
};

struct MatTransform {
/* On MatTransform and coordinate-system (CS) transformations:
Expand Down
2 changes: 1 addition & 1 deletion include/Objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ enum CoordGenType : uint32_t {

class NiDynamicEffect : public NiCloneableStreamable<NiDynamicEffect, NiAVObject> {
public:
bool switchState = false;
bool switchState = true;
NiBlockPtrArray<NiNode> affectedNodes;

void Sync(NiStreamReversible& stream);
Expand Down
28 changes: 28 additions & 0 deletions include/Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,34 @@ class NiPSysEmitterCtlrData : public NiCloneableStreamable<NiPSysEmitterCtlrData
void Sync(NiStreamReversible& stream);
};

class NiPSysEmitterCtlr : public NiCloneableStreamable<NiPSysEmitterCtlr, NiPSysModifierCtlr> {
public:
NiBlockRef<NiPSysEmitterCtlrData> dataRef;
NiBlockRef<NiInterpolator> visInterpolatorRef;

static constexpr const char* BlockName = "NiPSysEmitterCtlr";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible& stream);
void GetChildRefs(std::set<NiRef*>& refs) override;
void GetChildIndices(std::vector<uint32_t>& indices) override;
};

class BSMasterParticleSystem;

class BSPSysMultiTargetEmitterCtlr
: public NiCloneableStreamable<BSPSysMultiTargetEmitterCtlr, NiPSysEmitterCtlr> {
public:
uint16_t maxEmitters = 0;
NiBlockPtr<BSMasterParticleSystem> masterParticleSystemRef;

static constexpr const char* BlockName = "BSPSysMultiTargetEmitterCtlr";
const char* GetBlockName() override { return BlockName; }

void Sync(NiStreamReversible& stream);
void GetPtrs(std::set<NiPtr*>& ptrs) override;
};

class NiParticleSystem;

class NiPSysModifier : public NiCloneableStreamable<NiPSysModifier, NiObject> {
Expand Down
Loading

0 comments on commit 5b202d9

Please sign in to comment.