2019-12-13 05:00:11 +00:00
|
|
|
|
using System;
|
2020-05-13 12:02:36 +00:00
|
|
|
|
using System.Linq;
|
2019-12-13 05:00:11 +00:00
|
|
|
|
using System.Reflection;
|
2019-12-16 00:35:59 +00:00
|
|
|
|
|
2020-05-03 19:31:09 +00:00
|
|
|
|
using HarmonyLib;
|
2019-12-25 19:25:53 +00:00
|
|
|
|
// test
|
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using RobocraftX.Blocks;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using RobocraftX.SimulationModeState;
|
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-05-17 18:13:45 +00:00
|
|
|
|
using RobocraftX.FrontEnd;
|
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
|
|
|
|
{
|
|
|
|
|
// 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>
|
2019-12-14 18:52:24 +00:00
|
|
|
|
public class GamecraftModdingAPIPluginTest
|
|
|
|
|
#if DEBUG
|
|
|
|
|
: IllusionPlugin.IEnhancedPlugin
|
|
|
|
|
#endif
|
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-02-18 18:59:02 +00:00
|
|
|
|
public string[] Filter { get; } = new string[] { "Gamecraft", "GamecraftPreview" };
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2019-12-14 18:52:24 +00:00
|
|
|
|
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
|
2019-12-13 05:00:11 +00:00
|
|
|
|
|
2019-12-14 18:52:24 +00:00
|
|
|
|
public 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";
|
|
|
|
|
|
|
|
|
|
public void OnApplicationQuit()
|
|
|
|
|
{
|
2019-12-14 04:42:55 +00:00
|
|
|
|
GamecraftModdingAPI.Main.Shutdown();
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnApplicationStart()
|
|
|
|
|
{
|
2020-04-07 17:05:00 +00:00
|
|
|
|
FileLog.Reset();
|
2020-05-03 19:31:09 +00:00
|
|
|
|
Harmony.DEBUG = true;
|
2019-12-14 04:42:55 +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
|
|
|
|
|
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-04-29 01:56:34 +00:00
|
|
|
|
Utility.VersionTracking.Enable();
|
|
|
|
|
|
2020-05-14 02:34:26 +00:00
|
|
|
|
// debug/test handlers
|
|
|
|
|
HandlerBuilder.Builder()
|
|
|
|
|
.Name("appinit API debug")
|
|
|
|
|
.Handle(EventType.ApplicationInitialized)
|
|
|
|
|
.OnActivation(() => { Logging.Log("App Inited event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menuact API debug")
|
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Menu Activated event!"); })
|
|
|
|
|
.OnDestruction(() => { Logging.Log("Menu Destroyed event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menuswitch API debug")
|
|
|
|
|
.Handle(EventType.MenuSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Menu Switched To event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gameact API debug")
|
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Activated event!"); })
|
|
|
|
|
.OnDestruction(() => { Logging.Log("Game Destroyed event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gamerel API debug")
|
|
|
|
|
.Handle(EventType.GameReloaded)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Reloaded event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("gameswitch API debug")
|
|
|
|
|
.Handle(EventType.GameSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Switched To event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("simulationswitch API debug")
|
|
|
|
|
.Handle(EventType.SimulationSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Mode Simulation Switched To event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("buildswitch API debug")
|
|
|
|
|
.Handle(EventType.BuildSwitchedTo)
|
|
|
|
|
.OnActivation(() => { Logging.Log("Game Mode Build Switched To event!"); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
HandlerBuilder.Builder("menu activated API error thrower test")
|
|
|
|
|
.Handle(EventType.Menu)
|
|
|
|
|
.OnActivation(() => { throw new Exception("Event Handler always throws an exception!"); })
|
|
|
|
|
.Build();
|
2020-05-13 20:52:06 +00:00
|
|
|
|
|
2019-12-15 07:20:20 +00:00
|
|
|
|
// 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()
|
|
|
|
|
.Name("Exit")
|
|
|
|
|
.Description("Close Gamecraft immediately, without any prompts")
|
|
|
|
|
.Action(() => { UnityEngine.Application.Quit(); })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder()
|
|
|
|
|
.Name("SetFOV")
|
|
|
|
|
.Description("Set the player camera's field of view")
|
|
|
|
|
.Action((float d) => { UnityEngine.Camera.main.fieldOfView = d; })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
.Name("PlaceAluminium")
|
|
|
|
|
.Description("Place a block of aluminium at the given coordinates")
|
2020-05-13 12:02:36 +00:00
|
|
|
|
.Action((float x, float y, float z) => { Block.PlaceNew(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); })
|
2020-05-01 18:50:55 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
System.Random random = new System.Random(); // for command below
|
|
|
|
|
CommandBuilder.Builder()
|
|
|
|
|
.Name("RandomizeSignalsInputs")
|
|
|
|
|
.Description("Do the thing")
|
|
|
|
|
.Action(() => {
|
|
|
|
|
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);
|
|
|
|
|
}).Build();
|
2020-05-13 14:52:21 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder("getBlock")
|
|
|
|
|
.Action(() => uREPL.Log.Output(new Player(Players.PlayerType.Local).GetBlockLookedAt()+"")).Build();
|
2020-05-13 20:52:06 +00:00
|
|
|
|
|
|
|
|
|
CommandBuilder.Builder("Error", "Throw an error to make sure SimpleCustomCommandEngine's wrapper catches it.")
|
|
|
|
|
.Action(() => { throw new Exception("Error Command always throws an error"); })
|
|
|
|
|
.Build();
|
2020-05-01 18:50:55 +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
|
|
|
|
|
|
|
|
|
// dependency test
|
2020-02-18 18:59:02 +00:00
|
|
|
|
if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
|
|
|
|
|
{
|
|
|
|
|
Logging.LogWarning("You're in GamecraftScripting dependency hell");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logging.Log("Compatible GamecraftScripting detected");
|
|
|
|
|
}
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFixedUpdate() { }
|
|
|
|
|
|
|
|
|
|
public void OnLateUpdate() { }
|
|
|
|
|
|
|
|
|
|
public void OnLevelWasInitialized(int level) { }
|
|
|
|
|
|
|
|
|
|
public void OnLevelWasLoaded(int level) { }
|
|
|
|
|
|
2020-01-04 01:04:55 +00:00
|
|
|
|
public void OnUpdate() { }
|
2020-05-17 18:13:45 +00:00
|
|
|
|
|
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
public class MinimumSpecsPatch
|
|
|
|
|
{
|
|
|
|
|
public static bool Prefix(ref bool __result)
|
|
|
|
|
{
|
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MethodInfo TargetMethod()
|
|
|
|
|
{
|
|
|
|
|
return ((Func<bool>)MinimumSpecsCheck.CheckRequirementsMet).Method;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-13 05:00:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|