Compare commits

...

11 commits

Author SHA1 Message Date
b3a72516fb
Add ClearConsole command 2020-02-08 23:04:50 +01:00
dce3045989
Fix issues with new update, waypoint fixes
Waypoints can be created from pilot seats now and it won't try to teleport to a waypoint if in a pilot seat
2020-02-08 17:52:41 +01:00
f9c034693f
Merge branch 'master' of https://git.exmods.org/ExtraCommands/extracommands
 Conflicts:
	extracommands/CommandLineCompositionRootSaveCommandPatch.cs
	extracommands/MoveBlocksCommandEngine.cs
2020-02-08 15:46:19 +01:00
NGnius
d9316fa20b Fix merge conflicts and ref 2020-01-26 21:41:41 -05:00
NGnius
347d7d7518 Port commands to GamecraftModdingAPI 2020-01-26 21:36:16 -05:00
f681287af1
More attempts 2020-01-18 01:28:59 +01:00
9c30f0f3b8
Debugging, attempting to prevent scale change 2020-01-17 02:04:12 +01:00
72d3f65fb1
Create set scale command 2020-01-15 23:26:52 +01:00
56af8ecd2c
Fix issues after the last GC update 2020-01-15 21:19:38 +01:00
NGnius
a2c3709c23 Fix last block move logic 2019-12-14 15:40:09 -05:00
NGnius
383519f786 Fix for changes in latest GC update 2019-11-29 20:11:36 -05:00
19 changed files with 468 additions and 663 deletions

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using RobocraftX.GUI.CommandLine; using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer; using RobocraftX.Multiplayer;
using RobocraftX.StateSync; using RobocraftX.StateSync;
@ -8,89 +9,61 @@ using Unity.Entities;
using UnityEngine; using UnityEngine;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean;
using RobocraftX; using RobocraftX;
using RobocraftX.Schedulers;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Tasks;
using GamecraftModdingAPI.Utility;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand] //[CustomCommand("Chain")]
class ChainCommandEngine : CustomCommandEngine class ChainCommandEngine : ICustomCommandEngine
{ {
public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Run two commands one after the other";
{
}
public override void Ready() public string Name => "Chain";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other"); CommandRegistrationHelper.Register<string, string>(Name, ChainCommand, Description);
CustomCommandUtility.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid");
CustomCommandUtility.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly");
} }
private void ChainCommand(string command1, string command2) private void ChainCommand(string command1, string command2)
{ {
string command1a = decomma(command1); string command1a = decomma(command1);
string command2a = decomma(command2); string command2a = decomma(command2);
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; ScheduleCommands(command1a, command2a).RunOn(Scheduler.extraLeanRunner);
if (!success1) {
uREPL.Log.Error("First command was not executed successfully");
return;
}
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success;
if (!success2) {
uREPL.Log.Error("Second command was not executed successfully");
}
} }
private void ChainNoFailCommand(string command1, string command2) private IEnumerator<TaskContract> ScheduleCommands(string c1, string c2)
{ {
string command1a = decomma(command1); yield return Yield.It;
string command2a = decomma(command2); bool success1 = uREPL.Evaluator.Evaluate(c1).type == CompileResult.Type.Success;
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; if (!success1)
if (!success1) { {
uREPL.Log.Error("First command was not executed successfully"); Logging.CommandLogError("First command was not executed successfully");
} }
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; bool success2 = uREPL.Evaluator.Evaluate(c2).type == CompileResult.Type.Success;
if (!success2) { if (!success2)
uREPL.Log.Error("Second command was not executed successfully"); {
Logging.CommandLogError("Second command was not executed successfully");
} }
} }
private void ChainQuietCommand(string command1, string command2)
{
string command1a = decomma(command1);
string command2a = decomma(command2);
uREPL.Evaluator.Evaluate(command1a);
uREPL.Evaluator.Evaluate(command2a);
}
private string decomma(string strIn) private string decomma(string strIn)
{ {
string strOut = ""; return strIn.Replace(", ", " ");
bool wasCommaLast = false;
foreach (char c in strIn)
{
if (wasCommaLast)
{
wasCommaLast = false;
if (c == ' ')
{
strOut = strOut.Substring(0, strOut.Length - 1);
}
}
if (c == ',')
{
wasCommaLast = true;
}
strOut += c;
}
return strOut;
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("Chain"); CommandRegistrationHelper.Unregister("Chain");
CustomCommandUtility.Unregister("ChainNoFail");
CustomCommandUtility.Unregister("ChainQuiet");
} }
} }
} }

View file

@ -0,0 +1,24 @@
using GamecraftModdingAPI.Commands;
using Svelto.ECS;
namespace ExtraCommands
{
[CustomCommand("ClearConsole")]
public class ClearConsoleCommandEngine : ICustomCommandEngine
{
public void Ready()
{
CommandRegistrationHelper.Register("ClearConsole", uREPL.Window.ClearOutputCommand,
"Clears the console output.");
}
public IEntitiesDB entitiesDB { get; set; }
public void Dispose()
{
CommandRegistrationHelper.Unregister("ClearConsole");
}
public string Name { get; } = "ClearConsole";
public string Description { get; } = "Clears the console output.";
}
}

View file

@ -1,54 +1 @@
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 CommandLineCompositionRootSaveCommandPatch
{
static void Postfix(UnityContext<FullGameCompositionRoot> contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
{
int engineCount = 0;
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);
engineCount++;
}
}
}
}
Debug.Log($"Added {engineCount} custom command engines");
}
static MethodBase TargetMethod(HarmonyInstance instance)
{
return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<UnityContext<FullGameCompositionRoot>>);
}
private static MethodInfo _ComposeMethodInfo(Action<UnityContext<FullGameCompositionRoot>, EnginesRoot, World, Action, MultiplayerInitParameters> a)
{
return a.Method;
}
}
}

View file

