diff --git a/GamecraftModdingAPI.dll b/GamecraftModdingAPI.dll new file mode 100644 index 0000000..927d0a1 Binary files /dev/null and b/GamecraftModdingAPI.dll differ diff --git a/GamecraftScripting.sln b/GamecraftScripting.sln new file mode 100644 index 0000000..73fb25f --- /dev/null +++ b/GamecraftScripting.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29609.76 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamecraftScripting", "GamecraftScripting\GamecraftScripting.csproj", "{E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {588EB8B7-9ADA-4723-BAC9-04B676A88771} + EndGlobalSection +EndGlobal diff --git a/GamecraftScripting/Commands/DebugCommandEngine.cs b/GamecraftScripting/Commands/DebugCommandEngine.cs new file mode 100644 index 0000000..e5e48a4 --- /dev/null +++ b/GamecraftScripting/Commands/DebugCommandEngine.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GamecraftModdingAPI.Commands; +using GamecraftModdingAPI.Utility; +using Svelto.ECS; + +using IronPython; + +namespace GamecraftScripting.Commands +{ + class DebugCommandEngine : ICustomCommandEngine + { + public string Description { get; } = ""; + + public string Name { get; } = ""; + + public IEntitiesDB entitiesDB { set; private get; } + + public void Dispose() + { + CommandRegistrationHelper.Unregister("IronPythonInfo"); + } + + public void Ready() + { + CommandRegistrationHelper.Register("PythonInfo", ironPythonInfo, "Display Python debug info"); + } + + private void ironPythonInfo() + { + Logging.CommandLog(typeof(PythonOptions).Assembly.GetName().ToString()); + } + } +} diff --git a/GamecraftScripting/Commands/PythonRunnerCommandEngine.cs b/GamecraftScripting/Commands/PythonRunnerCommandEngine.cs new file mode 100644 index 0000000..8e34269 --- /dev/null +++ b/GamecraftScripting/Commands/PythonRunnerCommandEngine.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GamecraftModdingAPI.Commands; +using GamecraftModdingAPI.Utility; +using Svelto.ECS; + +using IronPython.Hosting; +using Microsoft.Scripting.Hosting; + +namespace GamecraftScripting.Commands +{ + class PythonRunnerCommandEngine : ICustomCommandEngine + { + public string Description { get; } = "Runs python scripts"; + + public string Name { get; } = "PythonRunner"; + + public IEntitiesDB entitiesDB { set; private get; } + + private ScriptEngine pythonEngine; + + private ScriptScope gameScope; + + public void Dispose() + { + CommandRegistrationHelper.Unregister("RunPythonScript"); + } + + public void Ready() + { + CommandRegistrationHelper.Register("RunPythonScript", RunPythonScript, "Run a python script stored on your computer"); + this.pythonEngine = Python.CreateEngine(); + this.gameScope = pythonEngine.CreateScope(); + } + + private void RunPythonScript(string scriptPath) + { + pythonEngine.ExecuteFile(scriptPath, gameScope); + } + + public PythonRunnerCommandEngine() + { + Logging.CommandLog($"cwd: {Directory.GetCurrentDirectory()}"); + } + } +} diff --git a/GamecraftScripting/GamecraftScripting.csproj b/GamecraftScripting/GamecraftScripting.csproj new file mode 100644 index 0000000..6fc5a51 --- /dev/null +++ b/GamecraftScripting/GamecraftScripting.csproj @@ -0,0 +1,546 @@ + + + + net48 + true + 0.0.1.0 + Exmods + GNU General Public Licence 3+ + https://git.exmods.org/SnakesOnAGame/GamecraftScripting + en-CA + + + + + + + + + + + + ..\GamecraftModdingAPI.dll + + + ..\..\ref\Gamecraft_Data\Managed\Analytics.dll + + + ..\..\ref\Gamecraft_Data\Managed\Assembly-CSharp-firstpass.dll + + + ..\..\ref\Gamecraft_Data\Managed\Assembly-CSharp.dll + + + ..\..\ref\Gamecraft_Data\Managed\Authentication.dll + + + ..\..\ref\Gamecraft_Data\Managed\BlockEntityFactory.dll + + + ..\..\ref\Gamecraft_Data\Managed\CommandLine.dll + + + ..\..\ref\Gamecraft_Data\Managed\DataLoader.dll + + + ..\..\ref\Gamecraft_Data\Managed\DDNA.dll + + + ..\..\ref\Gamecraft_Data\Managed\Facepunch.Steamworks.Win64.dll + + + ..\..\ref\Gamecraft_Data\Managed\FMOD.dll + + + ..\..\ref\Gamecraft_Data\Managed\FullGame.dll + + + ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll + + + ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Effects.dll + + + ..\..\ref\Gamecraft_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll + + + ..\..\ref\Gamecraft_Data\Managed\GameState.dll + + + ..\..\ref\Gamecraft_Data\Managed\GPUInstancer.dll + + + ..\..\ref\Gamecraft_Data\Managed\Havok.Physics.dll + + + ..\..\ref\Gamecraft_Data\Managed\Havok.Physics.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\HdgRemoteDebugRuntime.dll + + + ..\..\ref\Gamecraft_Data\Managed\IllusionInjector.dll + + + ..\..\ref\Gamecraft_Data\Managed\IllusionPlugin.dll + + + ..\..\ref\Gamecraft_Data\Managed\JWT.dll + + + ..\..\ref\Gamecraft_Data\Managed\LZ4.dll + + + ..\..\ref\Gamecraft_Data\Managed\MultiplayerNetworking.dll + + + ..\..\ref\Gamecraft_Data\Managed\MultiplayerTest.dll + + + ..\..\ref\Gamecraft_Data\Managed\Newtonsoft.Json.dll + + + ..\..\ref\Gamecraft_Data\Managed\RCX.ScreenshotTaker.dll + + + ..\..\ref\Gamecraft_Data\Managed\Rewired_Core.dll + + + ..\..\ref\Gamecraft_Data\Managed\Rewired_Windows.dll + + + ..\..\ref\Gamecraft_Data\Managed\Robocraft.MainGame.AutoEnterSimulation.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.AccountPreferences.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.Ghost.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.Triggers.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Character.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Common.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.ControlsScreen.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Crosshair.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.EntityStreamUtility.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.FrontEnd.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GameSignalHandling.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.DebugDisplay.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.RemoveBlock.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.ScaleGhost.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.SignalLabel.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUIs.WorkshopPrefabs.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Input.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Inventory.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.MachineEditor.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.MainGame.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.MainSimulation.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.MultiplayerInput.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Party.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.PartyGui.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Physics.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.PilotSeat.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Player.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Priority.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Rendering.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Rendering.Mock.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.SaveAndLoad.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.SaveGameDialog.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Serializers.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.Services.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.SignalHandling.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX.StateSync.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX_SpawnPoints.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocraftX_TextBlock.dll + + + ..\..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll + + + ..\..\ref\Gamecraft_Data\Managed\StringFormatter.dll + + + ..\..\ref\Gamecraft_Data\Managed\Svelto.Common.dll + + + ..\..\ref\Gamecraft_Data\Managed\Svelto.ECS.Debugger.dll + + + ..\..\ref\Gamecraft_Data\Managed\Svelto.ECS.dll + + + ..\..\ref\Gamecraft_Data\Managed\Svelto.Services.dll + + + ..\..\ref\Gamecraft_Data\Managed\Svelto.Tasks.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Animation.Rigging.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Burst.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Burst.Unsafe.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Cloud.UserReporting.Client.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Cloud.UserReporting.Plugin.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Collections.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Entities.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Entities.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Entities.Properties.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Entities.StaticTypeRegistry.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Jobs.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Mathematics.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Mathematics.Extensions.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Physics.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Physics.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Postprocessing.Runtime.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Properties.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Rendering.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Core.ShaderLibrary.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.Lightweight.Runtime.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.ResourceManager.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Scenes.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.ScriptableBuildPipeline.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.TextMeshPro.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Timeline.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Transforms.dll + + + ..\..\ref\Gamecraft_Data\Managed\Unity.Transforms.Hybrid.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AccessibilityModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AIModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AndroidJNIModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AnimationModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ARModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AssetBundleModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.AudioModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ClothModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ClusterInputModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ClusterRendererModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.CoreModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.CrashReportingModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.DirectorModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.DSPGraphModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.FileSystemHttpModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.GameCenterModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.GridModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.HotReloadModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ImageConversionModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.IMGUIModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.InputLegacyModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.InputModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.JSONSerializeModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.LocalizationModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ParticleSystemModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.PerformanceReportingModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.Physics2DModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.PhysicsModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ProfilerModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.ScreenCaptureModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.SharedInternalsModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.SpriteMaskModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.SpriteShapeModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.StreamingModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.SubstanceModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TerrainModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TerrainPhysicsModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TextCoreModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TextRenderingModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TilemapModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.TLSModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UI.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UIElementsModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UIModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UmbraModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UNETModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityAnalyticsModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityConnectModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityTestProtocolModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityWebRequestAssetBundleModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityWebRequestModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.VehiclesModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.VFXModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.VideoModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.VRModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.WindModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\UnityEngine.XRModule.dll + + + ..\..\ref\Gamecraft_Data\Managed\uREPL.dll + + + ..\..\ref\Gamecraft_Data\Managed\UserReporting.dll + + + ..\..\ref\Gamecraft_Data\Managed\VisualProfiler.dll + + + + + diff --git a/GamecraftScripting/Plugin.cs b/GamecraftScripting/Plugin.cs new file mode 100644 index 0000000..722123b --- /dev/null +++ b/GamecraftScripting/Plugin.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +using IllusionPlugin; +using UnityEngine; +using GamecraftModdingAPI; +using GamecraftModdingAPI.Commands; + +namespace GamecraftScripting +{ + class Plugin : IEnhancedPlugin + { + public string[] Filter { get; } = new string[] { "Gamecraft" }; + + public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; + + public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + + + public void OnApplicationQuit() + { + Main.Shutdown(); + } + + public void OnApplicationStart() + { + Main.Init(); + // register development commands +#if DEBUG + CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { Application.Quit(); }, "Exit", "Exit the game immediately")); +#endif + // debugging commands + CommandManager.AddCommand(new Commands.DebugCommandEngine()); + // functional commands + CommandManager.AddCommand(new Commands.PythonRunnerCommandEngine()); + } + + public void OnFixedUpdate() { } + + public void OnLateUpdate() { } + + public void OnLevelWasInitialized(int level) { } + + public void OnLevelWasLoaded(int level) { } + + public void OnUpdate() { } + } +} diff --git a/README.md b/README.md index 61a4d2c..930f89e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # GamecraftScripting -Python scripting support for Gamecraft \ No newline at end of file +Python scripting support for Gamecraft + +## Installation +[Follow the official mod installation guide](https://www.exmods.org/guides/install.html) + +## Script Development +GamecraftScripting uses IronPython to run Python 2.7 scripts in the Mono/.NET runtime. + +Resources +- [Python <-> .NET interfacing](https://ironpython.net/documentation/dotnet) +- [Python 2.7 docs](https://docs.python.org/2.7) +- [GamecraftModdingAPI .NET library](https://git.exmods/modtainers/GamecraftModdingAPI) \ No newline at end of file