Merged projects with plugins and modules

This commit is contained in:
2024-07-22 01:18:00 +03:00
parent 1fd065f4c2
commit 8ace51c840
59 changed files with 1669 additions and 73 deletions

View File

@@ -0,0 +1,22 @@
using System.Runtime.InteropServices;
using CppWrapper.Objects;
namespace DiscordBotUI
{
public abstract class Delegates
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ProcessApplicationData(ref ApplicationStruct appData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ProcessComplexObject(ref ComplexObject complexObject);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void CsharpFunctionDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetCsharpFunctionPointerDelegate(IntPtr funcPtr);
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\DiscordBotCore\DiscordBotCore.csproj" />
<ProjectReference Include="..\CppWrapper\CppWrapper.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,52 @@
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
using CppWrapper.Objects;
using CppWrapper.LibraryManagement;
using DiscordBotCore;
using CppWrapper;
namespace DiscordBotUI;
public class Entry : ICommandAction
{
public string ActionName => "cppui";
public string? Description => "A C++ linker to the C++ UI for the bot";
public string? Usage => "cppui";
public IEnumerable<InternalActionOption> ListOfOptions => [];
public InternalActionRunType RunType => InternalActionRunType.OnStartupAndCall;
public async Task Execute(string[]? args)
{
try{
string appUiComponent = "./Data/Test/libtestlib.dll";
ExternLibrary externalLibrary = new ExternLibrary(appUiComponent);
externalLibrary.InitializeLibrary();
externalLibrary.SetExternFunctionSetterPointerToCustomDelegate<Delegates.SetCsharpFunctionPointerDelegate, Delegates.CsharpFunctionDelegate>("setCSharpFunctionPointer", () =>
{
Console.WriteLine("Hello from C#. This code is called from the C# function");
});
Delegates.ProcessComplexObject processObj = externalLibrary.GetDelegateForFunctionPointer<Delegates.ProcessComplexObject>("ProcessComplexObject");
ComplexObject complexObject = new ComplexObject(10, 10.5, "Hello from C#");
processObj(ref complexObject);
Console.WriteLine($"Integer: {complexObject.Integer}");
Console.WriteLine($"Double: {complexObject.DoubleValue}");
Console.WriteLine($"String: {complexObject.strValue}");
externalLibrary.FreeLibrary();
} catch (Exception dllException) {
Application.CurrentApplication.Logger.LogException(dllException, this);
}
}
}