forked from skyrim-multiplayer/skymp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(skymp5-server): add OnPutItem/OnTakeItem support (skyrim-multipl…
- Loading branch information
1 parent
ce81275
commit f1d9f28
Showing
25 changed files
with
477 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "RecordHeader.h" | ||
|
||
#pragma pack(push, 1) | ||
|
||
namespace espm { | ||
|
||
class AMMO final : public RecordHeader | ||
{ | ||
public: | ||
static constexpr auto kType = "AMMO"; | ||
|
||
struct Data | ||
{ | ||
float weight; | ||
}; | ||
|
||
Data GetData(CompressedFieldsCache& compressedFieldsCache) const; | ||
}; | ||
|
||
static_assert(sizeof(AMMO) == sizeof(RecordHeader)); | ||
|
||
} | ||
|
||
#pragma pack(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "RecordHeader.h" | ||
|
||
#pragma pack(push, 1) | ||
|
||
namespace espm { | ||
|
||
class MISC final : public RecordHeader | ||
{ | ||
public: | ||
static constexpr auto kType = "MISC"; | ||
|
||
struct Data | ||
{ | ||
float weight; | ||
}; | ||
|
||
Data GetData(CompressedFieldsCache& compressedFieldsCache) const; | ||
}; | ||
|
||
static_assert(sizeof(MISC) == sizeof(RecordHeader)); | ||
|
||
} | ||
|
||
#pragma pack(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "RecordHeader.h" | ||
|
||
#pragma pack(push, 1) | ||
|
||
namespace espm { | ||
|
||
class SCRL final : public RecordHeader | ||
{ | ||
public: | ||
static constexpr auto kType = "SCRL"; | ||
|
||
private: | ||
struct DATA | ||
{ | ||
float weight; | ||
}; | ||
|
||
public: | ||
struct Data | ||
{ | ||
DATA data; | ||
}; | ||
|
||
Data GetData(CompressedFieldsCache& compressedFieldsCache) const; | ||
}; | ||
|
||
static_assert(sizeof(SCRL) == sizeof(RecordHeader)); | ||
|
||
} | ||
|
||
#pragma pack(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "RecordHeader.h" | ||
|
||
#pragma pack(push, 1) | ||
|
||
namespace espm { | ||
|
||
class SLGM final : public RecordHeader | ||
{ | ||
public: | ||
static constexpr auto kType = "SLGM"; | ||
|
||
struct Data | ||
{ | ||
float weight; | ||
}; | ||
|
||
Data GetData(CompressedFieldsCache& compressedFieldsCache) const; | ||
}; | ||
|
||
static_assert(sizeof(SLGM) == sizeof(RecordHeader)); | ||
|
||
} | ||
|
||
#pragma pack(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "libespm/AMMO.h" | ||
#include "libespm/RecordHeaderAccess.h" | ||
|
||
namespace espm { | ||
|
||
AMMO::Data AMMO::GetData(CompressedFieldsCache& cache) const | ||
{ | ||
Data res; | ||
RecordHeaderAccess::IterateFields( | ||
this, | ||
[&](const char* type, uint32_t size, const char* data) { | ||
if (!std::memcmp(type, "DATA", 4)) { | ||
// NOTE: 0x10 offset is for SSE version only | ||
res.weight = *reinterpret_cast<const float*>(data + 0x10); | ||
} | ||
}, | ||
cache); | ||
return res; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "libespm/MISC.h" | ||
#include "libespm/CompressedFieldsCache.h" | ||
#include "libespm/RecordHeaderAccess.h" | ||
|
||
namespace espm { | ||
|
||
MISC::Data MISC::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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "libespm/SCRL.h" | ||
#include "libespm/CompressedFieldsCache.h" | ||
#include "libespm/RecordHeaderAccess.h" | ||
|
||
namespace espm { | ||
|
||
SCRL::Data SCRL::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.data.weight = *reinterpret_cast<const float*>(data + 0x4); | ||
} | ||
}, | ||
cache); | ||
return res; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "libespm/SLGM.h" | ||
#include "libespm/CompressedFieldsCache.h" | ||
#include "libespm/RecordHeaderAccess.h" | ||
|
||
namespace espm { | ||
|
||
SLGM::Data SLGM::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; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
skymp5-server/cpp/server_guest_lib/GetWeightFromRecord.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "GetWeightFromRecord.h" | ||
|
||
#include "libespm/ALCH.h" | ||
#include "libespm/AMMO.h" | ||
#include "libespm/ARMO.h" | ||
#include "libespm/BOOK.h" | ||
#include "libespm/CompressedFieldsCache.h" | ||
#include "libespm/Convert.h" | ||
#include "libespm/INGR.h" | ||
#include "libespm/LIGH.h" | ||
#include "libespm/MISC.h" | ||
#include "libespm/RecordHeader.h" | ||
#include "libespm/SCRL.h" | ||
#include "libespm/SLGM.h" | ||
#include "libespm/WEAP.h" | ||
|
||
float GetWeightFromRecord(const espm::RecordHeader* record, | ||
espm::CompressedFieldsCache& cache) | ||
{ | ||
if (auto* weap = espm::Convert<espm::WEAP>(record)) { | ||
auto data = weap->GetData(cache); | ||
return data.weapData->weight; | ||
} | ||
|
||
if (auto* ligh = espm::Convert<espm::LIGH>(record)) { | ||
auto data = ligh->GetData(cache); | ||
return data.data.weight; | ||
} | ||
|
||
if (auto* armo = espm::Convert<espm::ARMO>(record)) { | ||
auto data = armo->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
if (auto* ingr = espm::Convert<espm::INGR>(record)) { | ||
auto data = ingr->GetData(cache); | ||
return data.itemData.weight; | ||
} | ||
|
||
if (auto* alch = espm::Convert<espm::ALCH>(record)) { | ||
auto data = alch->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
if (auto* book = espm::Convert<espm::BOOK>(record)) { | ||
auto data = book->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
// TODO: add unit test | ||
if (auto* ammo = espm::Convert<espm::AMMO>(record)) { | ||
auto data = ammo->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
// TODO: add unit test | ||
if (auto* scroll = espm::Convert<espm::SCRL>(record)) { | ||
auto data = scroll->GetData(cache); | ||
return data.data.weight; | ||
} | ||
|
||
// TODO: add unit test | ||
if (auto* slgm = espm::Convert<espm::SLGM>(record)) { | ||
auto data = slgm->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
// TODO: add unit test | ||
if (auto* misc = espm::Convert<espm::MISC>(record)) { | ||
auto data = misc->GetData(cache); | ||
return data.weight; | ||
} | ||
|
||
return 0.f; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace espm { | ||
|
||
class RecordHeader; | ||
class CompressedFieldsCache; | ||
|
||
} | ||
|
||
float GetWeightFromRecord(const espm::RecordHeader* record, | ||
espm::CompressedFieldsCache& cache); |
Oops, something went wrong.