Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Release 2.12.1 (LiteLDev#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox authored Mar 26, 2023
2 parents 4c43e26 + df95767 commit 10263f6
Show file tree
Hide file tree
Showing 29 changed files with 291 additions and 145 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ jobs:
move bedrock_server_var.lib ..\LiteLoader\lib
shell: cmd

- name: Get short SHA
id: sha_short
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set LITELOADER_VERSION_COMMIT_SHA
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: |
sed -r -i 's/#define\s+LITELOADER_VERSION_COMMIT_SHA\s+.*/#define LITELOADER_VERSION_COMMIT_SHA ${{ steps.sha_short.outputs.sha_short }}\r/' LiteLoader/include/liteloader/Version.h
export sha_short=$(git rev-parse --short HEAD)
sed -r -i "s/#define\s+LITELOADER_VERSION_COMMIT_SHA\s+.*/#define LITELOADER_VERSION_COMMIT_SHA $sha_short\r/" LiteLoader/include/liteloader/Version.h
shell: bash

- name: Set LITELOADER_VERSION_STATUS_BETA
Expand Down
4 changes: 2 additions & 2 deletions LLPreLoader/src/PreLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool loadLib(const string& libName, bool showFailInfo = true) {
Error("Error code: {} !", error_message_id);
LPWSTR message_buffer = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, error_message_id, MAKELANGID(0x09, SUBLANG_DEFAULT), (LPWSTR)&message_buffer, 0,
nullptr, error_message_id, NULL, (LPWSTR)&message_buffer, NULL,
nullptr);
Error("{}", wstr2str(message_buffer));
LocalFree(message_buffer);
Expand Down Expand Up @@ -137,4 +137,4 @@ void loadDlls() {
Info("PreLoader is running as DLL Loader...");
loadPlugins();
}
}
}
1 change: 1 addition & 0 deletions LLPreLoader/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv

