Skip to content

Commit

Permalink
Fix Starfield BSWeakReference for stream version 173
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Sep 15, 2024
1 parent 6522e99 commit 97d8571
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
15 changes: 8 additions & 7 deletions include/Nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ struct BSResourceID {
};

struct UnkMaterialStruct {
uint32_t unkInt1 = 0;
uint32_t biomeFormID = 0;
uint32_t dirHash = 0;
uint32_t fileHash = 0;
std::string mat; // mat\0

void Sync(NiStreamReversible& stream);
};

struct UnkWeakRefStruct {
struct BSWaterReferenceStruct {
Matrix4 transform;
BSResourceID resourceID;
uint32_t unkInt1 = 0;
Expand All @@ -203,13 +203,14 @@ struct UnkWeakRefStruct {
void Sync(NiStreamReversible& stream);
};

struct WeakReference {
struct BSWeakReference {
uint32_t formID = 0;
BSResourceID resourceID;

uint32_t numTransforms = 0;
std::vector<Matrix4> transforms;

uint32_t numUnk1;
uint32_t numMaterials;
std::vector<UnkMaterialStruct> unkMaterials;

void Sync(NiStreamReversible& stream);
Expand All @@ -218,11 +219,11 @@ struct WeakReference {
class BSWeakReferenceNode : public NiCloneableStreamable<BSWeakReferenceNode, NiNode> {
public:
uint32_t numWeakRefs = 0;
std::vector<WeakReference> weakRefs;
std::vector<BSWeakReference> weakRefs;

uint32_t unkInt1 = 0;
uint32_t numUnk2 = 0;
std::vector<UnkWeakRefStruct> unkWeakRefStructs;
uint32_t numWaterRefs = 0;
std::vector<BSWaterReferenceStruct> waterRefs;

static constexpr const char* BlockName = "BSWeakReferenceNode";
const char* GetBlockName() override { return BlockName; }
Expand Down
23 changes: 13 additions & 10 deletions src/Nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,32 @@ void BSRangeNode::Sync(NiStreamReversible& stream) {


void UnkMaterialStruct::Sync(NiStreamReversible& stream) {
stream.Sync(unkInt1);
stream.Sync(biomeFormID);
stream.Sync(dirHash);
stream.Sync(fileHash);
stream.SyncString(mat);
}

void UnkWeakRefStruct::Sync(NiStreamReversible& stream) {
void BSWaterReferenceStruct::Sync(NiStreamReversible& stream) {
stream.Sync(transform);
stream.Sync(resourceID);
stream.Sync(unkInt1);
material.Sync(stream, 4);
}

void WeakReference::Sync(NiStreamReversible& stream) {
void BSWeakReference::Sync(NiStreamReversible& stream) {
if (stream.GetVersion().Stream() >= 173)
stream.Sync(formID);

stream.Sync(resourceID);
stream.Sync(numTransforms);
transforms.resize(numTransforms);
for (uint32_t i = 0; i < numTransforms; i++)
stream.Sync(transforms[i]);

stream.Sync(numUnk1);
unkMaterials.resize(numUnk1);
for (uint32_t i = 0; i < numUnk1; i++)
stream.Sync(numMaterials);
unkMaterials.resize(numMaterials);
for (uint32_t i = 0; i < numMaterials; i++)
unkMaterials[i].Sync(stream);
}

Expand All @@ -159,10 +162,10 @@ void BSWeakReferenceNode::Sync(NiStreamReversible& stream) {
weakRefs[i].Sync(stream);

stream.Sync(unkInt1);
stream.Sync(numUnk2);
unkWeakRefStructs.resize(numUnk2);
for (uint32_t i = 0; i < numUnk2; i++)
unkWeakRefStructs[i].Sync(stream);
stream.Sync(numWaterRefs);
waterRefs.resize(numWaterRefs);
for (uint32_t i = 0; i < numWaterRefs; i++)
waterRefs[i].Sync(stream);
}


Expand Down

0 comments on commit 97d8571

Please sign in to comment.