mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-20 04:33:53 +00:00
Merge branch 'feature/plugin-api' of github.com:sylvessa/MinecraftConsoles into feature/plugin-api
This commit is contained in:
commit
8e66b2c19e
13 changed files with 570 additions and 5 deletions
|
|
@ -30,6 +30,8 @@ typedef int(__stdcall *fn_fire_player_move)(int entityId,
|
|||
double fromX, double fromY, double fromZ,
|
||||
double toX, double toY, double toZ,
|
||||
double *outCoords);
|
||||
typedef void(__stdcall* fn_set_scheduler_callbacks)(void* add, void* remove);
|
||||
typedef void(__stdcall* fn_fire_scheduler_callback)(int currentTick);
|
||||
typedef void(__stdcall *fn_set_native_callbacks)(void *damage, void *setHealth, void *teleport, void *setGameMode, void *broadcastMessage, void *setFallDistance, void *getPlayerSnapshot, void *sendMessage, void *setWalkSpeed, void *teleportEntity);
|
||||
typedef void(__stdcall *fn_set_world_callbacks)(void *getTileId, void *getTileData, void *setTile, void *setTileData, void *breakBlock, void *getHighestBlockY, void *getWorldInfo, void *setWorldTime, void *setWeather, void *createExplosion, void *strikeLightning, void *setSpawnLocation, void *dropItem);
|
||||
typedef void(__stdcall *fn_update_entity_id)(int oldEntityId, int newEntityId);
|
||||
|
|
@ -128,6 +130,8 @@ static fn_update_entity_id s_managedUpdateEntityId = nullptr;
|
|||
static fn_fire_player_quit s_managedFireQuit = nullptr;
|
||||
static fn_fire_player_kick s_managedFireKick = nullptr;
|
||||
static fn_fire_player_move s_managedFireMove = nullptr;
|
||||
static fn_set_scheduler_callbacks s_managedSetSchedulerCallbacks = nullptr;
|
||||
static fn_fire_scheduler_callback s_managedFireSchedulerCallback = nullptr;
|
||||
static fn_set_native_callbacks s_managedSetCallbacks = nullptr;
|
||||
static fn_set_world_callbacks s_managedSetWorldCallbacks = nullptr;
|
||||
static fn_fire_structure_grow s_managedFireStructureGrow = nullptr;
|
||||
|
|
@ -211,6 +215,8 @@ void Initialize()
|
|||
{L"FirePlayerQuit", (void **)&s_managedFireQuit},
|
||||
{L"FirePlayerKick", (void **)&s_managedFireKick},
|
||||
{L"FirePlayerMove", (void **)&s_managedFireMove},
|
||||
{L"SetSchedulerCallbacks", (void**)&s_managedSetSchedulerCallbacks},
|
||||
{L"FireSchedulerCallback", (void**)&s_managedFireSchedulerCallback},
|
||||
{L"SetNativeCallbacks", (void **)&s_managedSetCallbacks},
|
||||
{L"SetWorldCallbacks", (void **)&s_managedSetWorldCallbacks},
|
||||
{L"UpdatePlayerEntityId", (void **)&s_managedUpdateEntityId},
|
||||
|
|
@ -270,9 +276,11 @@ void Initialize()
|
|||
return;
|
||||
}
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
s_managedInit();
|
||||
s_managedSetSchedulerCallbacks(
|
||||
(void*)&NativeAddScheduler,
|
||||
(void*)&NativeRemoveScheduler
|
||||
);
|
||||
|
||||
s_managedSetCallbacks(
|
||||
(void *)&NativeDamagePlayer,
|
||||
|
|
@ -375,6 +383,10 @@ void Initialize()
|
|||
(void *)&NativeGetWorldEntities,
|
||||
(void *)&NativeGetChunkEntities);
|
||||
|
||||
//we should init after setting callbacks so we have access inside the plugins on enable
|
||||
s_initialized = true;
|
||||
s_managedInit();
|
||||
|
||||
LogInfo("fourkit", "FourKit initialized successfully.");
|
||||
}
|
||||
|
||||
|
|
@ -515,6 +527,16 @@ void UpdatePlayerEntityId(int oldEntityId, int newEntityId)
|
|||
LogDebugf("fourkit", "UpdatePlayerEntityId: %d -> %d", oldEntityId, newEntityId);
|
||||
}
|
||||
|
||||
void FireSchedulerCallback(int currentTick)
|
||||
{
|
||||
if (!s_initialized || !s_managedFireSchedulerCallback)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_managedFireSchedulerCallback(currentTick);
|
||||
}
|
||||
|
||||
bool FirePlayerMove(int entityId,
|
||||
double fromX, double fromY, double fromZ,
|
||||
double toX, double toY, double toZ,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace FourKitBridge
|
|||
bool FirePlayerQuit(int entityId);
|
||||
bool FirePlayerKick(int entityId, int disconnectReason,
|
||||
std::wstring &outLeaveMessage);
|
||||
void FireSchedulerCallback(int currentTick);
|
||||
bool FirePlayerMove(int entityId,
|
||||
double fromX, double fromY, double fromZ,
|
||||
double toX, double toY, double toZ,
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
#include "Common\NetworkUtils.h"
|
||||
#include "ServerLogManager.h"
|
||||
#include "../Minecraft.World/ItemInstance.cpp"
|
||||
#include <mutex>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -104,12 +105,79 @@ class VirtualContainer : public SimpleContainer
|
|||
return m_containerType;
|
||||
}
|
||||
};
|
||||
class NativeFourKitTask;
|
||||
|
||||
static int64_t STATIC_lastTick = -1;
|
||||
static std::unordered_map<int, std::shared_ptr<NativeFourKitTask>> _taskCache;
|
||||
static std::mutex _taskMutex;
|
||||
|
||||
class NativeFourKitTask {
|
||||
public:
|
||||
int startDelay;
|
||||
int runCooldown;
|
||||
|
||||
int lastRunTick;
|
||||
|
||||
NativeFourKitTask(int _startDelay, int _runCooldown) : startDelay(_startDelay), runCooldown(_runCooldown), lastRunTick(-1) {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace FourKitBridge
|
||||
{
|
||||
void __cdecl NativeDamagePlayer(int entityId, float amount)
|
||||
|
||||
void __cdecl NativeAddScheduler(int taskid, int startDelay, int runCooldown)
|
||||
{
|
||||
std::lock_guard<std::mutex> g(_taskMutex);
|
||||
_taskCache.emplace(taskid, std::make_shared<NativeFourKitTask>(startDelay, runCooldown));
|
||||
}
|
||||
|
||||
void __cdecl NativeRemoveScheduler(int taskid)
|
||||
{
|
||||
std::lock_guard<std::mutex> g(_taskMutex);
|
||||
auto it = _taskCache.find(taskid);
|
||||
|
||||
if (it != _taskCache.end()) {
|
||||
_taskCache.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerTickCallback(int currentTick)
|
||||
{
|
||||
bool callManagedFunction = false;
|
||||
|
||||
if (STATIC_lastTick == -1) {
|
||||
callManagedFunction = true;
|
||||
STATIC_lastTick = currentTick;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> g(_taskMutex);
|
||||
for (const auto& [taskid, task] : _taskCache)
|
||||
{
|
||||
NativeFourKitTask* taskPointer = task.get();
|
||||
if (taskPointer->startDelay > 0) {
|
||||
taskPointer->startDelay -= (currentTick - STATIC_lastTick);
|
||||
|
||||
if (taskPointer->startDelay <= 0) {
|
||||
callManagedFunction = true; //make c# update the tasks so its not queued anymore but now its running
|
||||
taskPointer->startDelay = 0; //ensure it stays 0
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int lastTaskTick = taskPointer->lastRunTick;
|
||||
if (lastTaskTick == -1 || (lastTaskTick + taskPointer->runCooldown) <= currentTick) {
|
||||
callManagedFunction = true;
|
||||
taskPointer->lastRunTick = currentTick;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callManagedFunction) FireSchedulerCallback(currentTick);
|
||||
STATIC_lastTick = currentTick;
|
||||
}
|
||||
void __cdecl NativeDamagePlayer(int entityId, float amount)
|
||||
{
|
||||
auto player = FindPlayer(entityId);
|
||||
if (player)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@
|
|||
|
||||
namespace FourKitBridge
|
||||
{
|
||||
//scheduler
|
||||
void __cdecl NativeAddScheduler(int taskid, int startDelay, int runCooldown);
|
||||
void __cdecl NativeRemoveScheduler(int taskid);
|
||||
|
||||
void ServerTickCallback(int currentTick);
|
||||
|
||||
// core
|
||||
void __cdecl NativeDamagePlayer(int entityId, float amount);
|
||||
void __cdecl NativeSetPlayerHealth(int entityId, float health);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue