2019-12-13 05:00:11 +00:00
|
|
|
|
using System;
|
2020-11-12 01:39:58 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-22 22:06:49 +00:00
|
|
|
|
using System.Diagnostics;
|
2020-12-17 19:20:46 +00:00
|
|
|
|
using System.IO;
|
2020-05-13 12:02:36 +00:00
|
|
|
|
using System.Linq;
|
2019-12-13 05:00:11 +00:00
|
|
|
|
using System.Reflection;
|
2020-11-12 01:39:58 +00:00
|
|
|
|
using System.Reflection.Emit;
|
2020-05-22 22:06:49 +00:00
|
|
|
|
using System.Text;
|
2020-12-21 21:31:57 +00:00
|
|
|
|
using GamecraftModdingAPI.App;
|
2020-05-03 19:31:09 +00:00
|
|
|
|
using HarmonyLib;
|
2020-05-22 22:06:49 +00:00
|
|
|
|
using IllusionInjector;
|
2019-12-25 19:25:53 +00:00
|
|
|
|
// test
|
2020-11-12 01:39:58 +00:00
|
|
|
|
using GPUInstancer;
|
2019-12-25 19:25:53 +00:00
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using RobocraftX.Blocks;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using RobocraftX.SimulationModeState;
|
2020-05-19 22:08:02 +00:00
|
|
|
|
using RobocraftX.FrontEnd;
|
|
|
|
|
using Unity.Mathematics;
|
2020-11-12 01:39:58 +00:00
|
|
|
|
using UnityEngine;
|
2020-06-14 19:40:47 +00:00
|
|
|
|
using RobocraftX.Schedulers;
|
|
|
|
|
using Svelto.Tasks.ExtraLean;
|
|
|
|
|
using uREPL;
|
2019-12-15 07:20:20 +00:00
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Commands;
|
2019-12-14 18:52:24 +00:00
|
|
|
|
using GamecraftModdingAPI.Events;
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
2020-05-13 14:52:21 +00:00
|
|
|
|
using GamecraftModdingAPI.Blocks;
|
2020-12-21 21:31:57 +00:00
|
|
|
|
using GamecraftModdingAPI.Interface.IMGUI;
|
2020-05-19 22:08:02 +00:00
|
|
|
|
using GamecraftModdingAPI.Players;
|
2020-12-21 21:31:57 +00:00
|
|
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
|
using UnityEngine.AddressableAssets.ResourceLocators;
|
|
|
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
|
using UnityEngine.ResourceManagement.ResourceLocations;
|
|
|
|
|
using UnityEngine.ResourceManagement.ResourceProviders;
|
|
|
|
|
using Debug = FMOD.Debug;
|
2020-11-12 01:39:58 +00:00
|
|
|
|
using EventType = GamecraftModdingAPI.Events.EventType;
|
2020-12-21 21:31:57 +00:00
|
|
|
|
using Label = GamecraftModdingAPI.Interface.IMGUI.Label;
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2019-12-14 04:42:55 +00:00
|
|
|
|
namespace GamecraftModdingAPI.Tests
|
2019-12-13 05:00:11 +00:00
|
|
|
|
{
|
2020-08-23 13:59:13 +00:00
|
|
|
|
#if DEBUG
|
2019-12-13 05:00:11 +00:00
|
|
|
|
// unused by design
|
2019-12-15 07:20:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modding API implemented as a standalone IPA Plugin.
|
|
|
|
|
/// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself
|
|
|
|
|
/// </summary>
|
2020-08-23 13:59:13 +00:00
|
|
|
|
public class GamecraftModdingAPIPluginTest : IllusionPlugin.IEnhancedPlugin
|
2020-05-13 20:52:06 +00:00
|
|
|
|
{
|
|
|
|
|
|
2020-05-03 19:31:09 +00:00
|
|
|
|
private static Harmony harmony { get; set; }
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2020-08-23 13:59:13 +00:00
|
|
|
|
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2020-08-23 13:59:13 +00:00
|
|
|
|
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
|
|
|
|
public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi";
|
|
|
|
|
|
2020-08-23 13:59:13 +00:00
|
|
|
|
public override void OnApplicationQuit()
|
2019-12-13 05:00:11 +00:00
|
|
|
|
{
|
2019-12-14 04:42:55 +00:00
|
|
|
|
GamecraftModdingAPI.Main.Shutdown();
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 13:59:13 +00:00
|
|
|
|
public override void OnApplicationStart()
|
2020-06-18 01:04:40 +00:00
|
|
|
|
{
|
2020-04-07 17:05:00 +00:00
|
|
|
|
FileLog.Reset();
|
2020-05-03 19:31:09 +00:00
|
|
|
|
Harmony.DEBUG = true;
|
2020-06-18 01:04:40 +00:00
|
|
|
|
GamecraftModdingAPI.Main.Init();
|
2020-04-29 01:56:34 +00:00
|
|
|
|
Logging.MetaDebugLog($"Version group id {(uint)ApiExclusiveGroups.versionGroup}");
|
2020-01-26 20:26:48 +00:00
|
|
|
|
// in case Steam is not installed/running
|
|
|
|
|
// this will crash the game slightly later during startup
|
|
|
|
|
//SteamInitPatch.ForcePassSteamCheck = true;
|
|
|
|
|
// in case running in a VM
|
|
|
|
|
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
|
|
|
|
|
// disable some Gamecraft analytics
|
|
|
|
|
//AnalyticsDisablerPatch.DisableAnalytics = true;
|
2020-02-18 18:59:02 +00:00
|
|
|
|
// disable background music
|
2020-06-18 01:04:40 +00:00
|
|
|
|
Logging.MetaDebugLog("Audio Mixers: " + string.Join(",", AudioTools.GetMixers()));
|
2020-02-20 01:32:58 +00:00
|
|
|
|
//AudioTools.SetVolume(0.0f, "Music"); // The game now sets this from settings again after this is called :(
|
2019-12-19 16:46:32 +00:00
|
|
|
|
|
2020-05-21 23:40:46 +00:00
|
|
|
|
//Utility.VersionTracking.Enable();//(very) unstable
|
2020-04-29 01:56:34 +00:00
|
|
|
|
|
2020-05-14 02:34:26 +00:00
|
|
|
|
// debug/test handlers
|
2020-08-03 16:45:38 +00:00
|
|
|
|
#pragma warning disable 0612
|
2020-05-14 02:34:26 +00:00
|
|
|
|
HandlerBuilder.Builder()
|
|
|
|
|
.Name("appinit API debug")
|
|
|
|
|
.Handle(EventType.ApplicationInitialized)
|
|
|
|
|
.OnActivation(() => { Logging.Log("App Inited event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menuact API debug")
|
|
|
|
|
.Handle(EventType.Menu)
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.OnActivation(() => { Logging.Log("Menu Activated event!"); })
|
2020-05-14 02:34:26 +00:00
|
|
|
|
.OnDestruction(() => { Logging.Log("Menu Destroyed event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menuswitch API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.MenuSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Menu Switched To event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gameact API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Activated event!"); })
|
|
|
|
|
.OnDestruction(() => { Logging.Log("Game Destroyed event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gamerel API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.GameReloaded)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Reloaded event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gameswitch API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.GameSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Switched To event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("simulationswitch API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.SimulationSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Mode Simulation Switched To event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("buildswitch API debug")
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Handle(EventType.BuildSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Mode Build Switched To event!"); })
|
|
|
|
|
.Build();
|
2020-05-14 02:34:26 +00:00
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menu activated API error thrower test")
|
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() => { throw new Exception("Event Handler always throws an exception!"); })
|
|
|
|
|
.Build();
|
2020-08-03 16:45:38 +00:00
|
|
|
|
#pragma warning restore 0612
|
2020-06-18 01:04:40 +00:00
|
|
|
|
/*HandlerBuilder.Builder("enter game from menu test")
|
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() =>
|
|
|
|
|
{
|
|
|
|
|
Tasks.Scheduler.Schedule(new Tasks.Repeatable(enterGame, shouldRetry, 0.2f));
|
|
|
|
|
})
|
|
|
|
|
.Build();*/
|
|
|
|
|
|
|
|
|
|
// debug/test commands
|
2020-02-18 18:59:02 +00:00
|
|
|
|
if (Dependency.Hell("ExtraCommands"))
|
|
|
|
|
{
|
2020-05-01 18:50:55 +00:00
|
|
|
|
CommandBuilder.Builder()
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Name("Exit")
|
|
|
|
|
.Description("Close Gamecraft immediately, without any prompts")
|
|
|
|
|
.Action(() => { UnityEngine.Application.Quit(); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
2020-05-01 18:50:55 +00:00
|
|
|
|
CommandBuilder.Builder()
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Name("SetFOV")
|
|
|
|
|
.Description("Set the player camera's field of view")
|
|
|
|
|
.Action((float d) => { UnityEngine.Camera.main.fieldOfView = d; })
|
|
|
|
|
.Build();
|
2020-05-01 18:50:55 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder()
|
2020-05-13 12:02:36 +00:00
|
|
|
|
.Name("MoveLastBlock")
|
|
|
|
|
.Description("Move the most-recently-placed block, and any connected blocks by the given offset")
|
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
if (GameState.IsBuildMode())
|
2020-05-13 14:52:21 +00:00
|
|
|
|
foreach (var block in Block.GetLastPlacedBlock().GetConnectedCubes())
|
2020-05-13 12:02:36 +00:00
|
|
|
|
block.Position += new Unity.Mathematics.float3(x, y, z);
|
|
|
|
|
else
|
|
|
|
|
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
|
|
|
|
|
}).Build();
|
2020-05-01 18:50:55 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder()
|
2020-06-18 01:04:40 +00:00
|
|
|
|
.Name("PlaceAluminium")
|
|
|
|
|
.Description("Place a block of aluminium at the given coordinates")
|
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
var block = Block.PlaceNew(BlockIDs.AluminiumCube, new float3(x, y, z));
|
|
|
|
|
Logging.CommandLog("Block placed with type: " + block.Type);
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
2020-05-01 18:50:55 +00:00
|
|
|
|
|
2020-05-22 22:06:49 +00:00
|
|
|
|
CommandBuilder.Builder()
|
|
|
|
|
.Name("PlaceAluminiumLots")
|
|
|
|
|
.Description("Place a lot of blocks of aluminium at the given coordinates")
|
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLog("Starting...");
|
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
for (int i = 0; i < 100; i++)
|
2020-06-18 01:04:40 +00:00
|
|
|
|
for (int j = 0; j < 100; j++)
|
|
|
|
|
Block.PlaceNew(BlockIDs.AluminiumCube, new float3(x + i, y, z + j));
|
2020-05-22 22:06:49 +00:00
|
|
|
|
//Block.Sync();
|
|
|
|
|
sw.Stop();
|
|
|
|
|
Logging.CommandLog("Finished in " + sw.ElapsedMilliseconds + "ms");
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2020-06-18 01:04:40 +00:00
|
|
|
|
Block b = null;
|
2020-05-24 17:29:02 +00:00
|
|
|
|
CommandBuilder.Builder("moveBlockInSim", "Run in build mode first while looking at a block, then in sim to move it up")
|
2020-05-22 22:06:49 +00:00
|
|
|
|
.Action(() =>
|
|
|
|
|
{
|
|
|
|
|
if (b == null)
|
|
|
|
|
{
|
|
|
|
|
b = new Player(PlayerType.Local).GetBlockLookedAt();
|
|
|
|
|
Logging.CommandLog("Block saved: " + b);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-05-24 17:29:02 +00:00
|
|
|
|
Logging.CommandLog("Block moved to: " + (b.GetSimBody().Position += new float3(0, 2, 0)));
|
2020-05-22 22:06:49 +00:00
|
|
|
|
}).Build();
|
2020-05-13 20:52:06 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder("Error", "Throw an error to make sure SimpleCustomCommandEngine's wrapper catches it.")
|
2020-05-19 22:08:02 +00:00
|
|
|
|
.Action(() => { throw new Exception("Error Command always throws an error"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder("ColorBlock",
|
|
|
|
|
"Change color of the block looked at if there's any.")
|
|
|
|
|
.Action<string>(str =>
|
|
|
|
|
{
|
|
|
|
|
if (!Enum.TryParse(str, out BlockColors color))
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLog("Color " + str + " not found! Interpreting as 4 color values.");
|
|
|
|
|
var s = str.Split(' ');
|
|
|
|
|
new Player(PlayerType.Local).GetBlockLookedAt().CustomColor = new float4(float.Parse(s[0]),
|
|
|
|
|
float.Parse(s[1]), float.Parse(s[2]), float.Parse(s[3]));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
new Player(PlayerType.Local).GetBlockLookedAt().Color =
|
2020-06-18 01:04:40 +00:00
|
|
|
|
new BlockColor { Color = color };
|
2020-05-19 22:08:02 +00:00
|
|
|
|
Logging.CommandLog("Colored block to " + color);
|
|
|
|
|
|
|
|
|
|
}).Build();
|
2020-05-22 01:00:33 +00:00
|
|
|
|
|
2020-05-24 17:29:02 +00:00
|
|
|
|
CommandBuilder.Builder("GetBlockByID", "Gets a block based on its object identifier and teleports it up.")
|
|
|
|
|
.Action<char>(ch =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var body in SimBody.GetFromObjectID(ch))
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLog("SimBody: " + body);
|
|
|
|
|
body.Position += new float3(0, 10, 0);
|
2020-05-24 19:55:49 +00:00
|
|
|
|
foreach (var bodyConnectedBody in body.GetConnectedBodies())
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLog("Moving " + bodyConnectedBody);
|
|
|
|
|
bodyConnectedBody.Position += new float3(0, 10, 0);
|
|
|
|
|
}
|
2020-05-24 17:29:02 +00:00
|
|
|
|
}
|
|
|
|
|
}).Build();
|
|
|
|
|
|
2020-07-13 19:55:48 +00:00
|
|
|
|
CommandBuilder.Builder()
|
|
|
|
|
.Name("PlaceConsole")
|
2020-07-18 23:13:39 +00:00
|
|
|
|
.Description("Place a bunch of console block with a given text - entering simulation with them crashes the game as the cmd doesn't exist")
|
2020-07-13 19:55:48 +00:00
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
Stopwatch sw = new Stopwatch();
|
|
|
|
|
sw.Start();
|
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 100; j++)
|
|
|
|
|
{
|
|
|
|
|
var block = Block.PlaceNew<ConsoleBlock>(BlockIDs.ConsoleBlock,
|
|
|
|
|
new float3(x + i, y, z + j));
|
|
|
|
|
block.Command = "test_command";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.Stop();
|
|
|
|
|
Logging.CommandLog($"Blocks placed in {sw.ElapsedMilliseconds} ms");
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
2020-08-03 16:45:38 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder()
|
|
|
|
|
.Name("WireTest")
|
|
|
|
|
.Description("Place two blocks and then wire them together")
|
|
|
|
|
.Action(() =>
|
|
|
|
|
{
|
|
|
|
|
LogicGate notBlock = Block.PlaceNew<LogicGate>(BlockIDs.NOTLogicBlock, new float3(1, 2, 0));
|
|
|
|
|
LogicGate andBlock = Block.PlaceNew<LogicGate>(BlockIDs.ANDLogicBlock, new float3(2, 2, 0));
|
|
|
|
|
// connect NOT Gate output to AND Gate input #2 (ports are zero-indexed, so 1 is 2nd position and 0 is 1st position)
|
|
|
|
|
Wire conn = notBlock.Connect(0, andBlock, 1);
|
|
|
|
|
Logging.CommandLog(conn.ToString());
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
2020-07-13 19:55:48 +00:00
|
|
|
|
|
2020-08-13 14:59:13 +00:00
|
|
|
|
CommandBuilder.Builder("TestChunkHealth", "Sets the chunk looked at to the given health.")
|
|
|
|
|
.Action((float val, float max) =>
|
|
|
|
|
{
|
|
|
|
|
var body = new Player(PlayerType.Local).GetSimBodyLookedAt();
|
|
|
|
|
if (body == null) return;
|
|
|
|
|
body.CurrentHealth = val;
|
|
|
|
|
body.InitialHealth = max;
|
|
|
|
|
Logging.CommandLog("Health set to: " + val);
|
|
|
|
|
}).Build();
|
|
|
|
|
|
2020-11-12 01:39:58 +00:00
|
|
|
|
CommandBuilder.Builder("placeBlockGroup", "Places some blocks in a group")
|
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
var pos = new float3(x, y, z);
|
|
|
|
|
var group = BlockGroup.Create(Block.PlaceNew(BlockIDs.AluminiumCube, pos,
|
|
|
|
|
color: BlockColors.Aqua));
|
|
|
|
|
Block.PlaceNew(BlockIDs.AluminiumCube, pos += new float3(1, 0, 0), color: BlockColors.Blue)
|
|
|
|
|
.BlockGroup = group;
|
|
|
|
|
Block.PlaceNew(BlockIDs.AluminiumCube, pos += new float3(1, 0, 0), color: BlockColors.Green)
|
|
|
|
|
.BlockGroup = group;
|
|
|
|
|
Block.PlaceNew(BlockIDs.AluminiumCube, pos += new float3(1, 0, 0), color: BlockColors.Lime)
|
|
|
|
|
.BlockGroup = group;
|
|
|
|
|
}).Build();
|
|
|
|
|
|
2020-12-17 19:20:46 +00:00
|
|
|
|
CommandBuilder.Builder("placeCustomBlock", "Places a custom block, needs a custom catalog and assets.")
|
|
|
|
|
.Action((float x, float y, float z) =>
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLog("Block placed: " +
|
|
|
|
|
Block.PlaceNew<TestBlock>((BlockIDs) 500, new float3(0, 0, 0)));
|
|
|
|
|
}).Build();
|
|
|
|
|
|
2020-05-22 22:06:49 +00:00
|
|
|
|
GameClient.SetDebugInfo("InstalledMods", InstalledMods);
|
2020-06-02 01:12:40 +00:00
|
|
|
|
Block.Placed += (sender, args) =>
|
|
|
|
|
Logging.MetaDebugLog("Placed block " + args.Type + " with ID " + args.ID);
|
|
|
|
|
Block.Removed += (sender, args) =>
|
|
|
|
|
Logging.MetaDebugLog("Removed block " + args.Type + " with ID " + args.ID);
|
2020-05-01 18:50:55 +00:00
|
|
|
|
|
2020-06-18 01:04:40 +00:00
|
|
|
|
/*
|
2020-02-18 18:59:02 +00:00
|
|
|
|
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
|
|
|
|
|
"SetFOV", "Set the player camera's field of view"));
|
|
|
|
|
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
|
|
|
|
|
(x, y, z) => {
|
|
|
|
|
bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
|
|
|
|
|
GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
|
|
|
|
|
new Unity.Mathematics.float3(x, y, z));
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
|
|
|
|
|
}
|
|
|
|
|
}, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
|
|
|
|
|
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
|
|
|
|
|
(x, y, z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
|
|
|
|
|
"PlaceAluminium", "Place a block of aluminium at the given coordinates"));
|
2020-02-20 01:32:58 +00:00
|
|
|
|
System.Random random = new System.Random(); // for command below
|
|
|
|
|
CommandManager.AddCommand(new SimpleCustomCommandEngine(
|
|
|
|
|
() => {
|
|
|
|
|
if (!GameState.IsSimulationMode())
|
|
|
|
|
{
|
|
|
|
|
Logging.CommandLogError("You must be in simulation mode for this to work!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Tasks.Repeatable task = new Tasks.Repeatable(() => {
|
|
|
|
|
uint count = 0;
|
|
|
|
|
EGID[] eBlocks = Blocks.Signals.GetElectricBlocks();
|
|
|
|
|
for (uint i = 0u; i < eBlocks.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
uint[] ids = Blocks.Signals.GetSignalIDs(eBlocks[i]);
|
|
|
|
|
for (uint j = 0u; j < ids.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
Blocks.Signals.SetSignalByID(ids[j], (float)random.NextDouble());
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Logging.MetaDebugLog($"Did the thing on {count} inputs");
|
|
|
|
|
},
|
|
|
|
|
() => { return GameState.IsSimulationMode(); });
|
|
|
|
|
Tasks.Scheduler.Schedule(task);
|
|
|
|
|
}, "RandomizeSignalsInputs", "Do the thing"));
|
2020-05-01 18:50:55 +00:00
|
|
|
|
*/
|
2020-02-18 18:59:02 +00:00
|
|
|
|
}
|
2020-02-20 01:32:58 +00:00
|
|
|
|
|
2020-06-18 01:04:40 +00:00
|
|
|
|
// dependency test
|
|
|
|
|
if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
|
2020-02-18 18:59:02 +00:00
|
|
|
|
{
|
|
|
|
|
Logging.LogWarning("You're in GamecraftScripting dependency hell");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logging.Log("Compatible GamecraftScripting detected");
|
|
|
|
|
}
|
2020-12-21 21:31:57 +00:00
|
|
|
|
// Interface test
|
2020-12-21 21:57:32 +00:00
|
|
|
|
Interface.IMGUI.Group uiGroup = new Group(new Rect(20, 20, 200, 500), "GamecraftModdingAPI_UITestGroup", true);
|
2020-12-21 21:31:57 +00:00
|
|
|
|
Interface.IMGUI.Button button = new Button("TEST");
|
|
|
|
|
button.OnClick += (b, __) => { Logging.MetaDebugLog($"Click on {((Interface.IMGUI.Button)b).Name}");};
|
|
|
|
|
Interface.IMGUI.Button button2 = new Button("TEST2");
|
|
|
|
|
button2.OnClick += (b, __) => { Logging.MetaDebugLog($"Click on {((Interface.IMGUI.Button)b).Name}");};
|
|
|
|
|
Text uiText = new Text("This is text!", multiline: true);
|
|
|
|
|
uiText.OnEdit += (t, txt) => { Logging.MetaDebugLog($"Text in {((Text)t).Name} is now '{txt}'"); };
|
|
|
|
|
Label uiLabel = new Label("Label!");
|
|
|
|
|
Image uiImg = new Image(name:"Behold this texture!");
|
|
|
|
|
uiImg.Enabled = false;
|
|
|
|
|
uiGroup.AddElement(button);
|
|
|
|
|
uiGroup.AddElement(button2);
|
|
|
|
|
uiGroup.AddElement(uiText);
|
|
|
|
|
uiGroup.AddElement(uiLabel);
|
|
|
|
|
uiGroup.AddElement(uiImg);
|
|
|
|
|
|
|
|
|
|
Addressables.LoadAssetAsync<Texture2D>("Assets/Art/Textures/UI/FrontEndMap/RCX_Blue_Background_5k.jpg")
|
|
|
|
|
.Completed +=
|
|
|
|
|
handle =>
|
|
|
|
|
{
|
|
|
|
|
uiImg.Texture = handle.Result;
|
|
|
|
|
uiImg.Enabled = true;
|
|
|
|
|
Logging.MetaDebugLog($"Got blue bg asset {handle.Result}");
|
|
|
|
|
};
|
2020-12-21 21:57:32 +00:00
|
|
|
|
|
2020-06-14 19:40:47 +00:00
|
|
|
|
|
2020-12-21 21:57:32 +00:00
|
|
|
|
CommandBuilder.Builder("enableCompletions")
|
2020-06-14 19:40:47 +00:00
|
|
|
|
.Action(() =>
|
|
|
|
|
{
|
|
|
|
|
var p = Window.selected.main.parameters;
|
|
|
|
|
p.useCommandCompletion = true;
|
|
|
|
|
p.useMonoCompletion = true;
|
|
|
|
|
p.useGlobalClassCompletion = true;
|
|
|
|
|
Log.Output("Submitted: " + Window.selected.submittedCode);
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
2020-12-17 19:20:46 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CustomBlock.RegisterCustomBlock<TestBlock>();
|
|
|
|
|
Logging.MetaDebugLog("Registered test custom block");
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog("Test custom block catalog not found");
|
|
|
|
|
}
|
2020-06-18 01:04:40 +00:00
|
|
|
|
#if TEST
|
|
|
|
|
TestRoot.RunTests();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2020-12-21 21:31:57 +00:00
|
|
|
|
private string modsString;
|
2020-05-22 22:06:49 +00:00
|
|
|
|
private string InstalledMods()
|
|
|
|
|
{
|
|
|
|
|
if (modsString != null) return modsString;
|
|
|
|
|
StringBuilder sb = new StringBuilder("Installed mods:");
|
|
|
|
|
foreach (var plugin in PluginManager.Plugins)
|
2020-05-24 19:55:49 +00:00
|
|
|
|
sb.Append("\n" + plugin.Name + " - " + plugin.Version);
|
2020-05-22 22:06:49 +00:00
|
|
|
|
return modsString = sb.ToString();
|
2020-05-17 21:23:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 01:04:40 +00:00
|
|
|
|
private bool retry = true;
|
|
|
|
|
|
|
|
|
|
private bool shouldRetry()
|
|
|
|
|
{
|
|
|
|
|
return retry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enterGame()
|
|
|
|
|
{
|
|
|
|
|
App.Client app = new App.Client();
|
|
|
|
|
App.Game[] myGames = app.MyGames;
|
|
|
|
|
Logging.MetaDebugLog($"MyGames count {myGames.Length}");
|
|
|
|
|
if (myGames.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog($"MyGames[0] EGID {myGames[0].EGID}");
|
|
|
|
|
retry = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//myGames[0].Description = "test msg pls ignore"; // make sure game exists first
|
|
|
|
|
Logging.MetaDebugLog($"Entering game {myGames[0].Name}");
|
|
|
|
|
myGames[0].EnterGame();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog($"Failed to enter game; exception: {e}");
|
|
|
|
|
retry = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog("MyGames not populated yet :(");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 18:13:45 +00:00
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
public class MinimumSpecsPatch
|
|
|
|
|
{
|
2020-06-12 15:27:36 +00:00
|
|
|
|
public static bool Prefix()
|
2020-05-17 18:13:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MethodInfo TargetMethod()
|
|
|
|
|
{
|
2020-06-12 15:27:36 +00:00
|
|
|
|
return ((Action) MinimumSpecsCheck.CheckRequirementsMet).Method;
|
2020-05-17 18:13:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-17 19:20:46 +00:00
|
|
|
|
|
|
|
|
|
[CustomBlock("customCatalog.json", "Assets/Prefabs/Cube.prefab", "strAluminiumCube", SortIndex = 12)]
|
|
|
|
|
public class TestBlock : CustomBlock
|
|
|
|
|
{
|
|
|
|
|
public TestBlock(EGID id) : base(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TestBlock(uint id) : base(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|
2020-08-23 13:59:13 +00:00
|
|
|
|
#endif
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|