Skip to content

Commit 4d8c560

Browse files
committed
fix: fix setNbt bug
1 parent f62096f commit 4d8c560

File tree

13 files changed

+65
-52
lines changed

13 files changed

+65
-52
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.8] - 2024-08-04
9+
10+
### Fixed
11+
12+
- Fix setNbt bug
13+
814
## [0.8.7] - 2024-08-04
915

1016
### Changed
@@ -492,6 +498,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
492498
[#154]: https://github.com/LiteLDev/LegacyScriptEngine/issues/154
493499
[#157]: https://github.com/LiteLDev/LegacyScriptEngine/issues/157
494500

501+
[0.8.8]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.7...v0.8.8
495502
[0.8.7]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.6...v0.8.7
496503
[0.8.6]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.5...v0.8.6
497504
[0.8.5]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.8.4...v0.8.5

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.8.7",
7+
"version": "0.8.8",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

src/legacy/api/BlockEntityAPI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
#include "api/BlockAPI.h"
66
#include "api/NativeAPI.h"
77
#include "api/NbtAPI.h"
8-
#include "ll/api/memory/Memory.h"
8+
#include "legacy/api/MoreGlobal.h"
99
#include "ll/api/service/Bedrock.h"
1010
#include "main/Global.h"
11-
#include "mc/dataloadhelper/DataLoadHelper.h"
1211
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
1312
#include "mc/nbt/CompoundTag.h"
1413
#include "mc/world/level/BlockSource.h"
@@ -93,9 +92,10 @@ Local<Value> BlockEntityClass::setNbt(const Arguments& args) {
9392

9493
try {
9594
auto nbt = NbtCompoundClass::extract(args[0]);
96-
if (!nbt) return Local<Value>(); // Null
97-
DefaultDataLoadHelper helper;
98-
blockEntity->load(*ll::service::getLevel(), *nbt, helper);
95+
if (!nbt || !MoreGlobal::defaultDataLoadHelper) {
96+
return Local<Value>();
97+
}
98+
blockEntity->load(*ll::service::getLevel(), *nbt, *MoreGlobal::defaultDataLoadHelper);
9999
return Boolean::newBoolean(true);
100100
}
101101
CATCH("Fail in setNbt!")

src/legacy/api/EntityAPI.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#include "api/NativeAPI.h"
1010
#include "api/NbtAPI.h"
1111
#include "api/PlayerAPI.h"
12-
#include "ll/api/base/StdInt.h"
12+
#include "legacy/api/MoreGlobal.h"
1313
#include "ll/api/memory/Memory.h"
1414
#include "ll/api/service/Bedrock.h"
1515
#include "mc/common/HitDetection.h"
16-
#include "mc/dataloadhelper/DataLoadHelper.h"
16+
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
1717
#include "mc/deps/core/string/HashedString.h"
1818
#include "mc/entity/utilities/ActorDamageCause.h"
1919
#include "mc/entity/utilities/ActorType.h"
20-
#include "mc/enums/FacingID.h"
2120
#include "mc/world/SimpleContainer.h"
2221
#include "mc/world/actor/ActorDefinitionIdentifier.h"
2322
#include "mc/world/effect/MobEffectInstance.h"
@@ -1296,8 +1295,6 @@ Local<Value> EntityClass::getNbt(const Arguments& args) {
12961295
CATCH("Fail in getNbt!")
12971296
}
12981297

1299-
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
1300-
13011298
Local<Value> EntityClass::setNbt(const Arguments& args) {
13021299
CHECK_ARGS_COUNT(args, 1);
13031300

@@ -1306,10 +1303,11 @@ Local<Value> EntityClass::setNbt(const Arguments& args) {
13061303
if (!entity) return Local<Value>();
13071304

13081305
auto nbt = NbtCompoundClass::extract(args[0]);
1309-
if (!nbt) return Local<Value>(); // Null
1306+
if (!nbt || !MoreGlobal::defaultDataLoadHelper) {
1307+
return Local<Value>();
1308+
}
13101309

1311-
DefaultDataLoadHelper helper;
1312-
return Boolean::newBoolean(entity->load(*nbt, helper));
1310+
return Boolean::newBoolean(entity->load(*nbt, *MoreGlobal::defaultDataLoadHelper));
13131311
}
13141312
CATCH("Fail in setNbt!")
13151313
}

src/legacy/api/MoreGlobal.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "mc/world/level/storage/DBStorage.h"
55
#include "mc/world/level/storage/DBStorageConfig.h"
66

7-
DBStorage* MoreGlobal::db;
7+
DBStorage* MoreGlobal::dbStorage;
8+
DefaultDataLoadHelper* MoreGlobal::defaultDataLoadHelper;
89

910
LL_TYPE_INSTANCE_HOOK(
1011
DBStorageHook,
@@ -15,9 +16,18 @@ LL_TYPE_INSTANCE_HOOK(
1516
struct DBStorageConfig& cfg,
1617
Bedrock::NotNullNonOwnerPtr<class LevelDbEnv>& dbEnv
1718
) {
18-
DBStorage* ori = origin(cfg, dbEnv);
19-
MoreGlobal::db = ori;
19+
DBStorage* ori = origin(cfg, dbEnv);
20+
MoreGlobal::dbStorage = ori;
2021
return ori;
2122
};
2223

23-
void MoreGlobal::Init() { DBStorageHook::hook(); }
24+
void MoreGlobal::onLoad() { DBStorageHook::hook(); }
25+
26+
bool MoreGlobal::onEnable() {
27+
defaultDataLoadHelper =
28+
static_cast<DefaultDataLoadHelper*>(ll::memory::resolveSymbol("??_7DefaultDataLoadHelper@@6B@"));
29+
if (defaultDataLoadHelper && DBStorageHook::unhook()) {
30+
return true;
31+
}
32+
return false;
33+
}

src/legacy/api/MoreGlobal.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
12
class DBStorage;
23
namespace MoreGlobal {
3-
extern DBStorage* db;
4-
extern void Init();
4+
extern DBStorage* dbStorage;
5+
extern DefaultDataLoadHelper* defaultDataLoadHelper;
6+
extern void onLoad();
7+
extern bool onEnable();
58
}; // namespace MoreGlobal

src/legacy/api/PlayerAPI.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,21 @@
2121
#include "legacyapi/form/FormPacketHelper.h"
2222
#include "legacyapi/form/FormUI.h"
2323
#include "ll/api/form/CustomForm.h"
24+
#include "ll/api/memory/Memory.h"
2425
#include "ll/api/service/Bedrock.h"
2526
#include "ll/api/service/PlayerInfo.h"
2627
#include "ll/api/service/ServerInfo.h"
2728
#include "lse/api/NetworkPacket.h"
2829
#include "main/EconomicSystem.h"
2930
#include "main/SafeGuardRecord.h"
3031
#include "mc/certificates/WebToken.h"
31-
#include "mc/dataloadhelper/DataLoadHelper.h"
3232
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
33-
#include "mc/entity/EntityIdTraits.h"
34-
#include "mc/entity/gamerefs_entity/EntityRegistry.h"
35-
#include "mc/entity/utilities/ActorDataIDs.h"
3633
#include "mc/enums/BossBarColor.h"
3734
#include "mc/enums/MinecraftPacketIds.h"
38-
#include "mc/enums/ScorePacketType.h"
3935
#include "mc/enums/TextPacketType.h"
4036
#include "mc/enums/d_b_helpers/Category.h"
4137
#include "mc/nbt/ListTag.h"
4238
#include "mc/network/ConnectionRequest.h"
43-
#include "mc/network/MinecraftPackets.h"
4439
#include "mc/network/NetworkIdentifier.h"
4540
#include "mc/network/ServerNetworkHandler.h"
4641
#include "mc/network/packet/BossEventPacket.h"
@@ -343,7 +338,7 @@ Local<Value> McClass::getPlayerNbt(const Arguments& args) {
343338
return NbtCompoundClass::pack(std::move(tag));
344339
}
345340
} else {
346-
DBStorage* db = MoreGlobal::db;
341+
DBStorage* db = MoreGlobal::dbStorage;
347342
if (db) {
348343
if (db->hasKey("player_" + uuid.asString(), DBHelpers::Category::Player)) {
349344
std::unique_ptr<CompoundTag> playerTag =
@@ -373,12 +368,11 @@ Local<Value> McClass::setPlayerNbt(const Arguments& args) {
373368
auto uuid = mce::UUID::fromString(args[0].asString().toString());
374369
auto tag = NbtCompoundClass::extract(args[1]);
375370
Player* player = ll::service::getLevel()->getPlayer(uuid);
376-
if (player) {
377-
DefaultDataLoadHelper defaultDataLoadHelper;
378-
player->load(*tag, defaultDataLoadHelper);
371+
if (player && !MoreGlobal::defaultDataLoadHelper) {
372+
player->load(*tag, *MoreGlobal::defaultDataLoadHelper);
379373
return Boolean::newBoolean(true);
380374
} else {
381-
DBStorage* db = MoreGlobal::db;
375+
DBStorage* db = MoreGlobal::dbStorage;
382376
if (db) {
383377
if (db->hasKey("player_" + uuid.asString(), DBHelpers::Category::Player)) {
384378
std::unique_ptr<CompoundTag> playerTag =
@@ -409,7 +403,7 @@ Local<Value> McClass::setPlayerNbtTags(const Arguments& args) {
409403
Player* player = ll::service::getLevel()->getPlayer(uuid);
410404
CompoundTag playerNbt;
411405
player->save(playerNbt);
412-
if (player) {
406+
if (player && MoreGlobal::defaultDataLoadHelper) {
413407
for (int i = 0; i < arr.size(); ++i) {
414408
auto value = arr.get(i);
415409
if (value.getKind() == ValueKind::kString) {
@@ -419,8 +413,7 @@ Local<Value> McClass::setPlayerNbtTags(const Arguments& args) {
419413
}
420414
}
421415
}
422-
DefaultDataLoadHelper defaultDataLoadHelper;
423-
player->load(playerNbt, defaultDataLoadHelper);
416+
player->load(playerNbt, *MoreGlobal::defaultDataLoadHelper);
424417
player->refreshInventory();
425418
return Boolean::newBoolean(true);
426419
}
@@ -448,7 +441,7 @@ Local<Value> McClass::getPlayerScore(const Arguments& args) {
448441
auto obj = args[1].asString().toString();
449442
Scoreboard& scoreboard = ll::service::getLevel()->getScoreboard();
450443
Objective* objective = scoreboard.getObjective(obj);
451-
DBStorage* db = MoreGlobal::db;
444+
DBStorage* db = MoreGlobal::dbStorage;
452445
if (!objective) {
453446
return Number::newNumber(0);
454447
}
@@ -496,7 +489,7 @@ Local<Value> McClass::setPlayerScore(const Arguments& args) {
496489
if (!objective) {
497490
return Boolean::newBoolean(false);
498491
}
499-
DBStorage* db = MoreGlobal::db;
492+
DBStorage* db = MoreGlobal::dbStorage;
500493
if (!db) {
501494
return Boolean::newBoolean(false);
502495
}
@@ -544,7 +537,7 @@ Local<Value> McClass::addPlayerScore(const Arguments& args) {
544537
if (!objective) {
545538
return Boolean::newBoolean(false);
546539
}
547-
DBStorage* db = MoreGlobal::db;
540+
DBStorage* db = MoreGlobal::dbStorage;
548541
if (!db) {
549542
return Boolean::newBoolean(false);
550543
}
@@ -592,7 +585,7 @@ Local<Value> McClass::reducePlayerScore(const Arguments& args) {
592585
if (!objective) {
593586
return Boolean::newBoolean(false);
594587
}
595-
DBStorage* db = MoreGlobal::db;
588+
DBStorage* db = MoreGlobal::dbStorage;
596589
if (!db) {
597590
return Boolean::newBoolean(false);
598591
}
@@ -643,7 +636,7 @@ Local<Value> McClass::deletePlayerScore(const Arguments& args) {
643636
if (!objective) {
644637
return Boolean::newBoolean(false);
645638
}
646-
DBStorage* db = MoreGlobal::db;
639+
DBStorage* db = MoreGlobal::dbStorage;
647640
if (!db) {
648641
return Boolean::newBoolean(false);
649642
}
@@ -3022,10 +3015,10 @@ Local<Value> PlayerClass::setNbt(const Arguments& args) {
30223015
if (!player) return Local<Value>();
30233016

30243017
auto nbt = NbtCompoundClass::extract(args[0]);
3025-
if (!nbt) return Local<Value>(); // Null
3026-
3027-
DefaultDataLoadHelper helper = DefaultDataLoadHelper();
3028-
return Boolean::newBoolean(player->load(*nbt, helper));
3018+
if (!nbt || !MoreGlobal::defaultDataLoadHelper) {
3019+
return Local<Value>();
3020+
}
3021+
return Boolean::newBoolean(player->load(*nbt, *MoreGlobal::defaultDataLoadHelper));
30293022
}
30303023
CATCH("Fail in setNbt!")
30313024
}

src/lse/Entry.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ void registerPluginManager(const std::shared_ptr<PluginManager>& pluginManager);
7878

7979
auto enable(ll::mod::NativeMod& /*self*/) -> bool {
8080
auto& logger = getSelfPluginInstance().getLogger();
81-
81+
if (!MoreGlobal::onEnable()) {
82+
logger.error("Failed to enable MoreGlobal"_tr());
83+
}
8284
try {
8385
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
8486
RegisterDebugCommand();
@@ -103,7 +105,7 @@ void initializeLegacyStuff() {
103105

104106
InitBasicEventListeners();
105107
InitMessageSystem();
106-
MoreGlobal::Init();
108+
MoreGlobal::onLoad();
107109
}
108110

109111
auto load(ll::mod::NativeMod& self) -> bool {

tooth.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/LegacyScriptEngine",
4-
"version": "0.8.7",
4+
"version": "0.8.8",
55
"info": {
66
"name": "LegacyScriptEngine",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.7",
16-
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.7"
15+
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.8",
16+
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.8"
1717
}
1818
}

tooth.lua.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua",
4-
"version": "0.8.7",
4+
"version": "0.8.8",
55
"info": {
66
"name": "LegacyScriptEngine with Lua backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

0 commit comments

Comments
 (0)