From 183670d5759e22107b21b1f971b9e9cc54adc4c4 Mon Sep 17 00:00:00 2001 From: Octavian Dima Date: Tue, 20 Apr 2021 18:36:58 +0300 Subject: [PATCH] Initial commit --- .clang-format | 36 ++ .editorconfig | 17 + .gitattributes | 2 + .github/workflows/build.yml | 23 ++ .gitignore | 365 ++++++++++++++++++ .gitmodules | 3 + LICENSE.md | 21 + README.md | 22 ++ RED4ext.Example.VisualStudio.sln | 25 ++ deps/red4ext.sdk | 1 + src/Main.cpp | 63 +++ src/RED4ext.Example.VisualStudio.vcxproj | 94 +++++ ...D4ext.Example.VisualStudio.vcxproj.filters | 6 + 13 files changed, 678 insertions(+) create mode 100644 .clang-format create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 RED4ext.Example.VisualStudio.sln create mode 160000 deps/red4ext.sdk create mode 100644 src/Main.cpp create mode 100644 src/RED4ext.Example.VisualStudio.vcxproj create mode 100644 src/RED4ext.Example.VisualStudio.vcxproj.filters diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..75ae89c --- /dev/null +++ b/.clang-format @@ -0,0 +1,36 @@ +--- +BasedOnStyle: Microsoft +--- +Language: Cpp + +AccessModifierOffset: -4 +AlwaysBreakTemplateDeclarations: Yes +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +KeepEmptyLinesAtTheStartOfBlocks: false +PointerAlignment: Left +SpaceAfterTemplateKeyword: false + +IncludeCategories: + - Regex: 'stdafx' + Priority: -1 + - Regex: 'Windows' + Priority: 0 + +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..83b5fd6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +indent_style = space + +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{c,h,cpp,hpp}] +indent_size = 4 + +[*.md] +indent_size = 2 + +[*.yml] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9de4d3c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,23 @@ +name: Build Workflow +on: [ push, pull_request ] + +jobs: + build: + name: Build (${{ matrix.config }}) + runs-on: windows-latest + + strategy: + matrix: + config: [ Debug, Release ] + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Build + run: MSBuild.exe RED4ext.Example.VisualStudio.sln -v:minimal -m -property:Configuration=${{ matrix.config }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aab9f63 --- /dev/null +++ b/.gitignore @@ -0,0 +1,365 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +### Custom ### +build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..96f8087 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/red4ext.sdk"] + path = deps/red4ext.sdk + url = https://github.com/WopsS/RED4ext.SDK.git diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0685cf3 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 - present Octavian Dima + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3575c35 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# RED4ext.Example using Visual Studio + +An example of a RED4ext plugin using Visual Studio. + +## Build instructions + +### Steps + +1. Download and install [Visual Studio 2019 Community Edition](https://www.visualstudio.com/) or a higher version. +2. Clone this repository. +3. Clone the dependencies (`git submodule update --init --recursive`). +4. Open the solution (**RED4ext.Example.VisualStudio.sln**). +5. Build the project (the artifacts are located in `build/{debug|release}` directory). + +**Notes**: + +* The plugin has to be a 64-bit library. That means all required libraries have to be compiled in 64-bit and the compiler has to support 64-bit. +* Make sure you have the latest SDK by updating it using the following commands: + * `cd deps/red4ext.sdk` + * `git pull` / `git fetch` + * `git checkout master` +* You can also generate the projects from command line, see the **build.yml** in **.github/workflows/build.yml**. diff --git a/RED4ext.Example.VisualStudio.sln b/RED4ext.Example.VisualStudio.sln new file mode 100644 index 0000000..a359eac --- /dev/null +++ b/RED4ext.Example.VisualStudio.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RED4ext.Example.VisualStudio", "src\RED4ext.Example.VisualStudio.vcxproj", "{8A72E3B4-B773-416F-AA0C-FCBEE424AF09}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A72E3B4-B773-416F-AA0C-FCBEE424AF09}.Debug|x64.ActiveCfg = Debug|x64 + {8A72E3B4-B773-416F-AA0C-FCBEE424AF09}.Debug|x64.Build.0 = Debug|x64 + {8A72E3B4-B773-416F-AA0C-FCBEE424AF09}.Release|x64.ActiveCfg = Release|x64 + {8A72E3B4-B773-416F-AA0C-FCBEE424AF09}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ACC1B1F1-63A2-4218-BF1F-6A030016847A} + EndGlobalSection +EndGlobal diff --git a/deps/red4ext.sdk b/deps/red4ext.sdk new file mode 160000 index 0000000..16ef2ff --- /dev/null +++ b/deps/red4ext.sdk @@ -0,0 +1 @@ +Subproject commit 16ef2ff0332c66876cf8baa41f06d8bcdac105d5 diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..768bff8 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,63 @@ +#include + +RED4EXT_C_EXPORT bool RED4EXT_CALL Load(RED4ext::PluginHandle aHandle, const RED4ext::IRED4ext* aInterface) +{ + /* + * Here you can register your custom functions, initalize variable, create hooks and so on. All hooks created here + * will be attached automatically later, you do not need to attach them manually. + * + * Be sure to store the plugin handle and the interface because you cannot get it again later. The plugin handle is + * what identify your plugin through the extender. + * + * Returning "true" in this function loads the plugin, returning "false" will unload it and "Unload" will be called. + */ + return true; +} + +RED4EXT_C_EXPORT void RED4EXT_CALL PostLoad() +{ + /* + * This function is called after all plugins are loaded. Use this to get interfaces to plugins you depends on. + */ +} + +RED4EXT_C_EXPORT void RED4EXT_CALL Unload() +{ + /* + * Here you can free resources you allocated during initalization or during the time your plugin was executed. + * + * Tis function is called when the game is closed or when "Load" returns false. + */ +} + +RED4EXT_C_EXPORT void RED4EXT_CALL Query(RED4ext::PluginInfo* aInfo) +{ + /* + * This function supply the necessary information about your plugin, like name, version, support runtime and SDK. DO + * NOT do anything here yet! + * + * You MUST have this function! + * + * Make sure to fill all of the fields here in order to load your plugin correctly. + * + * Runtime version is the game's version, it is best to let it set to "RED4EXT_RUNTIME_LATEST" if you want to target + * the latest game's version that the SDK defined, if the runtime version specified here and the game's version do + * not match, your plugin will not be loaded. If you want to use RED4ext only as a loader and you do not care about + * game's version use "RED4EXT_RUNTIME_INDEPENDENT". + */ + + aInfo->name = L"RED4ext.Example.VisualStudio"; + aInfo->author = L"WopsS"; + aInfo->version = RED4EXT_SEMVER(1, 0, 0); + aInfo->runtime = RED4EXT_RUNTIME_LATEST; + aInfo->sdk = RED4EXT_SDK_LATEST; +} + +RED4EXT_C_EXPORT uint32_t RED4EXT_CALL Supports() +{ + /* + * This functions returns only what API version is support by your plugins. + * You MUST have this function! + */ + return RED4EXT_API_VERSION_LATEST; +} diff --git a/src/RED4ext.Example.VisualStudio.vcxproj b/src/RED4ext.Example.VisualStudio.vcxproj new file mode 100644 index 0000000..6420f94 --- /dev/null +++ b/src/RED4ext.Example.VisualStudio.vcxproj @@ -0,0 +1,94 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {8a72e3b4-b773-416f-aa0c-fcbee424af09} + RED4extExampleVisualStudio + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + true + $(SolutionDir)\build\debug\bin\ + ../deps/red4ext.sdk/include;$(IncludePath) + + + false + $(SolutionDir)\build\release\bin\ + ../deps/red4ext.sdk/include;$(IncludePath) + + + + Level3 + true + _DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + false + + + + + Level3 + true + true + true + NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + true + true + false + + + + + + + + + \ No newline at end of file diff --git a/src/RED4ext.Example.VisualStudio.vcxproj.filters b/src/RED4ext.Example.VisualStudio.vcxproj.filters new file mode 100644 index 0000000..d3e9077 --- /dev/null +++ b/src/RED4ext.Example.VisualStudio.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file