Browse Source

Reimplement Waypoint functionality

tags/v0.0.1
NGnius 5 years ago
parent
commit
3f0da89d01
9 changed files with 628 additions and 31 deletions
  1. +63
    -0
      .gitattributes
  2. +340
    -0
      .gitignore
  3. +55
    -0
      extracommands/CommandLineCompositionRootPatch.cs
  4. +54
    -0
      extracommands/CreateWaypoint.cs
  5. +17
    -0
      extracommands/CustomCommandAttribute.cs
  6. +39
    -0
      extracommands/CustomCommandEngine.cs
  7. +53
    -2
      extracommands/ExtraCommands.csproj
  8. +7
    -7
      extracommands/ExtraCommandsPlugin.cs
  9. +0
    -22
      extracommands/TestPatch.cs

+ 63
- 0
.gitattributes View File

@@ -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

+ 340
- 0
.gitignore View File

@@ -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

+ 55
- 0
extracommands/CommandLineCompositionRootPatch.cs View File

@@ -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<FullGameCompositionRoot> 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<FullGameCompositionRoot>), 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<CommandLineContext>);
}

private static MethodInfo _ComposeMethodInfo(Action<CommandLineContext, EnginesRoot, World, Action, MultiplayerInitParameters> a)
{
return a.Method;
}
}
}

+ 54
- 0
extracommands/CreateWaypoint.cs View File

@@ -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<object, float[]> _waypoints = new Dictionary<object, float[]>();
public TeleportWaypointCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
{
}

public override void Ready()
{
uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand);
uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand);
}

private void CreateWaypointCommand(object name)
{
ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(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<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
}

public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("CreateWaypoint");
uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint");
}
}
}

+ 17
- 0
extracommands/CustomCommandAttribute.cs View File

@@ -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;
}
}
}

+ 39
- 0
extracommands/CustomCommandEngine.cs View File

@@ -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<FullGameCompositionRoot> context;

protected EnginesRoot enginesRoot;

protected World physWorld;

protected Action reloadGame;

protected MultiplayerInitParameters multiplayerInitParameters;

public CustomCommandEngine(UnityContext<FullGameCompositionRoot> 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() { }
}
}

+ 53
- 2
extracommands/ExtraCommands.csproj View File

@@ -9,14 +9,65 @@
</ItemGroup>

<ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\CommandLine.dll</HintPath>
</Reference>
<Reference Include="FullGame">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\FullGame.dll</HintPath>
</Reference>
<Reference Include="IllusionPlugin">
<HintPath>..\..\..\IPA\IPA\bin\Debug\IPA\Data\Managed\IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Character">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Character.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Multiplayer">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Multiplayer.NetworkEntityStream">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MultiplayerInput">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.MultiplayerInput.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.StateSync">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\RobocraftX.StateSync.dll</HintPath>
</Reference>
<Reference Include="Svelto.Common">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Svelto.Common.dll</HintPath>
</Reference>
<Reference Include="Svelto.ECS">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Svelto.ECS.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities.Hybrid">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities.Properties">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.Properties.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities.StaticTypeRegistry">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Entities.StaticTypeRegistry.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics.Extensions">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics.Extensions.Hybrid">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="uREPL">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\GamecraftPreview_Data\Managed\uREPL.dll</HintPath>
</Reference>
</ItemGroup>



extracommands/TestPlugin.cs → extracommands/ExtraCommandsPlugin.cs View File

@@ -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()

+ 0
- 22
extracommands/TestPatch.cs View File

@@ -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();
}
}
}

Loading…
Cancel
Save