Skip to content

Commit

Permalink
fix: now can build
Browse files Browse the repository at this point in the history
  • Loading branch information
futrime committed Jan 22, 2024
1 parent 4990146 commit edf3acc
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 356 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ PointerAlignment: Left
TabWidth: 4
UseTab: Never
SortIncludes: CaseSensitive

IncludeBlocks: Regroup
MaxEmptyLinesToKeep: 1
2 changes: 0 additions & 2 deletions src/api/APIHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
#include "api/NbtAPI.h"
#include "api/NetworkAPI.h"
#include "api/PlayerAPI.h"
#include "engine/EngineOwnData.h"
#include "main/Global.h"

#include <cmath>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

Expand Down
428 changes: 214 additions & 214 deletions src/api/APIHelp.h

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions src/api/LlAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include "api/LlAPI.h"

#include "api/APIHelp.h"
#include "engine/EngineOwnData.h"
#include "engine/GlobalShareData.h"
#include "ll/api/utils/WinUtils.h"
#include "utils/Utils.h"

#include <filesystem>
#include <map>
#include <string>

//////////////////// Classes ////////////////////
Expand Down Expand Up @@ -227,4 +223,19 @@ Local<Value> LlClass::getScriptEngineVersionFunction(const Arguments& args) {
return String::newString(EngineScope::currentEngine()->getEngineVersion());
}
CATCH("Fail in LLSEGetScriptEngineVerison")
}
}

Local<Value> LlClass::exportFunc(const Arguments& args) {
// TODO
return Local<Value>();
}

Local<Value> LlClass::importFunc(const Arguments& args) {
// TODO
return Local<Value>();
}

Local<Value> LlClass::hasFuncExported(const Arguments& args) {
// TODO
return Local<Value>();
}
58 changes: 30 additions & 28 deletions src/api/LlAPI.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
#pragma once

#include "api/APIHelp.h"

#include <ScriptX/ScriptX.h>

//////////////////// LLSE Static ////////////////////

class LlClass {
public:
static Local<Value> getLanguage();
static Local<Value> getMajorVersion();
static Local<Value> getMinorVersion();
static Local<Value> getRevisionVersion();
static Local<Value> getScriptEngineVersion();
static Local<Value> getVersionStatus();
static Local<Value> isRelease();
static Local<Value> isBeta();
static Local<Value> isDev();
static Local<Value> isWine();
static Local<Value> isDebugMode();
static Local<Value> getLanguage();
static Local<Value> getMajorVersion();
static Local<Value> getMinorVersion();
static Local<Value> getRevisionVersion();
static Local<Value> getScriptEngineVersion();
static Local<Value> getVersionStatus();
static Local<Value> isRelease();
static Local<Value> isBeta();
static Local<Value> isDev();
static Local<Value> isWine();
static Local<Value> isDebugMode();

static Local<Value> registerPlugin(const Arguments& args);
static Local<Value> versionString(const Arguments& args);
static Local<Value> requireVersion(const Arguments& args);
static Local<Value> getAllPluginInfo(const Arguments& args);
static Local<Value> listPlugins(const Arguments& args);
static Local<Value> exportFunc(const Arguments& args);
static Local<Value> importFunc(const Arguments& args);
static Local<Value> hasFuncExported(const Arguments& args);
static Local<Value> require(const Arguments& args);
static Local<Value> eval(const Arguments& args);
static Local<Value> getPluginInfo(const Arguments& args);
static Local<Value> registerPlugin(const Arguments &args);
static Local<Value> versionString(const Arguments &args);
static Local<Value> requireVersion(const Arguments &args);
static Local<Value> getAllPluginInfo(const Arguments &args);
static Local<Value> listPlugins(const Arguments &args);
static Local<Value> exportFunc(const Arguments &args);
static Local<Value> importFunc(const Arguments &args);
static Local<Value> hasFuncExported(const Arguments &args);
static Local<Value> require(const Arguments &args);
static Local<Value> eval(const Arguments &args);
static Local<Value> getPluginInfo(const Arguments &args);

// For Compatibility
static Local<Value> version(const Arguments& args);
static Local<Value> getVersionStatusFunction(const Arguments& args);
static Local<Value> isDebugModeFunction(const Arguments& args);
static Local<Value> getScriptEngineVersionFunction(const Arguments& args);
// For Compatibility
static Local<Value> version(const Arguments &args);
static Local<Value> getVersionStatusFunction(const Arguments &args);
static Local<Value> isDebugModeFunction(const Arguments &args);
static Local<Value> getScriptEngineVersionFunction(const Arguments &args);
};
extern ClassDefine<void> LlClassBuilder;
extern ClassDefine<void> VersionClassBuilder;
extern ClassDefine<void> VersionClassBuilder;
9 changes: 5 additions & 4 deletions src/api/MoreGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ LL_TYPE_INSTANCE_HOOK(
"??0DBStorage@@QEAA@UDBStorageConfig@@V?$not_null@V?$"
"NonOwnerPointer@VLevelDbEnv@@@Bedrock@@@gsl@@@Z",
DBStorage,
struct DBStorageConfig cfg,
Bedrock::NotNullNonOwnerPtr<class LevelDbEnv> dbEnv
struct DBStorageConfig& cfg,
Bedrock::NotNullNonOwnerPtr<class LevelDbEnv>& dbEnv
) {

DBStorage ori = origin(cfg, dbEnv);
MoreGlobal::setDBStorage(&ori);
return ori;
};

