mirror of
https://github.com/CDevJoud/Minecraft-Community-Edition.git
synced 2026-07-18 00:30:46 +00:00
added SampleMod For C++
This commit is contained in:
28
SampleModCpp/MyMod.cpp
Normal file
28
SampleModCpp/MyMod.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "XPP.hpp"
|
||||
|
||||
class MyMod : public IXPP {
|
||||
public:
|
||||
MyMod();
|
||||
~MyMod();
|
||||
XAPIDescriptor query() override {
|
||||
return XAPIDescriptor();
|
||||
}
|
||||
int onInit() override {
|
||||
XPP::logDebug("Hello C++");
|
||||
return 1;
|
||||
}
|
||||
int onUpdate() override {
|
||||
return 1;
|
||||
}
|
||||
int onShutdown() override {
|
||||
return 1;
|
||||
}
|
||||
}mod;
|
||||
|
||||
MyMod::MyMod() {
|
||||
XPP::initXPP(&mod);
|
||||
}
|
||||
|
||||
MyMod::~MyMod() {
|
||||
|
||||
}
|
||||
155
SampleModCpp/SampleModCpp.vcxproj
Normal file
155
SampleModCpp/SampleModCpp.vcxproj
Normal file
@@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MyMod.cpp" />
|
||||
<ClCompile Include="XPP.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="XPP.hpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{62121dc8-0ebd-43f8-8d30-85db30a3574d}</ProjectGuid>
|
||||
<RootNamespace>SampleModCpp</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>$(SolutionDir)\Minecraft-Community-Edition\Mod\;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>$(SolutionDir)\Minecraft-Community-Edition\Mod\;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;SAMPLEMODCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;SAMPLEMODCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;SAMPLEMODCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp23</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;SAMPLEMODCPP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp23</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
30
SampleModCpp/SampleModCpp.vcxproj.filters
Normal file
30
SampleModCpp/SampleModCpp.vcxproj.filters
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MyMod.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="XPP.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="XPP.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
124
SampleModCpp/XPP.cpp
Normal file
124
SampleModCpp/XPP.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#include "XPP.hpp"
|
||||
|
||||
IXPP* XPP::_instance;
|
||||
XI_createDeviceAndContextFn XI_createDeviceAndContext;
|
||||
XI_destroyDeviceAndContextFn XI_destroyDeviceAndContext;
|
||||
XHQEventBus qBus;
|
||||
XIDevice* device;
|
||||
XIContext* ctx;
|
||||
XIExports exports;
|
||||
|
||||
XPP& XPP::getSingleton() {
|
||||
static XPP xpp;
|
||||
return xpp;
|
||||
}
|
||||
|
||||
void XPP::initXPP(IXPP* instance) {
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
void XPP::logDebug(const std::string& msg) {
|
||||
XSEventLog log;
|
||||
log.channel = "default";
|
||||
log.msg = msg.c_str();
|
||||
log.severity = XE_EVENT_LOG_DEBUG;
|
||||
XPP::postEvent(nullptr, &log, XE_EVENT_TYPE_LOG);
|
||||
}
|
||||
|
||||
IXPP* XPP::getModInstance() {
|
||||
return _instance;
|
||||
}
|
||||
XHQEventBus CXAPI_createQEventBus(Xcstr name) {
|
||||
XHQEventBus qBus;
|
||||
if (device->vtbl->createQEventBus != XAPI_NULL) {
|
||||
XQEventBusDescriptor qBusdesc;
|
||||
qBusdesc.name = name;
|
||||
qBusdesc.maxSize = 0xFFFF;
|
||||
device->vtbl->createQEventBus(device, &qBus, qBusdesc);
|
||||
}
|
||||
else {
|
||||
qBus.idx = 0;
|
||||
}
|
||||
return qBus;
|
||||
}
|
||||
XHQEventBus XPP::createQEventBus(const std::string& name) {
|
||||
XHQEventBus qBus;
|
||||
if (device->vtbl->createQEventBus != XAPI_NULL) {
|
||||
XQEventBusDescriptor qBusDesc;
|
||||
qBusDesc.name = name.c_str();
|
||||
qBusDesc.maxSize = 0xFFFF;
|
||||
device->vtbl->createQEventBus(device, &qBus, qBusDesc);
|
||||
}
|
||||
else {
|
||||
qBus.idx = 0;
|
||||
}
|
||||
return qBus;
|
||||
}
|
||||
|
||||
int XPP::postEvent(XHQEventBus* _qBus, Xvoid* event, Xconst Xuint64 type) {
|
||||
XHQEventBus thisQbus;
|
||||
if (_qBus == XAPI_NULL) {
|
||||
thisQbus.idx = qBus.idx;
|
||||
}
|
||||
else {
|
||||
thisQbus.idx = _qBus->idx;
|
||||
}
|
||||
return (ctx->vtbl->postEvent != XAPI_NULL) ? ctx->vtbl->postEvent(&thisQbus, event, type) : XE_ERROR;
|
||||
}
|
||||
|
||||
extern "C" XAPI_EXPORT XAPIDescriptor XI_query(Xvoid) {
|
||||
auto& instance = XPP::getSingleton();
|
||||
auto desc = instance.getModInstance()->query();
|
||||
desc.sdkName = "XPP";
|
||||
return desc;
|
||||
}
|
||||
|
||||
extern "C" XAPI_EXPORT Xint32 XI_main(Xvoid* pParam) {
|
||||
XI_createDeviceAndContext = (XI_createDeviceAndContextFn)pParam;
|
||||
Xconst Xint32 ret = XI_createDeviceAndContext(&device, &ctx);
|
||||
|
||||
if (ret != XE_ERROR) {
|
||||
|
||||
if (device != XAPI_NULL && ctx != XAPI_NULL) {
|
||||
if (device->vtbl != XAPI_NULL && ctx->vtbl != XAPI_NULL) {
|
||||
if (device->vtbl->createQEventBus != XAPI_NULL) {
|
||||
XQEventBusDescriptor desc{};
|
||||
desc.maxSize = 0xFFFF;
|
||||
desc.name = "APP";
|
||||
device->vtbl->createQEventBus(device, &qBus, desc);
|
||||
}
|
||||
else {
|
||||
return XE_ERROR;
|
||||
}
|
||||
|
||||
exports.onInit = []() -> Xint32 {return XPP::getSingleton().getModInstance()->onInit(); };
|
||||
exports.onUpdate = []() -> Xint32 {return XPP::getSingleton().getModInstance()->onUpdate(); };
|
||||
exports.onShutdown = []() -> Xint32 {return XPP::getSingleton().getModInstance()->onShutdown(); };
|
||||
|
||||
if (device->vtbl->setXIExports != XAPI_NULL) {
|
||||
device->vtbl->setXIExports(device, exports);
|
||||
}
|
||||
else {
|
||||
return XE_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return XE_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return XE_ERROR;
|
||||
}
|
||||
}
|
||||
XPP::getSingleton().logDebug("XPP loaded up successfully! XAPI version v1.0.0");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
extern "C" XAPI_EXPORT Xint32 XI_terminate(Xvoid* pParam) {
|
||||
XI_destroyDeviceAndContext = (XI_destroyDeviceAndContextFn)pParam;
|
||||
|
||||
auto ret = XI_destroyDeviceAndContext(&device, &ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
28
SampleModCpp/XPP.hpp
Normal file
28
SampleModCpp/XPP.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#define XAPI_USE_V1_0_0
|
||||
#include "XAPI.h"
|
||||
#include <string>
|
||||
|
||||
class IXPP {
|
||||
public:
|
||||
virtual ~IXPP() {
|
||||
|
||||
}
|
||||
virtual XAPIDescriptor query() = 0;
|
||||
virtual int onInit() = 0;
|
||||
virtual int onUpdate() = 0;
|
||||
virtual int onShutdown() = 0;
|
||||
};
|
||||
|
||||
class XPP {
|
||||
public:
|
||||
static XPP& getSingleton();
|
||||
static void initXPP(IXPP* instance);
|
||||
static void logDebug(const std::string& msg);
|
||||
static IXPP* getModInstance();
|
||||
static XHQEventBus createQEventBus(const std::string& name);
|
||||
static int postEvent(XHQEventBus* _qBus, Xvoid* event, Xconst Xuint64 type);
|
||||
private:
|
||||
static IXPP* _instance;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user