Browse Source

Create minimum dependency mod starter project

base
NGnius 5 years ago
parent
commit
5b79f8dfba
3 changed files with 9 additions and 53 deletions
  1. +0
    -6
      TestMod/TestMod.csproj
  2. +3
    -18
      TestMod/TestPatch.cs
  3. +6
    -29
      TestMod/TestPlugin.cs

+ 0
- 6
TestMod/TestMod.csproj View File

@@ -9,9 +9,6 @@
</ItemGroup>

<ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\CommandLine.dll</HintPath>
</Reference>
<Reference Include="IllusionPlugin">
<HintPath>..\..\..\IPA\IPA\bin\Debug\IPA\Data\Managed\IllusionPlugin.dll</HintPath>
</Reference>
@@ -21,9 +18,6 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="uREPL">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\RobocraftX_Data\Managed\uREPL.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 3
- 18
TestMod/TestPatch.cs View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using RobocraftX.GUI.CommandLine;
using Harmony;
using UnityEngine;

@@ -13,25 +8,15 @@ namespace TestMod
[HarmonyPatch]
class TestPatch
{
static void Prefix(string name, Action func, string description = "")
static void Prefix()
{
Debug.Log("Registering "+name);
//uREPL.Log.Output("This is an unhelpful message");
Debug.Log("Test Patch Prefix");
}

[HarmonyTargetMethod]
static MethodBase HTargetMethod(HarmonyInstance instance)
{
Type CLUtility = AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility");
MethodInfo[] methods = CLUtility.GetMethods();
foreach (MethodInfo m in methods)
{
if (m.Name == "Register") {
return m;
}
}
Debug.Log("Defaulting to "+methods[0].Name);
return methods[0];
throw new NotImplementedException();
}
}
}

+ 6
- 29
TestMod/TestPlugin.cs View File

@@ -1,7 +1,6 @@
using System;
using IllusionPlugin;
using UnityEngine;
using uREPL;
using Harmony;
using System.Reflection;

@@ -17,27 +16,22 @@ namespace TestMod

public string Version { get; } = "v0.0.0a";

public string HarmonyID { get; } = "org.git.exmods.base.testmod.testplugin";

public void OnApplicationQuit()
{
//throw new NotImplementedException();
harmony.UnpatchAll(HarmonyID);
Debug.Log("TestPlugin shutdown complete");
}

public void OnApplicationStart()
{
Debug.Log("Hello World!");
if (harmony == null)
{
harmony = HarmonyInstance.Create("org.git.exmods.gamecraft.testmod.testplugin");
harmony = HarmonyInstance.Create(HarmonyID);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
MethodInfo commandHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string), typeof(string)});
uREPL.RuntimeCommands.Register<string>("Log", LogCommand, "this description is not shown anywhere");
commandHelp.Invoke(null, new string[] { "Log", "Write a string to Player.log" });
uREPL.RuntimeCommands.Register<string>("Echo", EchoCommand, "this doesn't matter");
commandHelp.Invoke(null, new string[] { "Echo", "Write a message to the command line" });
uREPL.RuntimeCommands.Register("Exit", QuitCommand, "Close Gamecraft");
commandHelp.Invoke(null, new string[] { "Exit", "Forcefully exit Gamecraft immediately" });
Debug.Log("TestPlugin startup complete");
Debug.Log("TestPlugin start & patch complete");
}

public void OnFixedUpdate()
@@ -63,23 +57,6 @@ namespace TestMod
public void OnUpdate()
{
//throw new NotImplementedException();
//UnityEngine.Debug.Log("Baby's first mod injection");
}

/* Log command method. This called by uREPL when the Log <object> command is called from RCX */
private void LogCommand(string msg)
{
Debug.Log(msg);
}

private void EchoCommand(string msg)
{
uREPL.Log.Output(msg);
}

private void QuitCommand()
{
UnityEngine.Application.Quit();
}
}
}