From 3f0da89d0192f1eaa0834790f04d5eb5d282199c Mon Sep 17 00:00:00 2001 From: NGnius Date: Tue, 22 Oct 2019 16:01:34 -0400 Subject: [PATCH] Reimplement Waypoint functionality --- .gitattributes | 63 ++++ .gitignore | 340 ++++++++++++++++++ .../CommandLineCompositionRootPatch.cs | 55 +++ extracommands/CreateWaypoint.cs | 54 +++ extracommands/CustomCommandAttribute.cs | 17 + extracommands/CustomCommandEngine.cs | 39 ++ extracommands/ExtraCommands.csproj | 55 ++- .../{TestPlugin.cs => ExtraCommandsPlugin.cs} | 14 +- extracommands/TestPatch.cs | 22 -- 9 files changed, 628 insertions(+), 31 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 extracommands/CommandLineCompositionRootPatch.cs create mode 100644 extracommands/CreateWaypoint.cs create mode 100644 extracommands/CustomCommandAttribute.cs create mode 100644 extracommands/CustomCommandEngine.cs rename extracommands/{TestPlugin.cs => ExtraCommandsPlugin.cs} (75%) delete mode 100644 extracommands/TestPatch.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,340 @@ +## 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 + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# 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 + +# 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 + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# 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 +# 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 + +# 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 +*- Backup*.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/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# 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 \ No newline at end of file diff --git a/extracommands/CommandLineCompositionRootPatch.cs b/extracommands/CommandLineCompositionRootPatch.cs new file mode 100644 index 0000000..2b9a804 --- /dev/null +++ b/extracommands/CommandLineCompositionRootPatch.cs @@ -0,0 +1,55 @@ +using System; +using System.Reflection; +using Harmony; +using UnityEngine; +using Unity.Entities; +using RobocraftX; +using RobocraftX.GUI.CommandLine; +using RobocraftX.Multiplayer; +using Svelto.ECS; +using Svelto.Context; + +namespace ExtraCommands +{ + [HarmonyPatch] + class CommandLineCompositionRootPatch + { + static void Postfix(UnityContext contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters) + { + MethodInfo commandHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string), typeof(string) }); + foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes()) + { + CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false); + CustomCommandEngine inst = null; + foreach (CustomCommandAttribute attr in attributes) + { + if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine))) + { + if (inst == null) + { + // create instance by getting the constructor through reflection + inst = (CustomCommandEngine)t.GetConstructor(new Type[] { typeof(UnityContext), typeof(EnginesRoot), typeof(World), typeof(Action), typeof(MultiplayerInitParameters) }) + .Invoke(new object[] { contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters }); + // add to engineRoot + enginesRoot.AddEngine(inst); + } + // add to Gamecraft help command + commandHelp.Invoke(null, new string[] { attr.Name, attr.Description }); + } + } + } + Debug.Log("Postfix"); + } + + [HarmonyTargetMethod] + static MethodBase HTargetMethod(HarmonyInstance instance) + { + return _ComposeMethodInfo(CommandLineCompositionRoot.Compose); + } + + private static MethodInfo _ComposeMethodInfo(Action a) + { + return a.Method; + } + } +} diff --git a/extracommands/CreateWaypoint.cs b/extracommands/CreateWaypoint.cs new file mode 100644 index 0000000..101f718 --- /dev/null +++ b/extracommands/CreateWaypoint.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using RobocraftX.GUI.CommandLine; +using RobocraftX.Multiplayer; +using RobocraftX.StateSync; +using RobocraftX.Character; +using Svelto.ECS; +using Unity.Entities; +using uREPL; +using Svelto.Context; +using RobocraftX; + +namespace ExtraCommands.Waypoints +{ + [CustomCommand("CreateWaypoint", "Create a waypoint in your current location")] + [CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")] + class TeleportWaypointCommandEngine : CustomCommandEngine + { + private Dictionary _waypoints = new Dictionary(); + public TeleportWaypointCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) + { + } + + public override void Ready() + { + uREPL.RuntimeCommands.Register("CreateWaypoint", CreateWaypointCommand); + uREPL.RuntimeCommands.Register("TeleportPlayerWaypoint", TeleportToWaypointCommand); + } + + private void CreateWaypointCommand(object name) + { + ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity(0u, CharacterExclusiveGroups.CharacterGroup); + _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z }; + uREPL.Log.Output("Saved " + name.ToString()); + } + + private void TeleportToWaypointCommand(object name) + { + if (!_waypoints.ContainsKey(name)) + { + uREPL.Log.Error("Waypoint not found"); + return; + } + float[] loc = _waypoints[name]; + uREPL.RuntimeCommands.Call("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]); + } + + public override void Dispose() + { + uREPL.RuntimeCommands.Unregister("CreateWaypoint"); + uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint"); + } + } +} diff --git a/extracommands/CustomCommandAttribute.cs b/extracommands/CustomCommandAttribute.cs new file mode 100644 index 0000000..ecf1a74 --- /dev/null +++ b/extracommands/CustomCommandAttribute.cs @@ -0,0 +1,17 @@ +using System; + +namespace ExtraCommands +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class CustomCommandAttribute: Attribute + { + public string Name { get; protected set; } + + public string Description { get; protected set; } + public CustomCommandAttribute(string name, string description = "") + { + this.Name = name; + this.Description = description; + } + } +} diff --git a/extracommands/CustomCommandEngine.cs b/extracommands/CustomCommandEngine.cs new file mode 100644 index 0000000..ddd1042 --- /dev/null +++ b/extracommands/CustomCommandEngine.cs @@ -0,0 +1,39 @@ +using RobocraftX.GUI.CommandLine; +using RobocraftX.Multiplayer; +using Svelto.Context; +using Svelto.ECS; +using System; +using Unity.Entities; +using RobocraftX; + +namespace ExtraCommands +{ + class CustomCommandEngine : IQueryingEntitiesEngine, IEngine, IDisposable + { + protected UnityContext context; + + protected EnginesRoot enginesRoot; + + protected World physWorld; + + protected Action reloadGame; + + protected MultiplayerInitParameters multiplayerInitParameters; + + public CustomCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) + { + this.context = ctxHolder; + this.enginesRoot = enginesRoot; + this.physWorld = physW; + this.reloadGame = reloadGame; + this.multiplayerInitParameters = mpParams; + } + + public IEntitiesDB entitiesDB { set; get; } + + virtual public void Dispose() { } + + // NOTE: Ready() should call uREPL.RuntimeCommands.Register to add the command to the command line + virtual public void Ready() { } + } +} diff --git a/extracommands/ExtraCommands.csproj b/extracommands/ExtraCommands.csproj index c034e29..e3d5100 100644 --- a/extracommands/ExtraCommands.csproj +++ b/extracommands/ExtraCommands.csproj @@ -9,14 +9,65 @@ + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\CommandLine.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\FullGame.dll + ..\..\..\IPA\IPA\bin\Debug\IPA\Data\Managed\IllusionPlugin.dll + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Character.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.MultiplayerInput.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.StateSync.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Svelto.Common.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Svelto.ECS.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.Hybrid.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.Properties.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.StaticTypeRegistry.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll + - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.dll + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\UnityEngine.dll - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.CoreModule.dll + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\UnityEngine.CoreModule.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\uREPL.dll diff --git a/extracommands/TestPlugin.cs b/extracommands/ExtraCommandsPlugin.cs similarity index 75% rename from extracommands/TestPlugin.cs rename to extracommands/ExtraCommandsPlugin.cs index 07c60ad..2c8af75 100644 --- a/extracommands/TestPlugin.cs +++ b/extracommands/ExtraCommandsPlugin.cs @@ -4,24 +4,24 @@ using UnityEngine; using Harmony; using System.Reflection; -namespace TestMod +namespace ExtraCommands { public class Plugin : IllusionPlugin.IEnhancedPlugin { public static HarmonyInstance harmony { get; protected set; } - public string[] Filter { get; } = new string[] { "RobocraftX", "Gamecraft" }; + public string[] Filter { get; } = new string[] { "RobocraftX", "Gamecraft", "GamecraftPreview" }; - public string Name { get; } = "TestPlugin"; + public string Name { get; } = "ExtraCommands"; - public string Version { get; } = "v0.0.0a"; + public string Version { get; } = "v0.0.1"; - public string HarmonyID { get; } = "org.git.exmods.base.testmod.testplugin"; + public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands"; public void OnApplicationQuit() { harmony.UnpatchAll(HarmonyID); - Debug.Log("TestPlugin shutdown complete"); + Debug.Log("ExtraCommands shutdown & unpatch complete"); } public void OnApplicationStart() @@ -31,7 +31,7 @@ namespace TestMod harmony = HarmonyInstance.Create(HarmonyID); harmony.PatchAll(Assembly.GetExecutingAssembly()); } - Debug.Log("TestPlugin start & patch complete"); + Debug.Log("ExtraCommands start & patch complete"); } public void OnFixedUpdate() diff --git a/extracommands/TestPatch.cs b/extracommands/TestPatch.cs deleted file mode 100644 index c7703d0..0000000 --- a/extracommands/TestPatch.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Reflection; -using Harmony; -using UnityEngine; - -namespace TestMod -{ - [HarmonyPatch] - class TestPatch - { - static void Prefix() - { - Debug.Log("Test Patch Prefix"); - } - - [HarmonyTargetMethod] - static MethodBase HTargetMethod(HarmonyInstance instance) - { - throw new NotImplementedException(); - } - } -}