Skip to content

Commit

Permalink
implement #2109;
Browse files Browse the repository at this point in the history
  • Loading branch information
ellipsis-dev[bot] authored Aug 11, 2024
1 parent 5815d9d commit e15fb20
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libespm/include/libespm/Records.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once
#include "ACHR.h"
#include "ACTI.h"
#include "SHOU.h"
#include "SLGM.h"
#include "WOOP.h"
#include "WTHR.h"
#include "ALCH.h"
#include "AMMO.h"
#include "ARMO.h"
Expand Down Expand Up @@ -32,4 +36,4 @@
#include "TES4.h"
#include "TREE.h"
#include "WEAP.h"
#include "WRLD.h"
#include "WRLD.h"
26 changes: 26 additions & 0 deletions libespm/include/libespm/SHOU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "RecordHeader.h"

#pragma pack(push, 1)

namespace espm {

class SHOU final : public RecordHeader
{
public:
static constexpr auto kType = "SHOU";

struct Data
{
// Assuming similar structure to SLGM for now
float weight;
};

Data GetData(CompressedFieldsCache& compressedFieldsCache) const;
};

static_assert(sizeof(SHOU) == sizeof(RecordHeader));

}

#pragma pack(pop)
26 changes: 26 additions & 0 deletions libespm/include/libespm/WOOP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "RecordHeader.h"

#pragma pack(push, 1)

namespace espm {

class WOOP final : public RecordHeader
{
public:
static constexpr auto kType = "WOOP";

struct Data
{
// Assuming similar structure to SLGM for now
float weight;
};

Data GetData(CompressedFieldsCache& compressedFieldsCache) const;
};

static_assert(sizeof(WOOP) == sizeof(RecordHeader));

}

#pragma pack(pop)
26 changes: 26 additions & 0 deletions libespm/include/libespm/WTHR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "RecordHeader.h"

#pragma pack(push, 1)

namespace espm {

class WTHR final : public RecordHeader
{
public:
static constexpr auto kType = "WTHR";

struct Data
{
// Assuming similar structure to SLGM for now
float weight;
};

Data GetData(CompressedFieldsCache& compressedFieldsCache) const;
};

static_assert(sizeof(WTHR) == sizeof(RecordHeader));

}

#pragma pack(pop)
21 changes: 21 additions & 0 deletions libespm/src/SHOU.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "libespm/SHOU.h"
#include "libespm/CompressedFieldsCache.h"
#include "libespm/RecordHeaderAccess.h"

namespace espm {

SHOU::Data SHOU::GetData(CompressedFieldsCache& cache) const
{
Data res;
RecordHeaderAccess::IterateFields(
this,
[&](const char* type, uint32_t size, const char* data) {
if (!std::memcmp(type, "DATA", 4)) {
res.weight = *reinterpret_cast<const float*>(data + 0x4);
}
},
cache);
return res;
}

}
5 changes: 3 additions & 2 deletions libespm/src/SLGM.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "libespm/SHOU.h"
#include "libespm/SLGM.h"
#include "libespm/CompressedFieldsCache.h"
#include "libespm/RecordHeaderAccess.h"

namespace espm {

SLGM::Data SLGM::GetData(CompressedFieldsCache& cache) const
{
Data res;
Expand All @@ -17,5 +17,6 @@ SLGM::Data SLGM::GetData(CompressedFieldsCache& cache) const
cache);
return res;
}

}

}
21 changes: 21 additions & 0 deletions libespm/src/WOOP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "libespm/WOOP.h"
#include "libespm/CompressedFieldsCache.h"
#include "libespm/RecordHeaderAccess.h"

namespace espm {

WOOP::Data WOOP::GetData(CompressedFieldsCache& cache) const
{
Data res;
RecordHeaderAccess::IterateFields(
this,
[&](const char* type, uint32_t size, const char* data) {
if (!std::memcmp(type, "DATA", 4)) {
res.weight = *reinterpret_cast<const float*>(data + 0x4);
}
},
cache);
return res;
}

}
21 changes: 21 additions & 0 deletions libespm/src/WTHR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "libespm/WTHR.h"
#include "libespm/CompressedFieldsCache.h"
#include "libespm/RecordHeaderAccess.h"

namespace espm {

WTHR::Data WTHR::GetData(CompressedFieldsCache& cache) const
{
Data res;
RecordHeaderAccess::IterateFields(
this,
[&](const char* type, uint32_t size, const char* data) {
if (!std::memcmp(type, "DATA", 4)) {
res.weight = *reinterpret_cast<const float*>(data + 0x4);
}
},
cache);
return res;
}

}
48 changes: 48 additions & 0 deletions unit/EspmTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,51 @@ TEST_CASE("isFood flag is set for sweet roll", "[espm]")
REQUIRE(data.isFood == true);
REQUIRE(data.isPoison == false);
}

TEST_CASE("Loads SHOU", "[espm]")
{
auto& br = l.GetBrowser();
espm::CompressedFieldsCache cache;

auto form = br.LookupById(0xPLACEHOLDER_SHOU_ID);
REQUIRE(form.rec->GetType() == "SHOU");

auto data = reinterpret_cast<const espm::SHOU*>(form.rec)->GetData(cache);
REQUIRE(data.weight == 0.0f); // Adjust expected value as needed
}

TEST_CASE("Loads SLGM", "[espm]")
{
auto& br = l.GetBrowser();
espm::CompressedFieldsCache cache;

auto form = br.LookupById(0xPLACEHOLDER_SLGM_ID);
REQUIRE(form.rec->GetType() == "SLGM");

auto data = reinterpret_cast<const espm::SLGM*>(form.rec)->GetData(cache);
REQUIRE(data.weight == 0.0f); // Adjust expected value as needed
}

TEST_CASE("Loads WOOP", "[espm]")
{
auto& br = l.GetBrowser();
espm::CompressedFieldsCache cache;

auto form = br.LookupById(0xPLACEHOLDER_WOOP_ID);
REQUIRE(form.rec->GetType() == "WOOP");

auto data = reinterpret_cast<const espm::WOOP*>(form.rec)->GetData(cache);
REQUIRE(data.weight == 0.0f); // Adjust expected value as needed
}

TEST_CASE("Loads WTHR", "[espm]")
{
auto& br = l.GetBrowser();
espm::CompressedFieldsCache cache;

auto form = br.LookupById(0xPLACEHOLDER_WTHR_ID);
REQUIRE(form.rec->GetType() == "WTHR");

auto data = reinterpret_cast<const espm::WTHR*>(form.rec)->GetData(cache);
REQUIRE(data.weight == 0.0f); // Adjust expected value as needed
}

0 comments on commit e15fb20

Please sign in to comment.