@ -1,18 +1,35 @@
using System; using System;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands namespace ExtraCommands
{ {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class CustomCommandAttribute: Attribute public class CustomCommandAttribute: Attribute
{ {
public string Name { get; protected set; } public readonly string Name;
public string Description { get; protected set; } public readonly string Description;
public CustomCommandAttribute(string name = "", string description = "") public readonly bool IsFactory;
public CustomCommandAttribute(string name = "", string description = "", bool factory = false)
{ {
this.Name = name; this.Name = name;
this.Description = description; this.Description = description;
this.IsFactory = factory;
} }
public static bool IsCompatible(Type t)
{
foreach (var i in t.GetInterfaces())
{
if (i == typeof(ICustomCommandEngine))
{
return true;
}
}
return false;
}
} }
} }

View file

@ -1,39 +0,0 @@
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 CustomCommandUtility.Register to add the command to the command line
virtual public void Ready() { }
}
}

View file

@ -1,54 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uREPL;
using RobocraftX.CommandLine.Custom;
namespace ExtraCommands
{
static class CustomCommandUtility
{
public static void Register(string name, Action action, string desc)
{
RuntimeCommands.Register(name, action, desc);
ConsoleCommands.Register(name, action, desc);
}
public static void Register(string name, Action<object> action, string desc)
{
RuntimeCommands.Register<object>(name, action, desc);
}
public static void Register<Param0>(string name, Action<Param0> action, string desc)
{
RuntimeCommands.Register<Param0>(name, action, desc);
ConsoleCommands.Register<Param0>(name, action, desc);
}
public static void Register<Param0, Param1>(string name, Action<Param0, Param1> action, string desc)
{
RuntimeCommands.Register<Param0, Param1>(name, action, desc);
ConsoleCommands.Register<Param0, Param1>(name, action, desc);
}
public static void Register(string name, Action<object, object, object> action, string desc)
{
RuntimeCommands.Register<object, object, object>(name, action, desc);
ConsoleCommands.Register<object, object, object>(name, action, desc);
}
public static void Register<Param0, Param1, Param2>(string name, Action<Param0, Param1, Param2> action, string desc)
{
RuntimeCommands.Register<Param0, Param1, Param2>(name, action, desc);
ConsoleCommands.Register<Param0, Param1, Param2>(name, action, desc);
}
public static void Unregister(string name)
{
RuntimeCommands.Unregister(name);
ConsoleCommands.Unregister(name);
}
}
}

View file

@ -10,6 +10,8 @@ using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using GamecraftModdingAPI.Commands;
// checklist of things to rename to make this command your own: // checklist of things to rename to make this command your own:
// [ ] namespace ExtraCommands.Example -> namespace ExtraCommands.[your command's namespace] // [ ] namespace ExtraCommands.Example -> namespace ExtraCommands.[your command's namespace]
// [ ] class ExampleCommandEngine : CustomCommandEngine -> class [your command name]CommandEngine : CustomCommandEngine // [ ] class ExampleCommandEngine : CustomCommandEngine -> class [your command name]CommandEngine : CustomCommandEngine
@ -25,24 +27,26 @@ namespace ExtraCommands.Example
{ {
// !!! Uncomment the line below this !!! // !!! Uncomment the line below this !!!
// [CustomCommand("Example")] // [CustomCommand("Example")]
class ExampleCommandEngine : CustomCommandEngine class ExampleCommandEngine : ICustomCommandEngine
{ {
// This class is a custom implementation of CustomCommandEngine specific to this command public string Description => "This is an example command which does nothing!";
// You can use Svelto.ECS.IEntityDB entitiesDB to query game entities or one of the protected variables for other things
// More documentation on Svelto.ECS: https://github.com/sebas77/Svelto.ECS
// Unfortunately the documentation is severely lacking and out of date; you may have better luck decompiling Svelto.ECS.dll
// See CustomCommandEngine.cs for more information on the super class
public ExampleCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Name => "Example";
{
}
// Ready() is called when the command is registered in-game (this happens whenever you load a game) public IEntitiesDB entitiesDB { set; private get; }
public override void Ready()
// This class is a custom implementation of CustomCommandEngine specific to this command
// You can use Svelto.ECS.IEntityDB entitiesDB to query game entities or one of the protected variables for other things
// More documentation on Svelto.ECS: https://github.com/sebas77/Svelto.ECS
// Unfortunately the documentation is severely lacking and out of date; you may have better luck decompiling Svelto.ECS.dll
// See CustomCommandEngine.cs for more information on the super class
// Ready() is called when the command is registered in-game (this happens whenever you load a game)
public void Ready()
{ {
// CustomCommandUtility.Register has multiple overloads depending on how many parameters you want to pass to your command // CustomCommandUtility.Register has multiple overloads depending on how many parameters you want to pass to your command
// See CustomCommandUtility.cs for more information // See CustomCommandUtility.cs for more information
CustomCommandUtility.Register("Example", ExampleCommand, "This is an example command which does nothing!"); CommandRegistrationHelper.Register(Name, ExampleCommand, Description);
} }
// ExampleCommand() is called whenever the command is executed. This can accept up to three parameters // ExampleCommand() is called whenever the command is executed. This can accept up to three parameters
@ -53,11 +57,11 @@ namespace ExtraCommands.Example
} }
// Dispose() is called when the command is unregistered in-game (this happens whenever you leave a game) // Dispose() is called when the command is unregistered in-game (this happens whenever you leave a game)
public override void Dispose() public void Dispose()
{ {
// You must unregister the command so it doesn't waste memory and so // You must unregister the command so it doesn't waste memory and so
// it can be re-registered next time // it can be re-registered next time
CustomCommandUtility.Unregister("Example"); CommandRegistrationHelper.Unregister(Name);
} }
} }
} }

View file

@ -10,18 +10,22 @@ using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("Exit")] [CustomCommand("Exit")]
class ExitCommandEngine : CustomCommandEngine class ExitCommandEngine : ICustomCommandEngine
{ {
public ExitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Close Gamecraft without any prompts";
{
}
public override void Ready() public string Name => "Exit";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register("Exit", ExitCommand, "Forcefully close Gamecraft"); CommandRegistrationHelper.Register(Name, ExitCommand, Description);
} }
private void ExitCommand() private void ExitCommand()
@ -29,9 +33,9 @@ namespace ExtraCommands.Basics
Application.Quit(); Application.Quit();
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("Exit"); CommandRegistrationHelper.Unregister(Name);
} }
} }
} }

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
@ -10,89 +10,104 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="GamecraftModdingAPI">
<HintPath>..\ref\Plugins\GamecraftModdingAPI.dll</HintPath>
</Reference>
<Reference Include="CommandLine"> <Reference Include="CommandLine">
<HintPath>..\ref\CommandLine.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>
</Reference> </Reference>
<Reference Include="Facepunch.Steamworks.Win64"> <Reference Include="Facepunch.Steamworks.Win64">
<HintPath>..\ref\Facepunch.Steamworks.Win64.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Facepunch.Steamworks.Win64.dll</HintPath>
</Reference> </Reference>
<Reference Include="FullGame"> <Reference Include="FullGame">
<HintPath>..\ref\FullGame.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\FullGame.dll</HintPath>
</Reference> </Reference>
<Reference Include="IllusionPlugin"> <Reference Include="IllusionPlugin">
<HintPath>..\IllusionPlugin.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\IllusionPlugin.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Character"> <Reference Include="RobocraftX.Character">
<HintPath>..\ref\RobocraftX.Character.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Character.dll</HintPath>
</Reference> </Reference>
<Reference Include="CommandLine"> <Reference Include="CommandLine">
<HintPath>..\ref\RobocraftX.Common.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Common.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Blocks"> <Reference Include="RobocraftX.Blocks">
<HintPath>..\ref\RobocraftX.Blocks.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Blocks.Ghost">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.Ghost.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Character"> <Reference Include="RobocraftX.Character">
<HintPath>..\ref\RobocraftX.Character.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Character.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Input"> <Reference Include="RobocraftX.Input">
<HintPath>..\ref\RobocraftX.Input.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Input.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MachineEditor.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.MainGame"> <Reference Include="RobocraftX.MainGame">
<HintPath>..\ref\RobocraftX.MainGame.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MainGame.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Multiplayer"> <Reference Include="RobocraftX.Multiplayer">
<HintPath>..\ref\RobocraftX.Multiplayer.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Multiplayer.NetworkEntityStream"> <Reference Include="RobocraftX.Multiplayer.NetworkEntityStream">
<HintPath>..\ref\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.MultiplayerInput"> <Reference Include="RobocraftX.MultiplayerInput">
<HintPath>..\ref\RobocraftX.MultiplayerInput.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.MultiplayerInput.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Physics">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Physics.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Services, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.Services.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.StateSync"> <Reference Include="RobocraftX.StateSync">
<HintPath>..\ref\RobocraftX.StateSync.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\RobocraftX.StateSync.dll</HintPath>
</Reference> </Reference>
<Reference Include="Svelto.Common"> <Reference Include="Svelto.Common">
<HintPath>..\ref\Svelto.Common.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Svelto.Common.dll</HintPath>
</Reference> </Reference>
<Reference Include="Svelto.ECS"> <Reference Include="Svelto.ECS">
<HintPath>..\ref\Svelto.ECS.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Svelto.ECS.dll</HintPath>
</Reference> </Reference>
<Reference Include="Svelto.Tasks"> <Reference Include="Svelto.Tasks">
<HintPath>..\ref\Svelto.Tasks.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Svelto.Tasks.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Entities"> <Reference Include="Unity.Entities">
<HintPath>..\ref\Unity.Entities.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Entities.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Entities.Hybrid"> <Reference Include="Unity.Entities.Hybrid">
<HintPath>..\ref\Unity.Entities.Hybrid.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Entities.Hybrid.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Entities.Properties"> <Reference Include="Unity.Entities.Properties">
<HintPath>..\ref\Unity.Entities.Properties.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Entities.Properties.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Entities.StaticTypeRegistry"> <Reference Include="Unity.Entities.StaticTypeRegistry">
<HintPath>..\ref\Unity.Entities.StaticTypeRegistry.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Entities.StaticTypeRegistry.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Mathematics"> <Reference Include="Unity.Mathematics">
<HintPath>..\ref\Unity.Mathematics.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Mathematics.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Mathematics.Extensions"> <Reference Include="Unity.Mathematics.Extensions">
<HintPath>..\ref\Unity.Mathematics.Extensions.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Mathematics.Extensions.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Mathematics.Extensions.Hybrid"> <Reference Include="Unity.Mathematics.Extensions.Hybrid">
<HintPath>..\ref\Unity.Mathematics.Extensions.Hybrid.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.Transforms"> <Reference Include="Unity.Transforms">
<HintPath>..\ref\Unity.Transforms.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Unity.Transforms.dll</HintPath>
</Reference> </Reference>
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>..\ref\UnityEngine.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\UnityEngine.dll</HintPath>
</Reference> </Reference>
<Reference Include="UnityEngine.CoreModule"> <Reference Include="UnityEngine.CoreModule">
<HintPath>..\ref\UnityEngine.CoreModule.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference> </Reference>
<Reference Include="uREPL"> <Reference Include="uREPL">
<HintPath>..\ref\uREPL.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\uREPL.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>

View file

@ -1,38 +1,53 @@
using System; using System;
using IllusionPlugin; using IllusionPlugin;
using UnityEngine; //using UnityEngine;
using Harmony;
using System.Reflection; using System.Reflection;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility;
namespace ExtraCommands namespace ExtraCommands
{ {
public class Plugin : IllusionPlugin.IEnhancedPlugin public class Plugin : IllusionPlugin.IEnhancedPlugin
{ {
public static HarmonyInstance harmony { get; protected set; }
public string[] Filter { get; } = new string[] { "RobocraftX", "Gamecraft", "GamecraftPreview" }; public string[] Filter { get; } = new string[] { "RobocraftX", "Gamecraft", "GamecraftPreview" };
public string Name { get; } = "ExtraCommands"; public string Name { get; } = "ExtraCommands";
public string Version { get; } = "v0.0.1"; public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands"; public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands";
public void OnApplicationQuit() public void OnApplicationQuit()
{ {
harmony.UnpatchAll(HarmonyID); GamecraftModdingAPI.Main.Shutdown();
Debug.Log("ExtraCommands shutdown & unpatch complete");
} }
public void OnApplicationStart() public void OnApplicationStart()
{ {
if (harmony == null) GamecraftModdingAPI.Main.Init();
{ object[] empty = new object[] { };
harmony = HarmonyInstance.Create(HarmonyID); int engineCount = 0;
harmony.PatchAll(Assembly.GetExecutingAssembly()); foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
} {
Debug.Log("ExtraCommands start & patch complete"); CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
} ICustomCommandEngine inst = null;
foreach (CustomCommandAttribute attr in attributes)
{
if (attr != null && CustomCommandAttribute.IsCompatible(t))
{
if (inst == null)
{
// create instance by getting the constructor through reflection
inst = (ICustomCommandEngine)t.GetConstructor(new Type[] { }).Invoke(empty);
CommandManager.AddCommand(inst);
engineCount++;
}
}
}
}
Logging.MetaLog($"Added {engineCount} custom command engines");
}
public void OnFixedUpdate() public void OnFixedUpdate()
{ {

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using RobocraftX.Multiplayer; using RobocraftX.Multiplayer;
using RobocraftX.Common; using RobocraftX.Common;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using Svelto.ECS; using Svelto.ECS;
using Svelto.ECS.EntityStructs; using Svelto.ECS.EntityStructs;
using Unity.Entities; using Unity.Entities;
@ -13,174 +14,39 @@ using RobocraftX.SimulationModeState;
using RobocraftX.UECS; using RobocraftX.UECS;
using Unity.Transforms; using Unity.Transforms;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Building namespace ExtraCommands.Building
{ {
[CustomCommand("MoveBlocks", "Move all blocks (including ground) from their original position")] //[CustomCommand("MoveBlocks", "Move all blocks (including ground) from their original position")]
[CustomCommand("MoveLastBlock", "Move last block from original position")] [CustomCommand("MoveLastBlock", "Move last block from original position")]
class MoveBlocksCommandEngine : CustomCommandEngine class MoveBlocksCommandEngine : ICustomCommandEngine
{ {
public MoveBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Move blocks";
{
}
public override void Ready() public string Name => "MoveBlocks";
{
CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move all blocks (including ground) from their original position");
CustomCommandUtility.Register<float, float, float>("MoveLastBlock", MoveLastBlockCommand, "Move last block from original position");
}
// Move every block by vector (x,y,z) public IEntitiesDB entitiesDB { set; private get; }
private void MoveBlocksCommand(float x, float y, float z)
{ public void Ready()
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP); {
if (simMode.simulationMode != SimulationMode.Build) //CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move all blocks (including ground) from their original position");
{ CommandRegistrationHelper.Register<float, float, float>("MoveLastBlock", MoveLastBlockCommand, "Move last block from original position");
uREPL.Log.Error("Blocks can only be moved in Build Mode"); }
return;
}
uint count = this.entitiesDB.Count<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
float3 translationVector = new float3(x,y,z);
for (uint i = 0; i < count; i++)
{
TranslateSingleBlock(i, translationVector);
}
uREPL.Log.Output($"Moved {count} blocks");
}
// Move block with highest index by vector (x,y,z)
private void MoveLastBlockCommand(float x, float y, float z) private void MoveLastBlockCommand(float x, float y, float z)
{
float3 vector = new float3(x, y, z);
Movement.MoveConnectedBlocks(BlockIdentifiers.LatestBlockID, vector);
}
public void Dispose()
{ {
uint count = entitiesDB.Count<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); //CommandRegistrationHelper.Unregister("MoveBlocks");
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP); CommandRegistrationHelper.Unregister("MoveLastBlock");
if (simMode.simulationMode != SimulationMode.Build)
{
uREPL.Log.Error("Blocks can only be moved in Build Mode");
return;
}
float3 newPos = TranslateConnectedBlocks(count-1, new float3(x,y,z));
uREPL.Log.Output($"Moved block to ({newPos.x},{newPos.y},{newPos.z})");
}
// Move the block denoted by blockID by translationVector (old_position += translationVector)
private float3 TranslateSingleBlock(uint blockID, float3 translationVector)
{
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
// main (persistent) position
posStruct.position.x += translationVector.x;
posStruct.position.y += translationVector.y;
posStruct.position.z += translationVector.z;
// placement grid position
gridStruct.position.x += translationVector.x;
gridStruct.position.y += translationVector.y;
gridStruct.position.z += translationVector.z;
// rendered position
transStruct.position.x += translationVector.x;
transStruct.position.y += translationVector.y;
transStruct.position.z += translationVector.z;
// collision position
this.physWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
{
Value = posStruct.position
});
return posStruct.position;
}
private float3 TranslateConnectedBlocks(uint blockID, float3 translationVector)
{
//float3 newPosition = TranslateSingleBlock(blockID, translationVector);
HashSet<uint> processedCubes = new HashSet<uint>();
Stack<uint> cubeStack = new Stack<uint>();
cubeStack.Push(blockID);
uint count;
GridConnectionsEntityStruct blockConnections;
MachineGraphConnectionEntityStruct[] connections;
while (cubeStack.Count > 0) // find all inter-connected blocks
{
uint connectedBlockID = cubeStack.Pop();
processedCubes.Add(connectedBlockID);
ScalingEntityStruct scale = entitiesDB.QueryEntity<ScalingEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
uREPL.Log.Output($"Catching {connectedBlockID} with scale {scale.scale}");
blockConnections = entitiesDB.QueryEntity<GridConnectionsEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
connections = entitiesDB.QueryEntities<MachineGraphConnectionEntityStruct>(blockConnections.connectionGroup, out count);
foreach (MachineGraphConnectionEntityStruct conn in connections)
{
if (!processedCubes.Contains(conn.connectedBlock.entityID)
&& blockConnections.isConnectionGroupAssigned
&& (conn.oppositeConnectionEgid.entityID != 0u
|| conn.oppositeConnectionEgid.entityID != conn.connectedBlock.entityID))
{
uREPL.Log.Output($"Block {connectedBlockID} connects to {conn.connectedBlock.entityID} (opposite {conn.oppositeConnectionEgid.entityID})");
cubeStack.Push(conn.connectedBlock.entityID);
}
}
}
foreach (uint id in processedCubes)
{
TranslateSingleBlock(id, translationVector);
}
uREPL.Log.Output($"Found {processedCubes.Count} connected blocks");
return this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).position;
}
// unused; for future reference
private void ToggleMode()
{
ref SimulationModeStateEntityStruct ptr = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
ref SimulationFrameEntityStruct ptr2 = ref this.entitiesDB.QueryUniqueEntity<SimulationFrameEntityStruct>(SimulationFrame.SimulationFrameGroup);
switch (ptr.simulationMode)
{
case SimulationMode.Build:
ptr.simulationMode = SimulationMode.SwitchToSim;
ptr.simulationModeChangeFrame = ptr2.simFrame;
return;
case SimulationMode.SwitchToSim:
case SimulationMode.SwitchToBuild:
return;
case SimulationMode.Simulation:
ptr.simulationMode = SimulationMode.SwitchToBuild;
ptr.simulationModeChangeFrame = ptr2.simFrame;
ptr.rigidBodiesCreated = false;
return;
default:
throw new ArgumentOutOfRangeException();
}
}
// unused; for future reference
private IEnumerator<TaskContract> TriggerSwitchToSimTask()
{
this.ToggleMode();
yield break;
}
// unused; for future reference
private IEnumerator<TaskContract> WaitThenTriggerSwitchToBuildTask()
{
while (true)
{
SimulationModeStateEntityStruct modeStruct = this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
if (modeStruct.simulationMode == SimulationMode.Simulation)
{
this.ToggleMode();
break;
} else
{
yield return Yield.It;
}
}
yield break;
}
public override void Dispose()
{
CustomCommandUtility.Unregister("MoveBlocks");
CustomCommandUtility.Unregister("MoveLastBlock");
} }
} }
} }

View file

@ -14,139 +14,37 @@ using Unity.Transforms;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine; using UnityEngine;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Blocks;
namespace ExtraCommands.Building namespace ExtraCommands.Building
{ {
//[CustomCommand("RotateBlocks", "Rotate all blocks (including ground) from their original position")] //[CustomCommand("RotateBlocks", "Rotate all blocks (including ground) from their original position")]
[CustomCommand("RotateLastBlock", "Rotate last block from original position")] [CustomCommand("RotateLastBlock", "Rotate last block from original position")]
class RotateBlocksCommandEngine : CustomCommandEngine class RotateBlocksCommandEngine : ICustomCommandEngine
{ {
public RotateBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Rotate last block from original position";
{
}
public override void Ready() public string Name => "RotateLastBlock";
{
//CustomCommandUtility.Register<float, float, float>("RotateBlocks", RotateBlocksCommand, "Rotate all blocks (including ground) from their original position");
CustomCommandUtility.Register<float, float, float>("RotateLastBlock", RotateLastBlockCommand, "Rotate last block from original position");
}
// Move every block by vector (x,y,z) public IEntitiesDB entitiesDB { set; private get; }
private void RotateBlocksCommand(float x, float y, float z)
public void Ready()
{ {
Vector3 eulerAngles = new Vector3(x, y, z); CommandRegistrationHelper.Register<float, float, float>(Name, RotateLastBlockCommand, Description);
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
if (simMode.simulationMode != SimulationMode.Build)
{
uREPL.Log.Error("Blocks can only be moved in Build Mode");
return;
}
uint count = entitiesDB.Count<RotationEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
for (uint i = 0; i < count; i++)
{
RotateSingleBlock(i, eulerAngles);
}
uREPL.Log.Output($"Moved {count} blocks");
} }
// Move block with highest index by vector (x,y,z) // Move block with highest index by vector (x,y,z)
private void RotateLastBlockCommand(float x, float y, float z) private void RotateLastBlockCommand(float x, float y, float z)
{ {
Vector3 eulerAngles = new Vector3(x, y, z); float3 eulerAngles = new float3(x, y, z);
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP); GamecraftModdingAPI.Blocks.Rotation.RotateBlock(BlockIdentifiers.LatestBlockID, eulerAngles);
if (simMode.simulationMode != SimulationMode.Build)
{
uREPL.Log.Error("Blocks can only be moved in Build Mode");
return;
}
uint count = entitiesDB.Count<RotationEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
if (count == 0)
{
uREPL.Log.Error("No block found");
return;
}
Vector3 newRotation = RotateSingleBlock(count - 1, eulerAngles);
uREPL.Log.Output($"Rotated block to ({newRotation.x},{newRotation.y},{newRotation.z})");
} }
private float3 RotateSingleBlock(uint blockID, Vector3 rotationVector) public void Dispose()
{
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
// main (persistent) position
Quaternion newRotation = (Quaternion)rotStruct.rotation;
newRotation.eulerAngles += rotationVector;
rotStruct.rotation = (quaternion)newRotation;
// placement grid rotation
Quaternion newGridRotation = (Quaternion)gridStruct.rotation;
newGridRotation.eulerAngles += rotationVector;
gridStruct.rotation = (quaternion)newGridRotation;
// rendered position
Quaternion newTransRotation = (Quaternion)rotStruct.rotation;
newTransRotation.eulerAngles += rotationVector;
transStruct.rotation = newTransRotation;
// collision position
this.physWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Rotation
{
Value = rotStruct.rotation
});
return ((Quaternion)rotStruct.rotation).eulerAngles;
}
// unused; for future reference
private void ToggleMode()
{
ref SimulationModeStateEntityStruct ptr = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
ref SimulationFrameEntityStruct ptr2 = ref this.entitiesDB.QueryUniqueEntity<SimulationFrameEntityStruct>(SimulationFrame.SimulationFrameGroup);
switch (ptr.simulationMode)
{
case SimulationMode.Build:
ptr.simulationMode = SimulationMode.SwitchToSim;
ptr.simulationModeChangeFrame = ptr2.simFrame;
return;
case SimulationMode.SwitchToSim:
case SimulationMode.SwitchToBuild:
return;
case SimulationMode.Simulation:
ptr.simulationMode = SimulationMode.SwitchToBuild;
ptr.simulationModeChangeFrame = ptr2.simFrame;
ptr.rigidBodiesCreated = false;
return;
default:
throw new ArgumentOutOfRangeException();
}
}
// unused; for future reference
private IEnumerator<TaskContract> TriggerSwitchToSimTask()
{
this.ToggleMode();
yield break;
}
// unused; for future reference
private IEnumerator<TaskContract> WaitThenTriggerSwitchToBuildTask()
{
while (true)
{
SimulationModeStateEntityStruct modeStruct = this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
if (modeStruct.simulationMode == SimulationMode.Simulation)
{
this.ToggleMode();
break;
} else
{
yield return Yield.It;
}
}
yield break;
}
public override void Dispose()
{ {
//CustomCommandUtility.Unregister("RotateBlocks"); //CustomCommandUtility.Unregister("RotateBlocks");
CustomCommandUtility.Unregister("RotateLastBlock"); CommandRegistrationHelper.Unregister("RotateLastBlock");
} }
} }
} }