loadConfig();
fixUpLibDir();
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOOPENFILEERRORBOX);
loadDlls();
}
if (ul_reason_for_call == DLL_PROCESS_DETACH) {}
Expand Down
2 changes: 0 additions & 2 deletions LiteLoader/include/liteloader/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ struct LLConfig {

bool enableCrashLogger = true;
std::string crashLoggerPath = ".\\plugins\\LiteLoader\\CrashLogger_Daemon.exe";
std::string antiGiveCommand = "kick {player}";
bool enableSimpleServerLogger = true;
bool enableFixListenPort = false;
bool enableAntiGive = true;
bool enableUnlockCmd = true;
bool enableErrorStackTraceback = true;
bool cacheErrorStackTracebackSymbol = false;
Expand Down
5 changes: 2 additions & 3 deletions LiteLoader/include/llapi/mc/Actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Actor {
LIAPI float quickEvalMolangScript(const string& expression);
LIAPI Biome* getBiome();
LIAPI float getRealSpeed() const;
LIAPI class EntityContext* getEntityContext() const;
LIAPI class EntityContext& getEntityContext() const;
//LIAPI Json::Value quickEvalMolangScriptAsJson(const string& expression);

inline Vec3 getPos()
Expand All @@ -98,8 +98,7 @@ class Actor {

// template<class T>
// inline T* tryGetComponent() const {
// auto* entityContext = getEntityContext();
// return entityContext->_enttRegistry().try_get<T>(entityContext->_getEntityId());
// return getEntityContext().tryGetComponent<T>();
// }

#undef AFTER_EXTRA
Expand Down
2 changes: 2 additions & 0 deletions LiteLoader/include/llapi/mc/CompoundTag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class CompoundTag : public Tag {
LIAPI std::string toBinaryNBT(bool isLittleEndian = true);
LIAPI static std::string nbtListToBinary(std::vector<std::unique_ptr<CompoundTag>> tags, bool isLittleEndian = true);
LIAPI static std::unique_ptr<CompoundTag> fromSNBT(const std::string& snbt);

LIAPI static std::unique_ptr<CompoundTag> fromBinaryNBT(std::string_view dataView, size_t& offset, bool isLittleEndian = true);
LIAPI static std::unique_ptr<CompoundTag> fromBinaryNBT(void* data, size_t len, bool isLittleEndian = true);
LIAPI static std::unique_ptr<CompoundTag> fromBinaryNBT(void* data, size_t len, size_t& offset, bool isLittleEndian = true);
LIAPI static std::unique_ptr<CompoundTag> fromBinaryNBT(std::string const& data, size_t& offset, bool isLittleEndian = true);
Expand Down
6 changes: 6 additions & 0 deletions LiteLoader/include/llapi/mc/EntityContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class EntityContext : public EntityContextBase {

#define AFTER_EXTRA
// Add Member There
public:
template <class T>
inline T* tryGetComponent() const {
return const_cast<T*>(_enttRegistry().try_get<T>(_getEntityId()));
}

#define DISABLE_CONSTRUCTOR_PREVENTION_ENTITYCONTEXT
#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ENTITYCONTEXT
Expand Down
35 changes: 24 additions & 11 deletions LiteLoader/src/liteloader/BuiltinBugFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "liteloader/LiteLoader.h"
#include "llapi/HookAPI.h"
#include "llapi/LoggerAPI.h"

#include "llapi/mc/InventoryTransactionPacket.hpp"
#include "llapi/mc/NetworkIdentifier.hpp"
#include "llapi/mc/Player.hpp"
Expand All @@ -14,21 +13,13 @@
#include "llapi/mc/BinaryStream.hpp"
#include "llapi/mc/LevelData.hpp"
#include "llapi/EventAPI.h"
#include "llapi/mc/NetworkConnection.hpp"
#include "llapi/mc/SimulatedPlayer.hpp"
#include "llapi/mc/MinecraftPackets.hpp"
#include "llapi/mc/MobEquipmentPacket.hpp"

#include "llapi/mc/LevelChunk.hpp"
#include "llapi/mc/ChunkSource.hpp"

#include "llapi/mc/NetworkPeer.hpp"
#include "llapi/mc/ReadOnlyBinaryStream.hpp"

#include "llapi/mc/SharedConstants.hpp"
#include "llapi/mc/PropertiesSettings.hpp"
#include "llapi/ScheduleAPI.h"

#include "llapi/mc/UpdateAdventureSettingsPacket.hpp"
#include "llapi/mc/UpdateAbilitiesPacket.hpp"
#include "llapi/mc/LayeredAbilities.hpp"
Expand Down Expand Up @@ -64,9 +55,8 @@ TClasslessInstanceHook(__int64, "?LogIPSupport@RakPeerHelper@@AEAAXW4PeerPurpose
}

// Fix abnormal items
#include "llapi/mc/InventoryTransaction.hpp"
/*
#include "llapi/mc/InventoryAction.hpp"
#include "llapi/mc/Level.hpp"
#include "llapi/mc/ElementBlock.hpp"
#include "llapi/mc/IContainerManager.hpp"
Expand Down Expand Up @@ -118,6 +108,7 @@ TInstanceHook(void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@A
}
return original(this, netid, pk);
}
*/

TInstanceHook(size_t, "??0PropertiesSettings@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z",
PropertiesSettings, const std::string& file) {
Expand Down Expand Up @@ -148,6 +139,7 @@ TInstanceHook(void, "?moveView@Player@@UEAAXXZ", Player) {
}

#include "llapi/mc/ChunkViewSource.hpp"
#include "llapi/mc/Level.hpp"

inline bool Interval(int a1) {
if (a1 < 0x5ffffff && a1 > -0x5ffffff)
Expand Down Expand Up @@ -473,4 +465,25 @@ TClasslessInstanceHook(void, "?sendEvent@ActorEventCoordinator@@QEAAXAEBV?$Event
}
}
}
}

// Fix LevelChunkPacket crash
#include "llapi/mc/LevelChunkPacket.hpp"
TInstanceHook(StreamReadResult, "?_read@LevelChunkPacket@@EEAA?AW4StreamReadResult@@AEAVReadOnlyBinaryStream@@@Z", LevelChunkPacket, ReadOnlyBinaryStream* bs) {
size_t readPointer = bs->getReadPointer();
bs->getVarInt();
bs->getVarInt();
unsigned int varInt = bs->getUnsignedVarInt();
if (varInt != -2) {
bs->getUnsignedVarInt();
}
bool boolean = bs->getBool();
if (boolean) {
varInt = bs->getUnsignedVarInt();
if (varInt > 10000) {
return StreamReadResult::Valid;
}
}
bs->setReadPointer(readPointer);
return original(this, bs);
}
9 changes: 0 additions & 9 deletions LiteLoader/src/liteloader/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ void inline to_json(nlohmann::json& j, const LLConfig& conf) {
{"FixListenPort", {
{"enabled", conf.enableFixListenPort}
}},
{"AntiGive", {
{"enabled", conf.enableAntiGive},
{"command", conf.antiGiveCommand}
}},
{"ErrorStackTraceback", {
{"enabled", conf.enableErrorStackTraceback},
{"cacheSymbol", conf.cacheErrorStackTracebackSymbol}
Expand Down Expand Up @@ -158,11 +154,6 @@ void inline from_json(const nlohmann::json& j, LLConfig& conf) {
conf.enableAddonsHelper = setting.value("enabled", true);
conf.addonsInstallPath = setting.value("autoInstallPath", "plugins/AddonsHelper");
}
if (modules.find("AntiGive") != modules.end()) {
const nlohmann::json& setting = modules.at("AntiGive");
conf.enableAntiGive = setting.value("enabled", true);
conf.antiGiveCommand = setting.value("command", "kick {player}");
}
if (modules.find("UnoccupyPort19132") != modules.end()) {
const nlohmann::json& setting = modules.at("UnoccupyPort19132");
conf.enableUnoccupyPort19132 = setting.value("enabled", true);
Expand Down
8 changes: 4 additions & 4 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ TInstanceHook(void,
// IDA NpcComponent::executeCommandAction
// NpcSceneDialogueData data(*this, *ac, a5);

NpcSceneDialogueData data(WeakEntityRef(ac->getEntityContext()->getWeakRef()), a5);
NpcSceneDialogueData data(WeakEntityRef(ac->getEntityContext().getWeakRef()), a5);

auto container = data.getActionsContainer();
auto actionAt = container->getActionAt(a4);
Expand Down Expand Up @@ -1899,9 +1899,9 @@ TClasslessInstanceHook(void, "?onScoreChanged@ServerScoreboard@@UEAAXAEBUScorebo

Player* player = nullptr;
auto pls = Level::getAllPlayers();
for (auto& player : pls) {
if (Global<Scoreboard>->getScoreboardId(*player).id == id) {
player = player;
for (auto& iPlayer : pls) {
if (Global<Scoreboard>->getScoreboardId(*iPlayer).id == id) {
player = iPlayer;
break;
}
}
Expand Down
44 changes: 22 additions & 22 deletions LiteLoader/src/llapi/ScheduleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,10 @@ class ScheduleTaskQueueType
break;

// timeout
if (!t.task)
continue;
try {
if (!t.task)
continue;
t.task();

switch (t.type) {
case ScheduleTaskData::TaskType::InfiniteRepeat: {
ScheduleTaskData sche{std::move(t)};
sche.leftTime = sche.interval;
push(std::move(sche));
break;
}
case ScheduleTaskData::TaskType::Repeat: {
if (t.count > 0) {
ScheduleTaskData sche{std::move(t)};
sche.leftTime = sche.interval;
--sche.count;
push(std::move(sche));
}
break;
}
default:
break;
}
} catch (const seh_exception& e) {
ll::logger.error("SEH exception occurred in ScheduleTask!");
ll::logger.error("{}", TextEncoding::toUTF8(e.what()));
Expand All @@ -161,6 +141,26 @@ class ScheduleTaskQueueType
if (auto plugin = ll::getPlugin(t.handle))
ll::logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString());
}

switch (t.type) {
case ScheduleTaskData::TaskType::InfiniteRepeat: {
ScheduleTaskData sche{std::move(t)};
sche.leftTime = sche.interval;
push(std::move(sche));
break;
}
case ScheduleTaskData::TaskType::Repeat: {
if (t.count > 0) {
ScheduleTaskData sche{std::move(t)};
sche.leftTime = sche.interval;
--sche.count;
push(std::move(sche));
}
break;
}
default:
break;
}
pop();
}
} catch (...) {
Expand Down
6 changes: 3 additions & 3 deletions LiteLoader/src/llapi/mc/ActorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

class UserEntityIdentifierComponent;

EntityContext* Actor::getEntityContext() const {
return dAccess<EntityContext*, 8>((Actor*)this);
class EntityContext& Actor::getEntityContext() const {
return dAccess<EntityContext, 8>((Actor*)this);
}

class UserEntityIdentifierComponent;
Expand Down Expand Up @@ -82,7 +82,7 @@ bool Actor::isItemActor() const {
#include "llapi/mc/ActorCollision.hpp"

bool Actor::isOnGround() const {
return ActorCollision::isOnGround(*getEntityContext()); // IDA DirectActorProxyImpl<IMobMovementProxy>::isOnGround
return ActorCollision::isOnGround(getEntityContext()); // IDA DirectActorProxyImpl<IMobMovementProxy>::isOnGround
}

std::string Actor::getTypeName() const {
Expand Down
30 changes: 20 additions & 10 deletions LiteLoader/src/llapi/nbt/CompoundTagAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,30 @@ std::string CompoundTag::nbtListToBinary(std::vector<std::unique_ptr<CompoundTag

#pragma region From Binary
//////////////////// From Binary ////////////////////
std::unique_ptr<CompoundTag> CompoundTag::fromBinaryNBT(void* data, size_t len, size_t& offset, bool isLittleEndian) {
void* vtbl;
if (isLittleEndian)
vtbl = dlsym("??_7StringByteInput@@6B@");
else
vtbl = dlsym("??_7BigEndianStringByteInput@@6B@");

uintptr_t iDataInput[4] = {(uintptr_t)vtbl, offset, len, (uintptr_t)data};
auto rtn = NbtIo::read((IDataInput&)iDataInput);

offset = iDataInput[1];
std::unique_ptr<CompoundTag> CompoundTag::fromBinaryNBT(std::string_view dataView, size_t& offset, bool isLittleEndian) {
struct {
__int64* mVtbl;
size_t mOffset;
std::string_view mBuffer;
} tStringByteInput;

if (isLittleEndian) tStringByteInput.mVtbl = (__int64*)dlsym("??_7StringByteInput@@6B@");
else tStringByteInput.mVtbl = (__int64*)dlsym("??_7BigEndianStringByteInput@@6B@");

tStringByteInput.mOffset = offset;
tStringByteInput.mBuffer = dataView;
auto rtn = NbtIo::read(*reinterpret_cast<IDataInput*>(&tStringByteInput));

//update currentOffset
offset = tStringByteInput.mOffset;
return rtn;
}

std::unique_ptr<CompoundTag> CompoundTag::fromBinaryNBT(void* data, size_t len, size_t& offset, bool isLittleEndian) {
return fromBinaryNBT(std::string_view((char*)data, len), offset, isLittleEndian);
}

std::unique_ptr<CompoundTag> CompoundTag::fromBinaryNBT(void* data, size_t len, bool isLittleEndian) {
size_t endOffset = 0;
return fromBinaryNBT(data, len, endOffset, isLittleEndian);
Expand Down
19 changes: 6 additions & 13 deletions LiteLoader/src/llapi/utils/WinHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,15 @@ string GetLastErrorMessage(DWORD error_message_id) {

LPWSTR message_buffer = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, error_message_id, MAKELANGID(0x09, SUBLANG_DEFAULT), (LPWSTR)&message_buffer, 0, nullptr);
nullptr, error_message_id, NULL, (LPWSTR)&message_buffer, NULL, nullptr);
string res = wstr2str(wstring(message_buffer));
LocalFree(message_buffer);
return res;
}

string GetLastErrorMessage() {
DWORD error_message_id = ::GetLastError();
if (error_message_id == 0)
return "";

LPWSTR message_buffer = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, error_message_id, MAKELANGID(0x09, SUBLANG_DEFAULT), (LPWSTR)&message_buffer, 0, nullptr);
string res = wstr2str(wstring(message_buffer));
LocalFree(message_buffer);
return res;
return GetLastErrorMessage(error_message_id);
}

// Tool
Expand Down Expand Up @@ -208,6 +200,7 @@ bool IsWineEnvironment() {

void SetCurrentThreadDescription(PCWSTR desc)
{
if(ll::isDebugMode())
SetThreadDescription(GetCurrentThread(), desc);
}
#ifdef DEBUG
SetThreadDescription(GetCurrentThread(), desc);
#endif
}
Loading

0 comments on commit 10263f6

Please sign in to comment.