Skip to content

Commit

Permalink
new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 committed Sep 19, 2023
1 parent e3f94c4 commit 80409f1
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeSettings.json
.vscode/
build/
SDK-cpp/
lib/
include/
81 changes: 81 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cmake_minimum_required(VERSION 3.21)

project(ZombieSceptor)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE Release)

file(GLOB_RECURSE SRC_FILES_DIR
${PROJECT_SOURCE_DIR}/src/*.c
${PROJECT_SOURCE_DIR}/src/*.cpp
${PROJECT_SOURCE_DIR}/src/*.h
)

include_directories(
${CMAKE_SOURCE_DIR}/SDK-cpp/include
${CMAKE_SOURCE_DIR}/SDK-cpp/include/llapi
${CMAKE_SOURCE_DIR}/include
)

link_directories(
${CMAKE_SOURCE_DIR}/SDK-cpp/lib
)

add_definitions(
-D"NDEBUG"
-D"NOMINMAX"
-D"TEMPLATE_EXPORTS"
-D"UNICODE"
-D"WIN32_LEAN_AND_MEAN"
-D"_AMD64_"
-D"_CRT_SECURE_NO_WARNINGS"
-D"_UNICODE"
-D"_USRDLL"
-D"_WINDLL"
-D"_WINDOWS"
)

add_compile_options(
/diagnostics:column
/EHsc
/FC
/GL
/MD
/nologo
/permissive-
/sdl
/utf-8
/Zc:inline
/Zi
/MP
)

add_link_options(
/DEBUG
/DELAYLOAD:"bedrock_server.dll"
/DLL
/IGNORE:4199
/INCREMENTAL:NO
/LTCG:INCREMENTAL
/MANIFESTUAC:NO
/MACHINE:X64
/NOLOGO
/OPT:ICF
/OPT:REF
/SUBSYSTEM:CONSOLE
)

add_library(${CMAKE_PROJECT_NAME} SHARED ${SRC_FILES_DIR})

target_link_libraries(${CMAKE_PROJECT_NAME}
"${CMAKE_SOURCE_DIR}/SDK-cpp/lib/LiteLoader.lib"
"${CMAKE_SOURCE_DIR}/SDK-cpp/lib/bedrock_server_api.lib"
"${CMAKE_SOURCE_DIR}/SDK-cpp/lib/bedrock_server_var.lib"
"${CMAKE_SOURCE_DIR}/SDK-cpp/lib/SymDBHelper.lib"
"${CMAKE_SOURCE_DIR}/lib/plhook.lib"
"${CMAKE_SOURCE_DIR}/lib/GMLib.lib"
)

add_custom_command(TARGET ${CMAKE_PROJECT_NAME} PRE_BUILD
COMMAND cmd /c ${PROJECT_SOURCE_DIR}/prepare_libraries.cmd ${PROJECT_SOURCE_DIR}
)
11 changes: 11 additions & 0 deletions prepare_libraries.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off

if not exist %1\SDK-cpp\Lib\bedrock_server_api.lib goto process
if not exist %1\SDK-cpp\Lib\bedrock_server_var.lib goto process
goto end

:process
cd /d %1\SDK-cpp\tools\
PeEditor.exe -c -l -o ../lib

:end
Empty file added src/DamageCause.cpp
Empty file.
7 changes: 7 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <LoggerAPI.h>
#include "version.h"
#include <GMLib/GMLib_ModAPI.h>
#include <mc/ActorDamageSource.hpp>

extern Logger logger;

53 changes: 53 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <LoggerAPI.h>
#include <ServerAPI.h>
#include "version.h"

void PluginInit();
bool CanLoad = false;

Logger logger(PLUGIN_NAME);

void CheckProtocolVersion() {
auto current_protocol = ll::getServerProtocolVersion();
if (TARGET_BDS_PROTOCOL_VERSION != current_protocol) {
logger.error("Protocol version mismatched! Target version: {}. Current version: {}.", TARGET_BDS_PROTOCOL_VERSION, current_protocol);
logger.error("This may result in crash. Please switch to the version matching the BDS version!");
}
else {
CanLoad = true;
PluginInit();
}
}

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
ll::registerPlugin(
PLUGIN_NAME,
PLUGIN_INTRODUCTION,
ll::Version(PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_REVISION, PLUGIN_LLVERSION_STATUS),
std::map<std::string, std::string>{
{"Author", PLUGIN_AUTHOR},
});
break;

case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

extern "C"
{
_declspec(dllexport) void onPostInit()
{
std::ios::sync_with_stdio(false);
CheckProtocolVersion();
}
}
52 changes: 52 additions & 0 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#define PLUGIN_VERSION_DEV 0
#define PLUGIN_VERSION_BETA 1
#define PLUGIN_VERSION_RELEASE 2

#define PLUGIN_NAME "ZombieSceptor"
#define PLUGIN_INTRODUCTION "GMLib Mod Test - ZombieSceptor"
#define PLUGIN_AUTHOR "Tsubasa6848"

#define PLUGIN_VERSION_MAJOR 1
#define PLUGIN_VERSION_MINOR 0
#define PLUGIN_VERSION_REVISION 0
#define PLUGIN_VERSION_BUILD 0
#define TARGET_BDS_PROTOCOL_VERSION 594

#define PLUGIN_VERSION_STATUS 2

#define __TO_VERSION_STRING(ver) #ver
#define TO_VERSION_STRING(ver) __TO_VERSION_STRING(ver)

#if PLUGIN_VERSION_STATUS == 0

#define PLUGIN_FILE_VERSION_FLAG VS_FF_DEBUG
#define PLUGIN_LLVERSION_STATUS ll::Version::Dev
#define PLUGIN_FILE_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_REVISION.PLUGIN_VERSION_BUILD DEV)

#elif PLUGIN_VERSION_STATUS == 1

#define PLUGIN_FILE_VERSION_FLAG VS_FF_DEBUG
#define PLUGIN_LLVERSION_STATUS ll::Version::Beta
#define PLUGIN_FILE_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_REVISION.PLUGIN_VERSION_BUILD BETA)

#else

#define PLUGIN_FILE_VERSION_FLAG 0x0L
#define PLUGIN_LLVERSION_STATUS ll::Version::Release
#define PLUGIN_FILE_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_REVISION.PLUGIN_VERSION_BUILD)

#endif

#define FILE_VERSION_BLOCK_HEADER 0x04004B0L
#define FILE_VERSION_COMPANY_NAME PLUGIN_AUTHOR
#define FILE_VERSION_LEGAL_COPYRIGHT "Copyright (C) 2022"
#define FILE_VERSION_FILE_DESCRIPTION PLUGIN_INTRODUCTION
#define FILE_VERSION_FILE_VERSION_STRING PLUGIN_FILE_VERSION_STRING
#define FILE_VERSION_INTERNAL_NAME PLUGIN_NAME
#define FILE_VERSION_ORIGINAL_FILENAME PLUGIN_NAME ".dll"
#define FILE_VERSION_PRODUCT_NAME FILE_VERSION_INTERNAL_NAME
#define FILE_VERSION_PRODUCT_VERSION_STRING PLUGIN_FILE_VERSION_STRING
#define FILE_VERSION_FILE_VERSION PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_REVISION, PLUGIN_VERSION_BUILD
#define FILE_VERSION_PRODUCT_VERSION FILE_VERSION_FILE_VERSION

0 comments on commit 80409f1

Please sign in to comment.