View file

@ -9,34 +9,35 @@ using UnityEngine;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics; using Unity.Mathematics;
using RobocraftX.Character.Camera; using RobocraftX.Character.Camera;
using RobocraftX.Character.Factories; using RobocraftX.Character.Factories;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("RotateTo")] [CustomCommand("Rotation")]
class RotatePlayerCommandEngine : CustomCommandEngine class RotatePlayerCommandEngine : ICustomCommandEngine
{ {
public string Description => "Rotation";
public RotatePlayerCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Name => "Rotation commands";
{
}
public override void Ready() public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<float, float>("RotateAbsolute", RotateAbsoluteCommand, "Rotate the player camera to the entered rotation"); CommandRegistrationHelper.Register<float, float>("RotateAbsolute", RotateAbsoluteCommand, "Rotate the player camera to the entered rotation");
CustomCommandUtility.Register<float, float>("RotateRelative", RotateRelativeCommand, "Rotate the player camera by the entered rotation"); CommandRegistrationHelper.Register<float, float>("RotateRelative", RotateRelativeCommand, "Rotate the player camera by the entered rotation");
} }
private void RotateAbsoluteCommand(float vertical, float horizontal) private void RotateAbsoluteCommand(float vertical, float horizontal)
{ {
uint count; EntityCollection<CharacterCameraEntityStruct> cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup);
CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
int num2 = 0; int num2 = 0;
while ((long)num2 < (long)((ulong)count)) while (num2 < cameras.length)
{ {
cameras[num2].eulerRotation.x = vertical; cameras[num2].eulerRotation.x = vertical;
cameras[num2].eulerRotation.y = horizontal; cameras[num2].eulerRotation.y = horizontal;
@ -57,12 +58,11 @@ namespace ExtraCommands.Basics
private void RotateRelativeCommand(float vertical, float horizontal) private void RotateRelativeCommand(float vertical, float horizontal)
{ {
float2 angleDelta = new float2(vertical, horizontal); float2 angleDelta = new float2(vertical, horizontal);
uint count; EntityCollection<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup);
ValueTuple<CharacterCameraSettingsEntityStruct[], CharacterCameraEntityStruct[]> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count); EntityCollection<CharacterCameraSettingsEntityStruct> settings = tuple.Item1;
CharacterCameraSettingsEntityStruct[] settings = tuple.Item1; EntityCollection<CharacterCameraEntityStruct> cameras = tuple.Item2;
CharacterCameraEntityStruct[] cameras = tuple.Item2;
int num2 = 0; int num2 = 0;
while ((long)num2 < (long)((ulong)count)) while (num2 < cameras.length)
{ {
CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta); CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta);
// TODO: Multiplayer compatibility // TODO: Multiplayer compatibility
@ -79,10 +79,10 @@ namespace ExtraCommands.Basics
} }
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("RotateAbsolute"); CommandRegistrationHelper.Unregister("RotateAbsolute");
CustomCommandUtility.Unregister("RotateRelative"); CommandRegistrationHelper.Unregister("RotateRelative");
} }
} }
} }

