commit 9cf53a49249df1a84eefc3e66cbd581bf11b2b9c Author: cosmonaut Date: Sun Apr 4 14:01:40 2021 -0700 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae88792 --- /dev/null +++ b/.gitignore @@ -0,0 +1,353 @@ +## 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 + +moonlibs/ + +# 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/ +[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/ + +# 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, .xml, .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/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8e2c264 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,46 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Framework Debugger", + "type": "clr", + "request": "launch", + "preLaunchTask": "Build: Framework Debug", + "program": "${workspaceFolder}/ProjectName/bin/Debug/x64/net472/ProjectName.exe", + "args": [], + "cwd": "${workspaceFolder}/ProjectName/bin/Debug/x64/net472", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Attach to Mono Debugger", + "type": "mono", + "request": "launch", + "preLaunchTask": "Build: Mono Debug", + "program": "${workspaceFolder}/ProjectName/bin/Debug/x64/net472/ProjectName.exe", + "args": [], + "env": { + "LD_LIBRARY_PATH": "${workspaceFolder}/ProjectName/bin/x64/Debug/net472/lib64", + "DYLD_LIBRARY_PATH": "${workspaceFolder}/ProjectName/bin/x64/Debug/net472/osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/Debug/x64/net472", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "name": "Attach to .NET 5 Debugger", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build: .NET 5 Debug", + "program": "${workspaceFolder}/ProjectName/bin/Debug/net5.0/ProjectName.dll", + "args": [], + "env": { + "LD_LIBRARY_PATH": "${workspaceFolder}/ProjectName/bin/Debug/net5.0/lib64", + "DYLD_LIBRARY_PATH": "${workspaceFolder}/ProjectName/bin/Debug/net5.0/osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/Debug/net5.0", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..1a2cfc1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,312 @@ +{ + "version": "2.0.0", + "options": { + "cwd": "${workspaceRoot}" + }, + "windows": { + "options": { + "shell": { + "executable": "cmd.exe", + "args": [ + "/d", + "/c" + ] + } + } + }, + "presentation": { + "reveal": "always", + "focus": true, + "panel": "shared" + }, + "tasks": [ + { + "label": "Build: Mono Release", + "command": "msbuild", + "args": [ + "-restore:True", + "${workspaceFolder}/ProjectName.Framework.sln", + "-p:Configuration=Release", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$msCompile" + }, + { + "label": "Run: Mono Release", + "command": "mono", + "args": [ + "ProjectName.exe" + ], + "options": { + "env": { + "LD_LIBRARY_PATH": "./lib64", + "DYLD_LIBRARY_PATH": "./osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Release/net472" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: Mono Release", + "dependsOn": [ + "Build: Mono Release", + "Run: Mono Release" + ], + "dependsOrder": "sequence", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build: Mono Debug", + "command": "msbuild", + "args": [ + "-restore:True", + "${workspaceFolder}/ProjectName.Framework.sln", + "-p:Configuration=Debug", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Run: Mono Debug", + "command": "mono", + "args": [ + "ProjectName.exe" + ], + "options": { + "env": { + "LD_LIBRARY_PATH": "./lib64", + "DYLD_LIBRARY_PATH": "./osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Debug/net472" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: Mono Debug", + "dependsOn": [ + "Build: Mono Debug", + "Run: Mono Debug" + ], + "dependsOrder": "sequence", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: .NET 5 Debug", + "type": "shell", + "dependsOrder": "sequence", + "dependsOn": [ + "Build: .NET 5 Debug", + "Run: .NET 5 Debug" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build: .NET 5 Debug", + "command": "dotnet", + "args": [ + "build", + "./ProjectName/ProjectName.Core.csproj", + "-p:SolutionDir=${workspaceFolder}/", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Run: .NET 5 Debug", + "command": "dotnet", + "args": [ + "./ProjectName.dll" + ], + "options": { + "env": { + "LD_LIBRARY_PATH": "./lib64", + "DYLD_LIBRARY_PATH": "./osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Debug/net5.0" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build: .NET 5 Release", + "command": "dotnet", + "args": [ + "build", + "./ProjectName/ProjectName.Core.csproj", + "--configuration", + "Release", + "-p:SolutionDir=${workspaceFolder}/", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Run: .NET 5 Release", + "command": "dotnet", + "args": [ + "./ProjectName.dll" + ], + "options": { + "env": { + "LD_LIBRARY_PATH": "./lib64", + "DYLD_LIBRARY_PATH": "./osx" + }, + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Release/net5.0" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: .NET 5 Release", + "dependsOrder": "sequence", + "dependsOn": [ + "Build: .NET 5 Release", + "Run: .NET 5 Release" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build: Framework Debug", + "command": "MsBuild.exe", + "args": [ + "-restore:True", + "${workspaceFolder}/ProjectName.Framework.sln", + "-p:Configuration=Debug", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Run: Framework Debug", + "command": "ProjectName.exe", + "options": { + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Debug/net472" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: Framework Debug", + "dependsOn": [ + "Build: Framework Debug", + "Run: Framework Debug" + ], + "dependsOrder": "sequence", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build: Framework Release", + "command": "MsBuild.exe", + "args": [ + "-restore:True", + "${workspaceFolder}/ProjectName.Framework.sln", + "-p:Configuration=Release", + "-p:Platform=x64" + ], + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Run: Framework Release", + "command": "ProjectName.exe", + "options": { + "cwd": "${workspaceFolder}/ProjectName/bin/x64/Release/net472" + }, + "type": "process", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Build & Run: Framework Release", + "dependsOn": [ + "Build: Framework Release", + "Run: Framework Release" + ], + "dependsOrder": "sequence", + "type": "shell", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + } + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6b2ad2d --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2021 Evan Hemsley + +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/ProjectName.Core.sln b/ProjectName.Core.sln new file mode 100644 index 0000000..1800f4f --- /dev/null +++ b/ProjectName.Core.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectName.Core", "ProjectName\ProjectName.Core.csproj", "{4589302C-174A-4173-9654-CAA6CA1B5220}" +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 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x64.ActiveCfg = Debug|x64 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x64.Build.0 = Debug|x64 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x86.ActiveCfg = Debug|x86 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Debug|x86.Build.0 = Debug|x86 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x64.ActiveCfg = Release|x64 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x64.Build.0 = Release|x64 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x86.ActiveCfg = Release|x86 + {4589302C-174A-4173-9654-CAA6CA1B5220}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {70247DA8-9C19-4FC5-B4BC-68E1262B9F4B} + EndGlobalSection +EndGlobal diff --git a/ProjectName.Framework.sln b/ProjectName.Framework.sln new file mode 100644 index 0000000..bebd481 --- /dev/null +++ b/ProjectName.Framework.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectName.Framework", "ProjectName\ProjectName.Framework.csproj", "{9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}" +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 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x64.ActiveCfg = Debug|x64 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x64.Build.0 = Debug|x64 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x86.ActiveCfg = Debug|x86 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Debug|x86.Build.0 = Debug|x86 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x64.ActiveCfg = Release|x64 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x64.Build.0 = Release|x64 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x86.ActiveCfg = Release|x86 + {9ED076FA-32C3-4F1E-BB90-549B3A2FA46F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4DB7BE1E-CAC6-4275-B514-20CBE80F794F} + EndGlobalSection +EndGlobal diff --git a/ProjectName/Content/README.md b/ProjectName/Content/README.md new file mode 100644 index 0000000..d05e474 --- /dev/null +++ b/ProjectName/Content/README.md @@ -0,0 +1 @@ +Insert your content files here (sprites, sound, etc) diff --git a/ProjectName/CopyMoonlibs.targets b/ProjectName/CopyMoonlibs.targets new file mode 100644 index 0000000..632dcb4 --- /dev/null +++ b/ProjectName/CopyMoonlibs.targets @@ -0,0 +1,63 @@ + + + + + + + + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + + %(RecursiveDir)%(Filename)%(Extension) + PreserveNewest + + + + diff --git a/ProjectName/DllMap.cs b/ProjectName/DllMap.cs new file mode 100644 index 0000000..a426f32 --- /dev/null +++ b/ProjectName/DllMap.cs @@ -0,0 +1,259 @@ +// only works in .NET Core. disable in .NET framework + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Xml.Linq; + +public static class DllMap +{ + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDefaultDllDirectories(int directoryFlags); + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + static extern void AddDllDirectory(string lpPathName); + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDllDirectory(string lpPathName); + + const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000; + + public static Dictionary MapDictionary; + public static string OS; + public static string CPU; + public static bool Optimise; + + public static void Initialise(bool optimise = true) + { + Optimise = optimise; + + // Our executabe needs to know how to find the native libraries + // For Windows, we can set this to be x86 or x64 directory at runtime (below) + // For Linux we need to move our native libraries to 'netcoredeps' which is set by .net core + // For OSX we need to set an environment variable (DYLD_LIBRARY_PATH) outside of the process by a script + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + try + { + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + AddDllDirectory(Path.Combine( + AppDomain.CurrentDomain.BaseDirectory, + Environment.Is64BitProcess ? "x64" : "x86" + )); + } + catch + { + // Pre-Windows 7, KB2533623 + SetDllDirectory(Path.Combine( + AppDomain.CurrentDomain.BaseDirectory, + Environment.Is64BitProcess ? "x64" : "x86" + )); + } + } + + // .NET Core also doesn't use DllImport but we can replicate this using NativeLibrary as per below + // Uses MoonWorks.dll.config to dictate what the name of the native library is per platform and architecture + var moonWorksAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels)); + DllMap.Register(moonWorksAssembly); + } + + // Register a call-back for native library resolution. + public static void Register(Assembly assembly) + { + NativeLibrary.SetDllImportResolver(assembly, MapAndLoad); + + // Do setup so that MapLibraryName is faster than reading the XML each time + + // 1) Get platform & cpu + OS = GetCurrentPlatform().ToString().ToLowerInvariant(); + CPU = GetCurrentRuntimeArchitecture().ToString().ToLowerInvariant(); + + // 2) Setup MapDictionary + // For Windows use hardcoded values + // Why? This is our development platform and we wanted the fastest start time possible (eliminates XML Load) + if (OS == "windows" && Optimise) + { + MapDictionary = new Dictionary(); + MapDictionary.Add("SDL2", "SDL2.dll"); + MapDictionary.Add("Refresh", "Refresh.dll"); + MapDictionary.Add("FAudio", "FAudio.dll"); + } + else + { + // For every other platform use XML file + // Read in config XML and only store details we're interested in within MapDictionary + string xmlPath = Path.Combine(Path.GetDirectoryName(assembly.Location), + Path.GetFileNameWithoutExtension(assembly.Location) + ".dll.config"); + + if (!File.Exists(xmlPath)) + { + Console.WriteLine($"=== Cannot find XML: " + xmlPath); + return; + } + + XElement root = XElement.Load(xmlPath); + + MapDictionary = new Dictionary(); + ParseXml(root, true); // Direct match on OS & CPU first + ParseXml(root, false); // Loose match on CPU second (won't allow duplicates) + } + } + + private static void ParseXml(XElement root, bool matchCPU) + { + foreach (var el in root.Elements("dllmap")) + { + // Ignore entries for other OSs + if (el.Attribute("os").ToString().IndexOf(OS) < 0) + continue; + + // Ignore entries for other CPUs + if (matchCPU) + { + if (el.Attribute("cpu") == null) + continue; + if (el.Attribute("cpu").ToString().IndexOf(CPU) < 0) + continue; + } + else + { + if (el.Attribute("cpu") != null && el.Attribute("cpu").ToString().IndexOf(CPU) < 0) + continue; + } + + string oldLib = el.Attribute("dll").Value; + string newLib = el.Attribute("target").Value; + if (string.IsNullOrWhiteSpace(oldLib) || string.IsNullOrWhiteSpace(newLib)) + continue; + + // Don't allow duplicates + if (MapDictionary.ContainsKey(oldLib)) + continue; + + MapDictionary.Add(oldLib, newLib); + } + } + + // The callback: which loads the mapped libray in place of the original + private static IntPtr MapAndLoad(string libraryName, Assembly assembly, DllImportSearchPath? dllImportSearchPath) + { + string mappedName = null; + mappedName = MapLibraryName(assembly.Location, libraryName, out mappedName) ? mappedName : libraryName; + return NativeLibrary.Load(mappedName, assembly, dllImportSearchPath); + } + + // Parse the assembly.xml file, and map the old name to the new name of a library. + private static bool MapLibraryName(string assemblyLocation, string originalLibName, out string mappedLibName) + { + if (MapDictionary.TryGetValue(originalLibName, out mappedLibName)) + return true; + else + return false; + } + + // Below pinched from Mono.DllMap project: https://github.com/Firwood-Software/AdvancedDLSupport/tree/1b7394211a655b2f77649ce3b610a3161215cbdc/Mono.DllMap + public static DllMapOS GetCurrentPlatform() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return DllMapOS.Linux; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return DllMapOS.Windows; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return DllMapOS.OSX; + } + + var operatingDesc = RuntimeInformation.OSDescription.ToUpperInvariant(); + foreach (var system in Enum.GetValues(typeof(DllMapOS)).Cast() + .Except(new[] { DllMapOS.Linux, DllMapOS.Windows, DllMapOS.OSX })) + { + if (operatingDesc.Contains(system.ToString().ToUpperInvariant())) + { + return system; + } + } + + throw new PlatformNotSupportedException($"Couldn't detect platform: {RuntimeInformation.OSDescription}"); + } + + public static DllMapArchitecture GetCurrentRuntimeArchitecture() + { + switch (RuntimeInformation.ProcessArchitecture) + { + case Architecture.Arm: + { + return DllMapArchitecture.ARM; + } + case Architecture.X64: + { + return DllMapArchitecture.x86_64; + } + case Architecture.X86: + { + return DllMapArchitecture.x86; + } + } + + typeof(object).Module.GetPEKind(out _, out var machine); + switch (machine) + { + case ImageFileMachine.I386: + { + return DllMapArchitecture.x86; + } + case ImageFileMachine.AMD64: + { + return DllMapArchitecture.x86_64; + } + case ImageFileMachine.ARM: + { + return DllMapArchitecture.ARM; + } + case ImageFileMachine.IA64: + { + return DllMapArchitecture.IA64; + } + } + throw new PlatformNotSupportedException("Couldn't detect the current architecture."); + } + + public enum DllMapOS + { + Linux = 1 << 0, + OSX = 1 << 1, + Solaris = 1 << 2, + FreeBSD = 1 << 3, + OpenBSD = 1 << 4, + NetBSD = 1 << 5, + Windows = 1 << 6, + AIX = 1 << 7, + HPUX = 1 << 8 + } + + public enum DllMapArchitecture + { + x86 = 1 << 0, + x86_64 = 1 << 1, + SPARC = 1 << 2, + PPC = 1 << 3, + S390 = 1 << 4, + S390X = 1 << 5, + ARM = 1 << 6, + ARMV8 = 1 << 7, + MIPS = 1 << 8, + Alpha = 1 << 9, + HPPA = 1 << 10, + IA64 = 1 << 11 + } +} diff --git a/ProjectName/Graphics/Containers/Framebuffers.cs b/ProjectName/Graphics/Containers/Framebuffers.cs new file mode 100644 index 0000000..17d21b3 --- /dev/null +++ b/ProjectName/Graphics/Containers/Framebuffers.cs @@ -0,0 +1,26 @@ +using MoonWorks.Graphics; + +namespace ProjectName.Graphics +{ + public class Framebuffers + { + public Framebuffer ExampleFramebuffer { get; } + + public Framebuffers( + GraphicsDevice graphicsDevice, + RenderPasses renderPasses, + RenderTargets renderTargets, + uint renderDimensionsX, + uint renderDimensionsY + ) { + ExampleFramebuffer = new Framebuffer( + graphicsDevice, + renderDimensionsX, + renderDimensionsY, + renderPasses.ExampleRenderPass, + null, + renderTargets.ExampleRenderTarget + ); + } + } +} \ No newline at end of file diff --git a/ProjectName/Graphics/Containers/RenderPasses.cs b/ProjectName/Graphics/Containers/RenderPasses.cs new file mode 100644 index 0000000..0b7e749 --- /dev/null +++ b/ProjectName/Graphics/Containers/RenderPasses.cs @@ -0,0 +1,24 @@ +using MoonWorks.Graphics; + +namespace ProjectName.Graphics +{ + public class RenderPasses + { + public RenderPass ExampleRenderPass { get; } + public RenderPasses(GraphicsDevice graphicsDevice) + { + var clearPassDescription = new ColorTargetDescription + { + Format = TextureFormat.R8G8B8A8, + LoadOp = LoadOp.Clear, + StoreOp = StoreOp.Store, + MultisampleCount = SampleCount.One + }; + + ExampleRenderPass = new RenderPass( + graphicsDevice, + clearPassDescription + ); + } + } +} \ No newline at end of file diff --git a/ProjectName/Graphics/Containers/RenderTargets.cs b/ProjectName/Graphics/Containers/RenderTargets.cs new file mode 100644 index 0000000..5eee4c6 --- /dev/null +++ b/ProjectName/Graphics/Containers/RenderTargets.cs @@ -0,0 +1,23 @@ +using MoonWorks.Graphics; + +namespace ProjectName.Graphics +{ + public class RenderTargets + { + public RenderTarget ExampleRenderTarget { get; } + + public RenderTargets( + GraphicsDevice graphicsDevice, + uint renderDimensionsX, + uint renderDimensionsY + ) { + ExampleRenderTarget = RenderTarget.CreateBackedRenderTarget( + graphicsDevice, + renderDimensionsX, + renderDimensionsY, + TextureFormat.R8G8B8A8, + false + ); + } + } +} diff --git a/ProjectName/Graphics/GraphicsObjects.cs b/ProjectName/Graphics/GraphicsObjects.cs new file mode 100644 index 0000000..309e083 --- /dev/null +++ b/ProjectName/Graphics/GraphicsObjects.cs @@ -0,0 +1,31 @@ +using MoonWorks.Graphics; + +namespace ProjectName.Graphics +{ + public class GraphicsObjects + { + public RenderTargets RenderTargets { get; } + public Framebuffers Framebuffers { get; } + public RenderPasses RenderPasses { get; } + + public GraphicsObjects( + GraphicsDevice graphicsDevice, + uint renderDimensionsX, + uint renderDimensionsY + ) { + RenderPasses = new RenderPasses(graphicsDevice); + RenderTargets = new RenderTargets( + graphicsDevice, + renderDimensionsX, + renderDimensionsY + ); + Framebuffers = new Framebuffers( + graphicsDevice, + RenderPasses, + RenderTargets, + renderDimensionsX, + renderDimensionsY + ); + } + } +} diff --git a/ProjectName/Program.cs b/ProjectName/Program.cs new file mode 100644 index 0000000..e133104 --- /dev/null +++ b/ProjectName/Program.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +using MoonWorks; +using MoonWorks.Window; + +namespace ProjectName +{ + class Program + { + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDllDirectory(string lpPathName); + + + static void Main(string[] args) + { +#if NETCOREAPP + DllMap.Initialise(false); +#endif + + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + SetDllDirectory(Path.Combine( + AppDomain.CurrentDomain.BaseDirectory, + Environment.Is64BitProcess ? "x64" : "x86" + )); + } + + WindowCreateInfo windowCreateInfo = new WindowCreateInfo + { + WindowWidth = 1280, + WindowHeight = 720, + WindowTitle = "ProjectName", + ScreenMode = ScreenMode.Windowed + }; + + ProjectNameGame game = new ProjectNameGame( + windowCreateInfo, + MoonWorks.Graphics.PresentMode.FIFORelaxed, + true + ); + + game.Run(); + } + } +} \ No newline at end of file diff --git a/ProjectName/ProjectName.Core.csproj b/ProjectName/ProjectName.Core.csproj new file mode 100644 index 0000000..d450a0d --- /dev/null +++ b/ProjectName/ProjectName.Core.csproj @@ -0,0 +1,31 @@ + + + obj\$(MSBuildProjectName) + x64;x86 + + + + WinExe + net5.0 + ProjectName + false + false + 8.0 + ProjectName.Program + ProjectName + ProjectName + true + true + + + + + Always + + + + + + + + diff --git a/ProjectName/ProjectName.Framework.csproj b/ProjectName/ProjectName.Framework.csproj new file mode 100644 index 0000000..f9907d5 --- /dev/null +++ b/ProjectName/ProjectName.Framework.csproj @@ -0,0 +1,34 @@ + + + obj\$(MSBuildProjectName) + x64;x86 + + + + Exe + net472 + ProjectName + false + false + 8.0 + ProjectName.Program + ProjectName + ProjectName + true + true + + + + $(DefaultItemExcludes);DllMap.cs + + + + Always + + + + + + + + diff --git a/ProjectName/ProjectNameGame.cs b/ProjectName/ProjectNameGame.cs new file mode 100644 index 0000000..0ce3a0b --- /dev/null +++ b/ProjectName/ProjectNameGame.cs @@ -0,0 +1,63 @@ +using MoonWorks.Graphics; +using MoonWorks.Window; +using MoonWorks; +using ProjectName.Graphics; + +namespace ProjectName +{ + class ProjectNameGame : Game + { + private GraphicsObjects GraphicsObjects { get; } + + private int RenderWidth { get; } + private int RenderHeight { get; } + + public ProjectNameGame( + WindowCreateInfo windowCreateInfo, + PresentMode presentMode, + bool debugMode + ) : base(windowCreateInfo, presentMode, 60, debugMode) + { + // Insert your game initialization logic here. + GraphicsObjects = new GraphicsObjects( + GraphicsDevice, + windowCreateInfo.WindowWidth, + windowCreateInfo.WindowHeight + ); + RenderWidth = (int)windowCreateInfo.WindowWidth; + RenderHeight = (int)windowCreateInfo.WindowHeight; + } + + protected override void Update(double dt) + { + // Insert your game update logic here. + } + + protected override void Draw(double dt, double alpha) + { + // Replace this with your own drawing code. + + var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); + + commandBuffer.BeginRenderPass( + GraphicsObjects.RenderPasses.ExampleRenderPass, + GraphicsObjects.Framebuffers.ExampleFramebuffer, + new Rect + { + X = 0, + Y = 0, + W = RenderWidth, + H = RenderHeight + }, + Color.CornflowerBlue.ToVector4() + ); + + commandBuffer.QueuePresent( + GraphicsObjects.RenderTargets.ExampleRenderTarget.TextureSlice, + Filter.Nearest + ); + + GraphicsDevice.Submit(commandBuffer); + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd3a43e --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# MoonWorksTemplate + +Template and build tasks for developing a cross-platform multi-target .NET Framework, Mono, and .NET 5 MoonWorks project in VSCode. + +The generated solution file will also work in regular Visual Studio. + +## Features + +- Includes project boilerplate code +- Build tasks for both .NET Framework, Mono, and .NET 5 side by side +- VSCode debugger integration + +## Requirements + +- [Git](https://git-scm.com/) or [Git for Windows](https://gitforwindows.org/) on Windows +- [.NET 5 SDK](https://dotnet.microsoft.com/download/dotnet/5.0) +- [.NET Framework 4.7.2 Developer Pack](https://dotnet.microsoft.com/download/dotnet-framework/net472) on Windows +- [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) on Windows +- [Mono](https://www.mono-project.com/) on OSX or Linux +- [Visual Studio Code](https://code.visualstudio.com/) +- [VSCode C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) +- [VSCode Mono Debug Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) if debugging using Mono + +## Installation + +- Make sure you have Git Bash from Git for Windows if you are on Windows +- Download this repository +- Run `install.sh` +- Move the newly created project directory wherever you want +- On Windows, add `C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin` to your system environment PATH variable after installing Build Tools for VS 2019 + +## Usage + +- Open the project directory in VSCode +- Press Ctrl-Shift-B to open the build tasks menu +- `Framework` tasks use .NET Framework to build and run (Windows only) +- `Mono` tasks use Mono to build and run +- `5` tasks use .NET 5 to build and run +- Press F5 to build and debug + +## Acknowledgments + +Thanks to Andrew Russell and Caleb Cornett's FNA templates for a starting point for this template. diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..e0f2067 --- /dev/null +++ b/install.sh @@ -0,0 +1,119 @@ +#!/bin/bash +# Author: Evan Hemsley +# Usage: ./install.sh + +# This file is heavily borrowed from Caleb Cornett's template install script. + +# Get the directory of this script +MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MOONWORKS_VERSION=0.1.0 + +readlinkf(){ perl -MCwd -e 'print Cwd::abs_path shift' "$1";} + +# Checks if git is installed +function checkGit() +{ + git --version > /dev/null 2>&1 + if [ ! $? -eq 0 ]; then + echo >&2 "ERROR: Git is not installed. Please install git to download MoonWorks." + exit 1 + fi +} + +# Pulls MoonWorks from github +function pullMoonWorks() +{ + checkGit + cd lib + git submodule add https://gitea.moonside.games/MoonsideGames/MoonWorks.git + git checkout $MOONWORKS_VERSION + cd .. + echo "Updating to the latest release of MoonWorks..." + git submodule update --init --recursive + if [ $? -eq 0 ]; then + echo "Finished updating!" + else + echo >&2 "ERROR: Unable to update." + exit 1 + fi +} + +# Downloads and extracts prepackaged archive of native libraries ("moonlibs") +function getLibs() +{ + # Downloading + echo "Downloading latest moonlibs..." + curl http://moonside.games/files/moonlibs.tar.bz2 > "$MY_DIR/moonlibs.tar.bz2" + if [ $? -eq 0 ]; then + echo "Finished downloading!" + else + >&2 echo "ERROR: Unable to download successfully." + exit 1 + fi + + # Decompressing + echo "Decompressing moonlibs..." + mkdir -p "$MY_DIR" + tar xjC "$MY_DIR" -f "$MY_DIR"/moonlibs.tar.bz2 + if [ $? -eq 0 ]; then + echo "Finished decompressing!" + echo "" + rm "$MY_DIR"/moonlibs.tar.bz2 + else + >&2 echo "ERROR: Unable to decompress successfully." + exit 1 + fi +} + +getLibs + +read -p "Enter your project name or 'exit' to quit: " newProjectName +if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then + exit 1 +fi + +NEW_PROJECT_DIR="$MY_DIR/../$newProjectName" + +if [ -d "$NEW_PROJECT_DIR" ]; then + >&2 echo "ERROR: Directory already exists." + exit 1 +fi + +# copy everything into new dir +cp -R "$MY_DIR" "$NEW_PROJECT_DIR" + +cd "$NEW_PROJECT_DIR" +files=(ProjectName.Core.sln ProjectName.Framework.sln .gitignore ProjectName/ProjectName.Core.csproj ProjectName/ProjectName.Framework.csproj ProjectName/ProjectNameGame.cs ProjectName/Program.cs ProjectName/Graphics/GraphicsObjects.cs ProjectName/Graphics/Containers/Framebuffers.cs ProjectName/Graphics/Containers/RenderPasses.cs ProjectName/Graphics/Containers/RenderTargets.cs .vscode/tasks.json .vscode/launch.json) +for file in "${files[@]}"; do + sed -i -e "s/ProjectName/$newProjectName/g" "./$file" + if [ "$(uname)" == "Darwin" ]; then + rm ./${file}-e + fi +done + +mv ./ProjectName.Core.sln "./$newProjectName.Core.sln" +mv ./ProjectName.Framework.sln "./$newProjectName.Framework.sln" +mv ./ProjectName/ProjectName.Core.csproj "./ProjectName/$newProjectName.Core.csproj" +mv ./ProjectName/ProjectName.Framework.csproj "./ProjectName/$newProjectName.Framework.csproj" +mv ./ProjectName/ProjectNameGame.cs ./ProjectName/${newProjectName}Game.cs +mv ./ProjectName "./$newProjectName" +rm ./install.sh +rm ./LICENSE + +rm -rf .git +git init +git branch -m main +mkdir lib +pullMoonWorks + +dotnet sln ${newProjectName}.Framework.sln add lib/MoonWorks/MoonWorks.csproj +dotnet sln ${newProjectName}.Core.sln add lib/MoonWorks/MoonWorks.csproj + +echo "Project $newProjectName created at: " + +if [ "$(uname)" == "Darwin" ]; then + echo $(readlinkf $NEW_PROJECT_DIR) +else + echo $(readlink -f $NEW_PROJECT_DIR) +fi