void MoreGlobal::Init() { DBStorageHook::hook(); }
void MoreGlobal::Init() { DBStorageHook::hook(); }

DBStorage* MoreGlobal::db = nullptr;
4 changes: 2 additions & 2 deletions src/api/NativeAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,5 @@ extern ClassDefine<void> NativeTypeEnumBuilder;
extern ClassDefine<ScriptNativeFunction> NativeCallBuilder;
extern ClassDefine<DynamicHookData> NativeHookBuilder;
extern ClassDefine<NativePointer> NativePointerBuilder;
extern ClassDefine<NativePatch> NativePatchBuilder;
extern ClassDefine<GlobalNativePointer> GlobalNativePointerBuilder;
// extern ClassDefine<NativePatch> NativePatchBuilder;
extern ClassDefine<GlobalNativePointer> GlobalNativePointerBuilder;
3 changes: 2 additions & 1 deletion src/api/PacketAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ Local<Value> BinaryStreamClass::writeVec3(const Arguments& args) {
return Local<Value>();
}
FloatPos* posObj = FloatPos::extractPos(args[0]);
pkt->writeType<Vec3>(posObj->getVec3());
// TODO
// pkt->writeType<Vec3>(posObj->getVec3());
return Boolean::newBoolean(true);
}
CATCH("Fail in BinaryStream writeVec3!");
Expand Down
35 changes: 18 additions & 17 deletions src/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,25 +2055,26 @@ Local<Value> PlayerClass::setSidebar(const Arguments& args) {
(ObjectiveSortOrder)sortOrder
);
player->sendNetworkPacket(disObjPkt);
std::vector<ScorePacketInfo> info;
static std::set<uint64_t> scoreIds; // Store scoreboard ids
uint64_t Id = 0;
// std::vector<ScorePacketInfo> info; // TODO
static std::set<uint64_t> scoreIds; // Store scoreboard ids
uint64_t Id = 0;
do {
Id = (uint64_t)((rand() << 16) + rand() + 1145140);
} while (scoreIds.find(Id) != scoreIds.end()); // Generate random id
const ScoreboardId& boardId = ScoreboardId(Id);
for (auto& i : data) {
ScorePacketInfo pktInfo = ScorePacketInfo();
pktInfo.mScoreboardId = boardId;
pktInfo.mObjectiveName = "FakeScoreObj";
pktInfo.mIdentityType = IdentityDefinition::Type::FakePlayer;
pktInfo.mScoreValue = i.second;
pktInfo.mFakePlayerName = i.first;
info.emplace_back(pktInfo);
}
SetScorePacket setPkt = SetScorePacket();
setPkt.mType = ScorePacketType::Change;
setPkt.mScoreInfo = info;
// TODO
// ScorePacketInfo pktInfo = ScorePacketInfo();
// pktInfo.mScoreboardId = boardId;
// pktInfo.mObjectiveName = "FakeScoreObj";
// pktInfo.mIdentityType = IdentityDefinition::Type::FakePlayer;
// pktInfo.mScoreValue = i.second;
// pktInfo.mFakePlayerName = i.first;
// info.emplace_back(pktInfo);
}
// SetScorePacket setPkt = SetScorePacket();
// setPkt.mType = ScorePacketType::Change;
// setPkt.mScoreInfo = info; // TODO

