Skip to content
This repository was archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
[MinecraftHeader] Fix crash in leveldata
Browse files Browse the repository at this point in the history
  • Loading branch information
codehz committed Jun 25, 2020
1 parent 39cb419 commit 0c44115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Base/compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ActorUniqueID Level::getNewUniqueID() const {
// RaidBossComponent::_sendBossEvent
PacketSender &Level::getPacketSender() const { return *direct_access<PacketSender *>(this, 2096); }

LevelDataWrapper &Level::GetLevelDataWrapper() { return direct_access<LevelDataWrapper>(this, 536); }
LevelDataWrapper &Level::GetLevelDataWrapper() { return direct_access<LevelDataWrapper>(this, 544); }

template <> Minecraft *LocateService<Minecraft>() {
return *GetServerSymbol<Minecraft *>("?mGame@ServerCommand@@1PEAVMinecraft@@EA");
Expand Down
17 changes: 12 additions & 5 deletions MinecraftHeaders/Level/LevelData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@

#include "../dll.h"

class LevelDataValue : public std::variant<
int, bool, float, std::string, GeneratorType, GameType, BlockPos, unsigned int,
std::unique_ptr<CompoundTag>> {
public:
struct LevelDataValue : public std::variant<
int, bool, float, std::string, GeneratorType, GameType, BlockPos, unsigned int,
std::unique_ptr<CompoundTag>> {
using variant::variant;
};

Expand Down Expand Up @@ -106,7 +105,15 @@ class LevelData {
template <typename T> T const *_extractValue(StringKey const &) const;

public:
template <typename T> inline T const *extractValue(StringKey const &key) const { return _extractValue<T>(key); }
inline LevelDataValue const *getValue(StringKey const &key) const {
if (auto kv = mKV.find(key); kv != mKV.end()) return &kv->second;
if (auto kv = mAltKV.find(key); kv != mAltKV.end()) return &kv->second;
return nullptr;
}
template <typename T> inline T const *extractValue(StringKey const &key) const {
auto val = getValue(key);
return std::get_if<T>(val);
}
template <typename T> inline void setValue(StringKey const &key, T value) { mKV[key] = LevelDataValue(value); }

inline BlockPos getSpawnPos() const {
Expand Down

0 comments on commit 0c44115

Please sign in to comment.