diff --git a/docs/en/rust-sdk.md b/docs/en/rust-sdk.md index 87c9261..5ec1873 100644 --- a/docs/en/rust-sdk.md +++ b/docs/en/rust-sdk.md @@ -4,16 +4,5 @@ Rust SDK uses similar to C++ interface with some extra wrapping methods to allow ## Example -See the `Dylib` plugin. It adds a class `DynamicLibrary` with the following methods: - -```ts -declare class DynamicLibrary { - constructor(handle: number); - static Load(libraryFileName: string): DynamicLibrary | undefined; - free(): void; - getProcedure(procName: string): int | undefined; -} -``` - -[See more information](https://library.sannybuilder.com/#/sa_unreal/classes/DynamicLibrary) in Sanny Builder Library. The usage of the `DynamicLibrary` class requires a `dll` [permission](./permissions.md). - +See the `Input` plugin. It adds a bunch of new commands to check or emulate keyboard and mouse input. +https://github.com/cleolibrary/CLEO-Redux/tree/master/plugins/Input diff --git a/plugins/Dylib/.cargo/config b/plugins/Dylib/.cargo/config deleted file mode 100644 index a9f279d..0000000 --- a/plugins/Dylib/.cargo/config +++ /dev/null @@ -1,17 +0,0 @@ -[build] -target = "i686-pc-windows-msvc" -#target = "x86_64-pc-windows-msvc" - -[target.i686-pc-windows-msvc] -rustflags = [ - "-C", "target-feature=+crt-static", - "-C", "link-arg=/OUT:build/dylib.cleo", - "-L", "../../SDK" -] - -[target.x86_64-pc-windows-msvc] -rustflags = [ - "-C", "target-feature=+crt-static", - "-C", "link-arg=/OUT:build/dylib64.cleo", - "-L", "../../SDK" -] diff --git a/plugins/Dylib/Cargo.lock b/plugins/Dylib/Cargo.lock deleted file mode 100644 index 34f58a9..0000000 --- a/plugins/Dylib/Cargo.lock +++ /dev/null @@ -1,101 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "cleo_redux_sdk" -version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c1e23e39a04a8a72bc3878d743c9dc32ababf2fe4ea87d3b0f3c930c14e5b0" - -[[package]] -name = "ctor" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "dylib" -version = "1.1.0" -dependencies = [ - "cleo_redux_sdk", - "ctor", - "libloading", -] - -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/plugins/Dylib/Cargo.toml b/plugins/Dylib/Cargo.toml deleted file mode 100644 index 45186c7..0000000 --- a/plugins/Dylib/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "dylib" -version = "1.1.0" -edition = "2021" -authors = ["Seemann "] - -[lib] -crate-type = ["cdylib"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ctor = "0.1.21" -libloading = "0.7.3" -cleo_redux_sdk = "0.0.7" \ No newline at end of file diff --git a/plugins/Dylib/Dylib.sln b/plugins/Dylib/Dylib.sln new file mode 100644 index 0000000..bff3bad --- /dev/null +++ b/plugins/Dylib/Dylib.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33027.164 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dylib", "Dylib.vcxproj", "{CD9B9381-1C83-463A-9B6A-0B85A5757304}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Debug|x64.ActiveCfg = Debug|x64 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Debug|x64.Build.0 = Debug|x64 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Debug|x86.ActiveCfg = Debug|Win32 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Debug|x86.Build.0 = Debug|Win32 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Release|x64.ActiveCfg = Release|x64 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Release|x64.Build.0 = Release|x64 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Release|x86.ActiveCfg = Release|Win32 + {CD9B9381-1C83-463A-9B6A-0B85A5757304}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B9BB6CCA-CC2A-4298-967B-099E9EA49CA7} + EndGlobalSection +EndGlobal diff --git a/plugins/Dylib/Dylib.vcxproj b/plugins/Dylib/Dylib.vcxproj new file mode 100644 index 0000000..60329ba --- /dev/null +++ b/plugins/Dylib/Dylib.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {cd9b9381-1c83-463a-9b6a-0b85a5757304} + Dylib + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + .cleo + $(SolutionDir)build\ + + + false + .cleo + $(SolutionDir)build\ + + + true + 64.cleo + $(SolutionDir)build\ + + + false + 64.cleo + $(SolutionDir)build\ + + + + Level3 + true + WIN32;_DEBUG;DYLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + + + Windows + true + false + ../../sdk/cleo_redux.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;DYLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + + + Windows + true + true + true + false + ../../sdk/cleo_redux.lib;%(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;DYLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + + + Windows + true + false + ../../sdk/cleo_redux64.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;DYLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + + + Windows + true + true + true + false + ../../sdk/cleo_redux64.lib;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/plugins/Dylib/dllmain.cpp b/plugins/Dylib/dllmain.cpp new file mode 100644 index 0000000..8a0ea01 --- /dev/null +++ b/plugins/Dylib/dllmain.cpp @@ -0,0 +1,71 @@ +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include + +#include "../../SDK/cleo_redux_sdk.h" + +class DylibPlugin { +public: + DylibPlugin() { + Log("Dylib plugin 2.0"); + + RegisterCommand("LOAD_DYNAMIC_LIBRARY", LoadDynamicLibrary, "dll"); + RegisterCommand("FREE_DYNAMIC_LIBRARY", FreeDynamicLibrary, "dll"); + RegisterCommand("GET_DYNAMIC_LIBRARY_PROCEDURE", GetDynamicLibraryProcedure, "dll"); + } + + // https://library.sannybuilder.com/#/unknown_x86/dylib/LOAD_DYNAMIC_LIBRARY + static HandlerResult LoadDynamicLibrary(Context ctx) + { + wchar_t libname[MAX_PATH]; + char buf[STR_MAX_LEN]; + + GetStringParam(ctx, buf, sizeof(buf)); + + char message[STR_MAX_LEN * 2]; + sprintf(message, "Loading dynamic library %s", buf); + Log(message); + + // if libname is just a file name then load it as is - subject to DLL search order + // https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order + if ((strrchr(buf, '/') || strchr(buf, '\\'))) { + char path[MAX_PATH]; + + ResolvePath(buf, path); + MultiByteToWideChar(CP_UTF8, 0, path, -1, libname, MAX_PATH); + } + else { + MultiByteToWideChar(CP_UTF8, 0, buf, -1, libname, MAX_PATH); + } + + auto libHandle = LoadLibrary(libname); + SetIntParam(ctx, (isize)libHandle); + UpdateCompareFlag(ctx, libHandle != nullptr); + + return HandlerResult::CONTINUE; + } + + // https://library.sannybuilder.com/#/unknown_x86/dylib/FREE_DYNAMIC_LIBRARY + static HandlerResult FreeDynamicLibrary(Context ctx) + { + FreeLibrary((HMODULE)GetIntParam(ctx)); + return HandlerResult::CONTINUE; + } + + // https://library.sannybuilder.com/#/unknown_x86/dylib/GET_DYNAMIC_LIBRARY_PROCEDURE + static HandlerResult GetDynamicLibraryProcedure(Context ctx) + { + char buf[STR_MAX_LEN]; + + GetStringParam(ctx, buf, sizeof(buf)); + auto libHandle = GetIntParam(ctx); + + void* funcAddr = (void*)GetProcAddress((HMODULE)libHandle, buf); + SetIntParam(ctx, (isize)funcAddr); + UpdateCompareFlag(ctx, funcAddr != nullptr); + + return HandlerResult::CONTINUE; + } +} DylibPlugin; \ No newline at end of file diff --git a/plugins/Dylib/src/impl.rs b/plugins/Dylib/src/impl.rs deleted file mode 100644 index ea2747c..0000000 --- a/plugins/Dylib/src/impl.rs +++ /dev/null @@ -1,60 +0,0 @@ -use cleo_redux_sdk::*; -use libloading; - -/// https://library.sannybuilder.com/#/unknown_x86/dylib/LOAD_DYNAMIC_LIBRARY -pub extern "C" fn load_dynamic_library(ctx: Context) -> HandlerResult { - let libname = get_string_param(ctx); - - // if libname is just a file name then load it as is - subject to DLL search order - // https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order - let path = if libname.contains("\\") || libname.contains("/") { - resolve_path(&libname) - } else { - std::path::PathBuf::from(&libname) - }; - - log(format!("loading dynamic library {libname}")); - - match unsafe { libloading::Library::new(path) } { - Ok(handle) => { - let addr = Box::into_raw(Box::new(handle)); - set_int_param(ctx, addr as isize); - update_compare_flag(ctx, true); - } - Err(error) => { - log(format!("{error}")); - update_compare_flag(ctx, false); - set_int_param(ctx, 0); - } - } - HandlerResult::CONTINUE -} - -/// https://library.sannybuilder.com/#/unknown_x86/dylib/FREE_DYNAMIC_LIBRARY -pub extern "C" fn free_dynamic_library(ctx: Context) -> HandlerResult { - log(format!("disposing dynamic library")); - - let addr = get_int_param(ctx); - unsafe { - std::mem::drop(Box::from_raw(addr as *mut libloading::Library)); - } - HandlerResult::CONTINUE -} - -/// https://library.sannybuilder.com/#/unknown_x86/dylib/GET_DYNAMIC_LIBRARY_PROCEDURE -pub extern "C" fn find_procedure(ctx: Context) -> HandlerResult { - let symbol = get_string_param(ctx); - let lib = get_int_param(ctx) as *mut libloading::Library; - - unsafe { - let addr = lib - .as_mut() - .and_then(|lib| lib.get::(symbol.as_bytes()).ok()) - .and_then(|addr| Some(*addr as isize)) - .unwrap_or(0); - - set_int_param(ctx, addr); - update_compare_flag(ctx, addr > 0); - } - HandlerResult::CONTINUE -} diff --git a/plugins/Dylib/src/lib.rs b/plugins/Dylib/src/lib.rs deleted file mode 100644 index 4374752..0000000 --- a/plugins/Dylib/src/lib.rs +++ /dev/null @@ -1,19 +0,0 @@ -use ctor::*; - -#[cfg_attr(target_arch = "x86", link(name = "cleo_redux"))] -#[cfg_attr(target_arch = "x86_64", link(name = "cleo_redux64"))] -extern crate cleo_redux_sdk; - -mod r#impl; - -#[ctor] -fn init() { - use cleo_redux_sdk::{log, register_command}; - use r#impl::{find_procedure, free_dynamic_library, load_dynamic_library}; - - log("Dylib plugin 1.1"); - - register_command("LOAD_DYNAMIC_LIBRARY", load_dynamic_library, Some("dll")); - register_command("FREE_DYNAMIC_LIBRARY", free_dynamic_library, Some("dll")); - register_command("GET_DYNAMIC_LIBRARY_PROCEDURE", find_procedure, Some("dll")); -}