View file

@ -10,18 +10,22 @@ using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("SetFieldOfView")] [CustomCommand("SetFieldOfView")]
class SetFOVCommandEngine : CustomCommandEngine class SetFOVCommandEngine : ICustomCommandEngine
{ {
public SetFOVCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Set the camera's field of view";
{
}
public override void Ready() public string Name => "SetFieldOfView";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<float>("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view"); CommandRegistrationHelper.Register<float>(Name, SetFieldOfViewCommand, Description);
} }
private void SetFieldOfViewCommand(float newFoV) private void SetFieldOfViewCommand(float newFoV)
@ -29,9 +33,9 @@ namespace ExtraCommands.Basics
Camera.main.fieldOfView = newFoV; Camera.main.fieldOfView = newFoV;
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("SetFieldOfView"); CommandRegistrationHelper.Unregister(Name);
} }
} }
} }

View file

@ -0,0 +1,158 @@
using System;
using System.Linq;
using System.Reflection;
using GamecraftModdingAPI.Commands;
using Harmony;
using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer;
using RobocraftX.StateSync;
using RobocraftX.Character;
using Svelto.ECS;
using Unity.Entities;
using UnityEngine;
using uREPL;
using Svelto.Context;
using RobocraftX;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Blocks.Scaling;
using RobocraftX.Common;
using RobocraftX.CR.MachineEditing;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
namespace ExtraCommands.Basics
{
[CustomCommand("SetScale")]
class SetScaleCommandEngine : ICustomCommandEngine
{
public void Ready()
{
CommandRegistrationHelper.Register<float, float, float>("SetScale", SetScaleCommand, "Set the scale for the next block. Use 0 0 0 to reset. The displayed cube is uniformly scaled until placed.");
}
public IEntitiesDB entitiesDB { get; set; }
private static float3 _scale;
//private HarmonyInstance harmony;
private void SetScaleCommand(float x, float y, float z)
{
/*if (harmony == null)
{
Console.WriteLine("Patching...");
harmony = HarmonyInstance.Create("org.exmods.extracommands.setscale");
var type = Type.GetType("RobocraftX.CR.MachineEditing.PlacementCursorEngine");
var method = type.GetMethod("<UpdateCursor>g__UpdatePlacementCursorScales|10_0");
harmony.Patch(method, new HarmonyMethod(((Func<bool>) PatchPrefix).Method));
Console.WriteLine("Patched");
}*/
_scale = new float3(x, y, z);
EntityCollection<GhostScalingEntityStruct> scalings =
entitiesDB.QueryEntities<GhostScalingEntityStruct>(
(ExclusiveGroupStruct) NamedExclusiveGroup<GHOST_BLOCKS>.Group);
Console.WriteLine("Found " + scalings.length + " scalings.");
var egid = new EGID(0, NamedExclusiveGroup<GHOST_BLOCKS>.Group);
for (int index = 0; index < scalings.length; index++)
{
Console.WriteLine("G scaling " + index + ": " + scalings[index].ghostScale);
ref var scaling = ref entitiesDB.QueryEntity<ScalingEntityStruct>(egid);
Console.WriteLine("Scaling " + index + ": " + scaling);
ref var scale = ref entitiesDB.QueryEntity<BlockPlacementScaleEntityStruct>(egid);
Console.WriteLine("Scale " + index + ": " + scale.snapGridScale);
UpdateScale(ref scale, ref scaling, ref scalings[index], egid);
}
}
private void UpdateScale(ref BlockPlacementScaleEntityStruct scale, ref ScalingEntityStruct scaling,
ref GhostScalingEntityStruct gscaling, EGID egid)
{
Console.WriteLine("Attempting to update scale...");
if (_scale.x < 4e-5 || _scale.y < 4e-5 || _scale.z < 4e-5) return;
Console.WriteLine("Scale is set, continuing.");
scale.snapGridScale = Math.Max((int) _scale.x, 1);
scale.blockPlacementHeight = Math.Max((int) _scale.y, 1);
scale.desiredScaleFactor = Math.Max((int) _scale.x, 1);
entitiesDB.PublishEntityChange<BlockPlacementScaleEntityStruct>(egid);
Console.WriteLine("Scale published");
scaling.scale = _scale;
entitiesDB.PublishEntityChange<ScalingEntityStruct>(egid);
Console.WriteLine("Scaling published");
gscaling.ghostScale = _scale;
gscaling.hasBlockBeenUnformedScaled = true; //Apply scale instead of overwriting it
entitiesDB.PublishEntityChange<GhostScalingEntityStruct>(egid);
Console.WriteLine("Scale updated (" + scaling.scale + ")");
}
public void Dispose()
{
CommandRegistrationHelper.Unregister("SetScale");
}
/*public void Add(ref GhostScalingEntityStruct entityView, EGID egid)
{ //If the cursor is near a block, it recreates the entity - nope
Console.WriteLine("Entity " + egid + " added: " + entityView.ghostScale);
ref var scale = ref entitiesDB.QueryEntity<BlockPlacementScaleEntityStruct>(egid);
ref var scaling = ref entitiesDB.QueryEntity<ScalingEntityStruct>(egid);
UpdateScale(ref scale, ref scaling, ref entityView);
entitiesDB.PublishEntityChange<ScalingEntityStruct>(egid);
entitiesDB.PublishEntityChange<BlockPlacementScaleEntityStruct>(egid);
entitiesDB.PublishEntityChange<GhostScalingEntityStruct>(egid);
}
public void Remove(ref GhostScalingEntityStruct entityView, EGID egid)
{
}*/
/*private bool PatchPrefix()
{
if (math.any(_scale < new float3(4e-5)))
return true;
return false; //Prevent updating
}*/
//ScaleGhostBlockEngine.UpdateScaling
[HarmonyPatch]
public class ScalePatch
{
static bool Prefix()
{
if (math.any(_scale < new float3(4e-5)))
return true;
return false; //Prevent updating
}
static MethodBase TargetMethod(HarmonyInstance instance)
{
return typeof(ScaleGhostBlockEngine).GetMethod("UpdateScaling",
BindingFlags.NonPublic | BindingFlags.Instance);
}
}
//RobocraftX.Blocks.Ghost.UniformScaleGhostBlockEngine.SimulatePhysicsStep - Does not update the ghost block but the outline still gets rounded
//RobocraftX.Blocks.Ghost.GhostScalingSyncEngine.SimulatePhysicsStep (reflection) - Doesn't do anything immediately visible
//RobocraftX.CR.MachineEditing.PlacementCursorEngine.<UpdateCursor>g__UpdatePlacementCursorScales|10_0
//[HarmonyPatch(typeof(UniformScaleGhostBlockEngine))]
//[HarmonyPatch("SimulatePhysicsStep")]
//[HarmonyPatch]
public class UniformScalePatch
{
static bool Prefix()
{
if (math.any(_scale < new float3(4e-5)))
return true;
return false; //Prevent updating
}
static MethodBase TargetMethod(HarmonyInstance instance)
{
return typeof(PlacementCursorEngine)
.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
.First(m => m.Name.Contains("UpdatePlacementCursorScales"));
}
}
public string Name { get; } = "SetScale";
public string Description { get; } = "Set the scale for the next block to be placed.";
}
}

