Browse Source

Implement CRF robot importer and import framework

tags/v0.0.1
NGnius (Graham) 3 years ago
parent
commit
3a196e18bf
6 changed files with 101 additions and 18 deletions
  1. +1
    -1
      NPort/API/SimpleImporter.cs
  2. +1
    -1
      NPort/Importers/RobocraftFactoryImporter.cs
  3. +56
    -0
      NPort/Installer/Updater.cs
  4. +15
    -0
      NPort/Installer/Utility.cs
  5. +7
    -11
      NPort/NPort.csproj
  6. +21
    -5
      NPort/NPortPlugin.cs

+ 1
- 1
NPort/API/SimpleImporter.cs View File

@@ -30,7 +30,7 @@ namespace NPort.API
Block placedBlock = Block.PlaceNew(type, position);
placedBlock.Color = colour;
placedBlock.Rotation = rotation;
//placedBlock.Material = material;
placedBlock.Material = material;
}

public abstract bool SimpleImport(string[] args);


+ 1
- 1
NPort/Importers/RobocraftFactoryImporter.cs View File

@@ -49,7 +49,7 @@ namespace NPort.Importers
float3 rotation = TranslateBlockRotation(cube.orientation);
float3 position = new float3(cube.x - BAY_CENTER, cube.y - 8f , cube.z - BAY_CENTER);
BlockColor colour = QuantizeToBlockColor(cube.colour);
PlaceBlock(BlockIDs.Cube, position * 0.2f, rotation, colour, BlockMaterial.SteelBodywork);
PlaceBlock(BlockIDs.Cube, position * 0.2f, rotation, colour, BlockMaterial.RigidSteel);
//break;
}
return true;


+ 56
- 0
NPort/Installer/Updater.cs View File

@@ -0,0 +1,56 @@
using System.Security.Cryptography;
using System.IO;

namespace NPort.Installer
{
// if I could statically link libfj inside this DLL, this would not need to exist
public class Updater
{
internal static void CheckForUpdate()
{
// calculate checksums
string newChecksum;
using (Stream f = Utility.GetEmbeddedLibFj())
{
newChecksum = Checksum(f);
}
string oldChecksum = "";
if (File.Exists(Utility.LIBFJ_INSTALL_PATH))
{
using (Stream f = File.OpenRead(Utility.LIBFJ_INSTALL_PATH))
{
oldChecksum = Checksum(f);
}
}

if (newChecksum != oldChecksum)
{
// update required
using (Stream outfile = File.Create(Utility.LIBFJ_INSTALL_PATH))
{
using (Stream resource = Utility.GetEmbeddedLibFj())
{
resource.CopyTo(outfile);
}
}
}
}

internal static void Remove()
{
if (File.Exists(Utility.LIBFJ_INSTALL_PATH))
{
File.Delete(Utility.LIBFJ_INSTALL_PATH);
}
}

private static string Checksum(Stream stream)
{
using (MD5 md5 = MD5.Create())
{
return System.Convert.ToBase64String(md5.ComputeHash(stream));
}
}
}
}

+ 15
- 0
NPort/Installer/Utility.cs View File

@@ -0,0 +1,15 @@
using System.IO;
using System.Reflection;

namespace NPort.Installer
{
public static class Utility
{
public const string LIBFJ_RESOURCE_NAME = "NPort.libfj.dll";

public const string LIBFJ_INSTALL_PATH = "TechbloxPreview_Data/Plugins/x86_64/libfj.dll";

public static Stream GetEmbeddedLibFj() =>
Assembly.GetExecutingAssembly().GetManifestResourceStream(LIBFJ_RESOURCE_NAME);
}
}

+ 7
- 11
NPort/NPort.csproj View File

@@ -485,10 +485,6 @@
<HintPath>..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.Inventory.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.Inventory.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.RemoveBlock">
<HintPath>..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.RemoveBlock.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.RemoveBlock.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.ScaleGhost">
<HintPath>..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.ScaleGhost.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\RobocraftX.GUI.ScaleGhost.dll</HintPath>
@@ -653,10 +649,6 @@
<HintPath>..\ref\TechbloxPreview_Data\Managed\Techblox.InputCapture.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\Techblox.InputCapture.dll</HintPath>
</Reference>
<Reference Include="Techblox.MouseCursor">
<HintPath>..\ref\TechbloxPreview_Data\Managed\Techblox.MouseCursor.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\Techblox.MouseCursor.dll</HintPath>
</Reference>
<Reference Include="Techblox.SwitchAnimation">
<HintPath>..\ref\TechbloxPreview_Data\Managed\Techblox.SwitchAnimation.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\Techblox.SwitchAnimation.dll</HintPath>
@@ -1082,9 +1074,13 @@
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\VisualProfiler.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Installer" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="../clibfj/libfj.dll" />
</ItemGroup>
<!--End Dependencies-->

<Target Name="BuildLibfj" BeforeTargets="CoreCompile">
<Exec Command="cd ../clibfj &amp;&amp; ./release.sh" />
</Target>

</Project>

+ 21
- 5
NPort/NPortPlugin.cs View File

@@ -1,4 +1,5 @@
using System.Reflection;
using System.Linq;
using System.Reflection;

using IllusionPlugin;
using TechbloxModdingAPI.Utility;
@@ -14,11 +15,19 @@ namespace NPort

public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();

private bool _isEditingCache = false;

// called when Gamecraft shuts down
public override void OnApplicationQuit()
{
// Shutdown this mod
Logging.LogDebug($"{Name} has shutdown");
string[] args = System.Environment.GetCommandLineArgs();
if (args.Contains("-nport-uninstall") || args.Contains("-unfuckify"))
{
Installer.Updater.Remove();
}

Logging.LogDebug($"{Name} has shutdown");

// Shutdown the Gamecraft modding API last
Main.Shutdown();
@@ -27,12 +36,16 @@ namespace NPort
// called when Gamecraft starts up
public override void OnApplicationStart()
{
// Initialize the Gamecraft modding API first
// Initialize the Gamecraft modding API first
Main.Init();
// check out the modding API docs here: https://mod.exmods.org/

// Initialize this mod

Installer.Updater.CheckForUpdate(); // install/update libfj.dll
TechbloxModdingAPI.App.Game.Enter += (sender, args) => { this._isEditingCache = true; };
TechbloxModdingAPI.App.Game.Edit += (sender, args) => { this._isEditingCache = true; };
TechbloxModdingAPI.App.Game.Simulate += (sender, args) => { this._isEditingCache = false; };
TechbloxModdingAPI.App.Game.Exit += (sender, args) => { this._isEditingCache = false; };
Logging.MetaLog($"{Name} has started up");
#if DEBUG
// TEST
@@ -53,7 +66,8 @@ namespace NPort
private string[] _argNames = { };

public override void OnGUI()
{
{
if (!this._isEditingCache) return;
#if DEBUG
// testing
if (GUILayout.Button("Get PIG!!! OINK!"))
@@ -67,6 +81,8 @@ namespace NPort
_selectedItem = GUILayout.Toolbar(_selectedItem, API.ImportRegistry.Names);
if (_selectedItem >= 0)
{
// show help message
GUILayout.Box(API.ImportRegistry.Help(_selectedItem), GUILayout.MinWidth(128f), GUILayout.ExpandHeight(true));
// get arguments for selected importer
_argNames = API.ImportRegistry.Args(_selectedItem);
// grow/shrink _argCache when needed


Loading…
Cancel
Save