当前位置: 首页 > news >正文

C++插件管理系统

插件加载目录结构

execute
    plug.exe
    plugify.dll
    plugify.pconfig
    res
        cpp-lang-module.pmodule
        example_plugin.pplugin
        bin
            cpp-lang-module.dll
            example_plugin.dll

 plugify.pconfig

{
    "baseDir": "res",
    "logSeverity": "debug",
    "repositories": [
    ],
    "preferOwnSymbols": false
}

example_plugin.pplugin

{
    "fileVersion": 1,
    "version": 1,
    "versionName": "1.0",
    "friendlyName": "PluginCPP",
    "description": "An example of a plugin. This can be used as a starting point when creating your own plugin.",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/orgs/untrustedmodders/README.md",
    "downloadURL": "https://github.com/orgs/untrustedmodders/example-repo.zip",
    "updateURL": "https://github.com/untrustedmodders/plugify/issues",
    "entryPoint": "bin/example_plugin",
    "supportedPlatforms": [],
    "languageModule": {
        "name": "cpp"
    },
    "dependencies": [],
    "exportedMethods": [
        {
            "name": "MakePrint",
            "funcName": "MakePrint",
            "paramTypes": [
                {
                    "type": "int32",
                    "name": "count"
                },
                {
                    "type": "string",
                    "name": "message"
                }
            ],
            "retType": {
                "type": "void"
            }
        }
    ]
}

 cpp-lang-module.pmodule

{
    "fileVersion": 1,
    "version": 0,
    "versionName": "v0",
    "friendlyName": "Cpp language module",
    "language": "cpp",
    "description": "Adds support for C++ plugins",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/untrustedmodders/cpp-lang-module/blob/main/README.md",
    "downloadURL": "https://github.com/untrustedmodders/cpp-lang-module/releases/download/v0/cpp-lang-module.zip",
    "updateURL": "https://untrustedmodders.github.io/cpp-lang-module/cpp-lang-module.json",
    "supportedPlatforms": [],
    "forceLoad": false
}

 插件定义
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>
#include <iostream>class ExamplePlugin : public plugify::IPluginEntry {
public:void OnPluginStart() override {std::cout << "Example Start!" << std::endl;}void OnPluginEnd() override {std::cout << "Example End!" << std::endl;}void MakePrint(int count, const std::string& message) {for (int i = 0; i < count; ++i) {std::cout << message << std::endl;}}
} g_examplePlugin;EXPOSE_PLUGIN(PLUGIN_API, &g_examplePlugin)extern "C"
PLUGIN_API void MakePrint(int count, const std::string& message) {g_examplePlugin.MakePrint(count, message);
}
 模块定义

#include <plugify/assembly.h>
#include <plugify/module.h>
#include <plugify/plugin.h>
#include <plugify/plugify_provider.h>
#include <plugify/language_module.h>
#include <plugify/cpp_plugin.h>#include <module_export.h>
#include <unordered_map>
#include <map>
#include <array>class CppLanguageModule final : public plugify::ILanguageModule {
public:CppLanguageModule() = default;// ILanguageModuleplugify::InitResult Initialize(std::weak_ptr<plugify::IPlugifyProvider> provider, plugify::ModuleRef module) override;void Shutdown() override;void OnMethodExport(plugify::PluginRef plugin) override;plugify::LoadResult OnPluginLoad(plugify::PluginRef plugin) override;void OnPluginStart(plugify::PluginRef plugin) override;void OnPluginEnd(plugify::PluginRef plugin) override;bool IsDebugBuild() override;const std::shared_ptr<plugify::IPlugifyProvider>& GetProvider() { return _provider; }plugify::MemAddr GetNativeMethod(std::string_view methodName) const;void GetNativeMethod(std::string_view methodName, plugify::MemAddr* addressDest);private:std::shared_ptr<plugify::IPlugifyProvider> _provider;std::map<plugify::UniqueId, AssemblyHolder> _assemblyMap;std::unordered_map<std::string, plugify::MemAddr, string_hash, std::equal_to<>> _nativesMap;std::vector<plugify::MemAddr*> _addresses;static std::array<void*, 15> _pluginApi;
};// ILanguageModule
InitResult CppLanguageModule::Initialize(std::weak_ptr<IPlugifyProvider> provider, ModuleRef /*module*/) {if (!(_provider = provider.lock())) {return ErrorData{ "Provider not exposed" };}_provider->Log("[CPPLM]  Inited!", Severity::Debug);return InitResultData{};
}
 测试
plug.exe
plugify init
[+] Info: Plugify Init!
[+] Info: Version: 1.0.0.0
[+] Info: Git: [v35-1-g08987de]:(v35) - Fix cmake typo in test on main at 'Sun Sep 1 09:21:31 2024'
[+] Info: Compiled on: Windows-10.0.19045 from: Ninja with: 'MSVC'
[~] Debug: Loading local packages
[~] Debug: Loading remote packages
[#] Error: Packages manifest from 'https://github.com/untrustedmodders/plugify/issues' has JSON parsing error: 8:1: expected_brace<!DOCTYPE html>^
[~] Debug: PackageManager loaded in 788.826ms
[~] Debug: [CPPLM] Inited!
Example Start!
[~] Debug: PluginManager loaded in 10.951ms
 参考

GitHub - untrustedmodders/cpp-lang-module: C++ Language Module


 

创作不易,小小的支持一下吧!


http://www.mrgr.cn/news/22826.html

相关文章:

  • Docker的基本概念和优势
  • 什么是图像的边缘?说说边缘检测的任务以及基本原理?
  • 骨传导耳机品牌排行榜前五名揭秘!5大爆款骨传导耳机实测汇总!
  • 线性基 高斯消元法 C++
  • 低代码,是全村希望还是智商税?
  • 03 Flask-添加配置信息
  • HCIA--实验十三:VLAN间通信子接口实验/双单臂路由实验
  • idea开发Java程序的步骤及设置
  • Flux【大模型】【真人模型】:朴素的真实感,一款适合自媒体和朋友圈小伙伴的Flux大模型墨幽随拍
  • 计算机毕业设计 | springboot 图书商城 书店管理系统(附源码)
  • 安宝特案例 | AR如何大幅提升IC封装厂检测效率?
  • 软件工程知识点总结(4):概要设计
  • 在 RT-Thread 上使用单色屏 UI 库 - U8G2
  • djangobilibili网用户数据采集系统-计算机毕业设计源码55962
  • 七种方法加密图纸!2024企业要如何对CAD图纸进行加密?
  • 343. 整数拆分
  • 为什么RAG对下一代AI开发至关重要
  • 最新前端开发VSCode高效实用插件推荐清单
  • 【漏洞复现】泛微OA E-Cology XmlRpcServlet 任意文件读取漏洞
  • 自己平时常用的linux命令