View file

@ -10,18 +10,22 @@ using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("SetTargetFPS")] [CustomCommand("SetTargetFPS")]
class SetTargetFramerateCommandEngine : CustomCommandEngine class SetTargetFramerateCommandEngine : ICustomCommandEngine
{ {
public SetTargetFramerateCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Set Gamecraft's target FPS'";
{
}
public override void Ready() public string Name => "SetTargetFPS";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<int>("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS"); CommandRegistrationHelper.Register<int>(Name, SetFramerateCommand, Description);
} }
private void SetFramerateCommand(int newFoV) private void SetFramerateCommand(int newFoV)
@ -29,9 +33,9 @@ namespace ExtraCommands.Basics
Application.targetFrameRate = newFoV; Application.targetFrameRate = newFoV;
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("SetTargetFPS"); CommandRegistrationHelper.Unregister(Name);
} }
} }
} }

View file

@ -9,26 +9,42 @@ using Unity.Entities;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using RobocraftX.Physics;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Waypoints namespace ExtraCommands.Waypoints
{ {
[CustomCommand] [CustomCommand("Waypoints")]
class TeleportWaypointCommandEngine : CustomCommandEngine class TeleportWaypointCommandEngine : ICustomCommandEngine
{ {
private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>(); 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() public string Description => "";
public string Name => "Waypoints";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location"); CommandRegistrationHelper.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
CustomCommandUtility.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint"); CommandRegistrationHelper.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
} }
private void CreateWaypointCommand(object name) private void CreateWaypointCommand(object name)
{ {
ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup); RigidBodyEntityStruct reference;
if (entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.OnFootGroup, out uint index,
out RigidBodyEntityStruct[] array)
|| entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.InPilotSeatGroup, out index,
out array))
reference = array[index];
else
{
Log.Output("Player not found!");
return;
}
_waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z }; _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
uREPL.Log.Output("Saved " + name.ToString()); uREPL.Log.Output("Saved " + name.ToString());
} }
@ -40,14 +56,20 @@ namespace ExtraCommands.Waypoints
uREPL.Log.Error("Waypoint not found"); uREPL.Log.Error("Waypoint not found");
return; return;
} }
float[] loc = _waypoints[name];
if (entitiesDB.Exists<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.InPilotSeatGroup))
{
Log.Error("Cannot teleport from a pilot seat");
return;
}
float[] loc = _waypoints[name];
uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]); uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("CreateWaypoint"); CommandRegistrationHelper.Unregister("CreateWaypoint");
CustomCommandUtility.Unregister("TeleportPlayerWaypoint"); CommandRegistrationHelper.Unregister("TeleportPlayerWaypoint");
} }
} }
} }