player->sendNetworkPacket(disObjPkt);
return Boolean::newBoolean(true);
Expand Down Expand Up @@ -2110,8 +2111,8 @@ Local<Value> PlayerClass::setBossBar(const Arguments& args) {
int percent = args[2].toInt();
if (percent < 0) percent = 0;
else if (percent > 100) percent = 100;
float value = (float)percent / 100;
AddEntityPacket entityPkt = AddEntityPacket();
float value = (float)percent / 100;
// AddEntityPacket entityPkt = AddEntityPacket(); // TODO
// Todo
// AddEntityPacket(uid, "player", Vec3(getPos().x, (float)-70,
// getPos().z),
Expand All @@ -2123,7 +2124,7 @@ Local<Value> PlayerClass::setBossBar(const Arguments& args) {
pkt.mName = args[1].asString().toString();
pkt.mHealthPercent = value;
pkt.mColor = color;
player->sendNetworkPacket(entityPkt);
// player->sendNetworkPacket(entityPkt);
player->sendNetworkPacket(pkt);
return Boolean::newBoolean(true);
}
Expand Down
141 changes: 73 additions & 68 deletions src/engine/EngineOwnData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ll/api/Logger.h"
#include "ll/api/i18n/I18nAPI.h"
#include "main/Configs.h"
#include "utils/UsingScriptX.inc"
#include "utils/UsingScriptX.h"

#include <fstream>
#include <map>
Expand All @@ -13,14 +13,14 @@
#include <unordered_map>

struct FormCallbackData {
script::ScriptEngine* engine;
script::Global<script::Function> func;
script::ScriptEngine *engine;
script::Global<script::Function> func;
};

struct RemoteCallData {
std::string nameSpace;
std::string funcName;
script::Global<Function> callback;
std::string nameSpace;
std::string funcName;
script::Global<Function> callback;
};

/*
Expand All @@ -35,68 +35,73 @@ struct SimpleCallbackData
class Player;

struct EngineOwnData {
// 基础信息
std::string pluginName = "";
std::string pluginFileOrDirPath = "";
std::string engineType = LLSE_BACKEND_TYPE;

// 表单回调
std::map<unsigned, FormCallbackData> formCallbacks;

// RemoteCall Exported Functions: unordered_map<nameSpace, funcName>
std::unordered_map<std::string, RemoteCallData> exportFuncs;

/*
uint64_t simpleCallbackIndex = 0;
std::unordered_map<uint64_t, SimpleCallbackData> simpleCallbacks;
inline uint64_t addSimpleCallback(script::Local<Function> func,
std::vector<script::Local<Value>> values)
{
auto index = ++simpleCallbackIndex;
std::vector<script::Global<Value>> globalValues;
for (auto& value : values)
globalValues.emplace_back(value);
SimpleCallbackData data{EngineScope::currentEngine(),
script::Global<Function>(func), std::move(globalValues)};
simpleCallbacks.emplace(index, std::move(data));
return index;
}
inline bool removeSimpleCallback(uint64_t index)
{
return simpleCallbacks.erase(index);
}
*/

// I18nAPI
ll::i18n::I18N* i18n = nullptr;

// LoggerAPI
ll::Logger logger = ll::Logger("");
int maxLogLevel = 4;

// 玩家绑定数据
std::unordered_map<std::string, script::Global<Value>> playerDataDB;

// Dynamic Call vm for NativeFFI
DCCallVM* dynamicCallVM;

// Unload Callbacks, use for close database...
int index = 0;
std::unordered_map<int, std::function<void(ScriptEngine*)>> unloadCallbacks;
inline int addUnloadCallback(std::function<void(ScriptEngine*)>&& cb) {
unloadCallbacks[++index] = cb;
return index;
}
inline bool removeUnloadCallback(int index) { return unloadCallbacks.erase(index); }

// Init
EngineOwnData() {
dynamicCallVM = dcNewCallVM(4096);
dcMode(dynamicCallVM, DC_CALL_C_DEFAULT);
}
// 基础信息
std::string pluginName = "";
std::string pluginFileOrDirPath = "";
std::string engineType = LLSE_BACKEND_TYPE;

// 表单回调
std::map<unsigned, FormCallbackData> formCallbacks;

// RemoteCall Exported Functions: unordered_map<nameSpace, funcName>
std::unordered_map<std::string, RemoteCallData> exportFuncs;

/*
uint64_t simpleCallbackIndex = 0;
std::unordered_map<uint64_t, SimpleCallbackData> simpleCallbacks;
inline uint64_t addSimpleCallback(script::Local<Function> func,
std::vector<script::Local<Value>> values)
{
auto index = ++simpleCallbackIndex;
std::vector<script::Global<Value>> globalValues;
for (auto& value : values)
globalValues.emplace_back(value);
SimpleCallbackData data{EngineScope::currentEngine(),
script::Global<Function>(func), std::move(globalValues)};
simpleCallbacks.emplace(index, std::move(data));
return index;
}
inline bool removeSimpleCallback(uint64_t index)
{
return simpleCallbacks.erase(index);
}
*/

// I18nAPI
ll::i18n::I18N *i18n = nullptr;

// LoggerAPI
ll::Logger logger = ll::Logger("");
int maxLogLevel = 4;

// 玩家绑定数据
std::unordered_map<std::string, script::Global<Value>> playerDataDB;

// Dynamic Call vm for NativeFFI
DCCallVM *dynamicCallVM;

// Unload Callbacks, use for close database...
int index = 0;
std::unordered_map<int, std::function<void(ScriptEngine *)>> unloadCallbacks;
inline int addUnloadCallback(std::function<void(ScriptEngine *)> &&cb) {
unloadCallbacks[++index] = cb;
return index;
}
inline bool removeUnloadCallback(int index) {
return unloadCallbacks.erase(index);
}

// Init
EngineOwnData() {
dynamicCallVM = dcNewCallVM(4096);
dcMode(dynamicCallVM, DC_CALL_C_DEFAULT);
}
};

// 引擎附加数据
#define ENGINE_GET_DATA(e) (std::static_pointer_cast<EngineOwnData>((e)->getData()))
#define ENGINE_OWN_DATA() (std::static_pointer_cast<EngineOwnData>(EngineScope::currentEngine()->getData()))
#define ENGINE_GET_DATA(e) \
(std::static_pointer_cast<EngineOwnData>((e)->getData()))
#define ENGINE_OWN_DATA() \
(std::static_pointer_cast<EngineOwnData>( \
EngineScope::currentEngine()->getData()))
2 changes: 1 addition & 1 deletion src/main/BindAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ void BindAPIs(ScriptEngine* engine) {
engine->registerNativeClass<ScriptNativeFunction>(NativeCallBuilder);
engine->registerNativeClass<NativeStdString>(NativeStdStringBuilder);
engine->registerNativeClass<DynamicHookData>(NativeHookBuilder);
engine->registerNativeClass<NativePatch>(NativePatchBuilder);
// engine->registerNativeClass<NativePatch>(NativePatchBuilder);
engine->registerNativeClass<GlobalNativePointer>(GlobalNativePointerBuilder);
}
Loading

0 comments on commit edf3acc

Please sign in to comment.