View file

@ -1,57 +0,0 @@
using System;
using System.Reflection;
using Harmony;
using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer;
using RobocraftX.StateSync;
using RobocraftX.Character;
using RobocraftX.Character.Movement;
using RobocraftX.Common.Input;
using Svelto.ECS;
using Unity.Entities;
using UnityEngine;
using uREPL;
using Svelto.Context;
using RobocraftX;
namespace ExtraCommands.Basics
{
//[HarmonyPatch]
//[CustomCommand("ToggleJumpEnabled")]
class ToggleJumpCommandEngine : CustomCommandEngine
{
private static bool isJumpEnabled = false;
public ToggleJumpCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
{
}
public override void Ready()
{
CustomCommandUtility.Register<bool>("ToggleJumpEnabled", ToggleJumpCommand, "Enable or disable the character's ability to jump");
}
private void ToggleJumpCommand(bool isEnabled)
{
isJumpEnabled = isEnabled;
}
public override void Dispose()
{
CustomCommandUtility.Unregister("ToggleJumpEnabled");
}
public static void Postfix (ref CharacterInputEntityStruct input, InputStruct entity)
{
if (entity.CheckInputAction(ActionInput.Up) && !isJumpEnabled)
{
input.action.y -= 1f;
}
}
public static MethodBase TargetMethod(HarmonyInstance instance)
{
Type targetType = Harmony.AccessTools.TypeByName("RobocraftX.Character.Input.CharacterInputEngine");
return Harmony.AccessTools.Method(targetType, "SaveInput", new Type[] { typeof(CharacterInputEntityStruct), typeof(InputStruct) });
}
}
}

View file

@ -10,18 +10,22 @@ using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using GamecraftModdingAPI.Commands;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand("Wait")] [CustomCommand("Wait")]
class WaitCommandEngine : CustomCommandEngine class WaitCommandEngine : ICustomCommandEngine
{ {
public WaitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public string Description => "Delay execution (freeze the game) for a length of time (ms)";
{
}
public override void Ready() public string Name => "Wait";
public IEntitiesDB entitiesDB { set; private get; }
public void Ready()
{ {
CustomCommandUtility.Register<int>("Wait", WaitCommand, "Delay execution (freeze the game) for a length of time (ms)"); CommandRegistrationHelper.Register<int>("Wait", WaitCommand, "Delay execution (freeze the game) for a length of time (ms)");
} }
private void WaitCommand(int ms) private void WaitCommand(int ms)
@ -29,9 +33,9 @@ namespace ExtraCommands.Basics
System.Threading.Thread.Sleep(ms); System.Threading.Thread.Sleep(ms);
} }
public override void Dispose() public void Dispose()
{ {
CustomCommandUtility.Unregister("Wait"); CommandRegistrationHelper.Unregister("Wait");
} }
} }
} }