Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
3b5888fbf7 | |||
8d2d11b736 | |||
eb78bd61e3 | |||
e66548b516 |
5 changed files with 120 additions and 169 deletions
|
@ -4,41 +4,29 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Mime;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using GamecraftModdingAPI.Utility;
|
||||
using GamecraftModdingAPI.Engines;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RobocraftX.Common;
|
||||
using RobocraftX.Common.Input;
|
||||
using RobocraftX.Common.Utilities;
|
||||
using RobocraftX.SimulationModeState;
|
||||
using RobocraftX.StateSync;
|
||||
using Svelto.ECS;
|
||||
using Svelto.ECS.Experimental;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Diagnostics;
|
||||
using uREPL;
|
||||
|
||||
namespace GCDC
|
||||
{
|
||||
public class TextBlockUpdateEngine : IDeterministicSim, IInitializeOnBuildStart, IApiEngine
|
||||
public class DiscordClient
|
||||
{
|
||||
private string _token;
|
||||
private bool _running;
|
||||
private Thread _rect;
|
||||
private readonly Queue<string> messages = new Queue<string>();
|
||||
private readonly GCDCPlugin plugin;
|
||||
public DiscordClient(GCDCPlugin plugin) => this.plugin = plugin;
|
||||
public void Ready()
|
||||
{
|
||||
if (!RuntimeCommands.HasRegistered("dc"))
|
||||
RuntimeCommands.Register<string>("dc", SendMessage);
|
||||
if (!RuntimeCommands.HasRegistered("dcsetup"))
|
||||
RuntimeCommands.Register<string>("dcsetup", Setup,
|
||||
"Initial setup for GCDC. The argument is the channel ID first.");
|
||||
if (File.Exists("gcdc.json"))
|
||||
{
|
||||
var jo = JObject.Load(new JsonTextReader(File.OpenText("gcdc.json")));
|
||||
|
@ -69,7 +57,7 @@ namespace GCDC
|
|||
{
|
||||
try
|
||||
{
|
||||
if (JObject.Parse(WebUtils.Request("users/get?token=" + tokenOrChannel))["response"].Value<string>() == "OK")
|
||||
if (JObject.Parse(WebUtils.Request("users/get?token=" + tokenOrChannel))["response"]?.Value<string>() == "OK")
|
||||
{
|
||||
_token = tokenOrChannel;
|
||||
var jo = new JObject {["token"] = tokenOrChannel};
|
||||
|
@ -101,8 +89,7 @@ namespace GCDC
|
|||
{
|
||||
var parameters = "token=" + _token + "&message=" + message;
|
||||
var resp = JObject.Parse(WebUtils.Request("messages/send?" + parameters, ""));
|
||||
if (resp["response"]
|
||||
.Value<string>() == "OK")
|
||||
if (resp["response"]?.Value<string>() == "OK")
|
||||
{
|
||||
AddMessage("<nobr><" + resp["username"] + "> " + message);
|
||||
Log.Output("Message sent");
|
||||
|
@ -145,45 +132,20 @@ namespace GCDC
|
|||
_rect.Start();
|
||||
}
|
||||
|
||||
public EntitiesDB entitiesDB { get; set; }
|
||||
public string name { get; } = "GCDC-TextUpdate";
|
||||
private volatile Queue<string> messages = new Queue<string>();
|
||||
private volatile bool updatedTextBlock;
|
||||
|
||||
public JobHandle SimulatePhysicsStep(
|
||||
in float deltaTime,
|
||||
in PhysicsUtility utility,
|
||||
in PlayerInput[] playerInputs) //Gamecraft.Blocks.ConsoleBlock.dll
|
||||
{
|
||||
if (updatedTextBlock)
|
||||
return new JobHandle();
|
||||
var txt = messages.Count > 0 ? messages.Aggregate((current, msg) => current + "\n" + msg) : "<No messages yet>";
|
||||
RuntimeCommands.Call("ChangeTextBlockCommand", "Discord", txt);
|
||||
updatedTextBlock = true;
|
||||
|
||||
return new JobHandle();
|
||||
}
|
||||
|
||||
public void AddMessage(string message)
|
||||
{
|
||||
messages.Enqueue(message);
|
||||
if (messages.Count > 10)
|
||||
messages.Dequeue();
|
||||
updatedTextBlock = false;
|
||||
plugin.Update(messages);
|
||||
}
|
||||
|
||||
public JobHandle OnInitializeBuildMode()
|
||||
{
|
||||
updatedTextBlock = false; //Update text block
|
||||
return new JobHandle();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Stop()
|
||||
{
|
||||
_running = false;
|
||||
_rect.Interrupt();
|
||||
}
|
||||
|
||||
public string Name { get; } = "GCDCEngine";
|
||||
public void Update() => plugin.Update(messages);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Gamecraft.Blocks.ConsoleBlock;
|
||||
using Harmony;
|
||||
using RobocraftX;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.Services.MultiplayerNetworking;
|
||||
using RobocraftX.StateSync;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GCDC
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class DiscordEngineInjectionPatch
|
||||
{
|
||||
static void Postfix(EnginesRoot enginesRoot, in StateSyncRegistrationHelper stateSyncReg, bool isAuthoritative)
|
||||
{
|
||||
if (isAuthoritative)
|
||||
{
|
||||
stateSyncReg.AddDeterministicEngine(new TextBlockUpdateEngine());
|
||||
Debug.Log($"Added Discord text block update engine");
|
||||
}
|
||||
else
|
||||
Debug.Log("Not authoritative, not adding Discord engine");
|
||||
}
|
||||
|
||||
static MethodBase TargetMethod(HarmonyInstance instance)
|
||||
{
|
||||
return _ComposeMethodInfo(ConsoleBlockCompositionRoot.Compose);
|
||||
}
|
||||
|
||||
private delegate void ComposeAction(EnginesRoot er, in StateSyncRegistrationHelper ssrh,
|
||||
NetworkReceivers networkReceivers, NetworkSender networkSende, bool isAuthoritative);
|
||||
private static MethodInfo _ComposeMethodInfo(ComposeAction a)
|
||||
{
|
||||
return a.Method;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
124
GCDC/GCDC.csproj
124
GCDC/GCDC.csproj
|
@ -9,8 +9,13 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GCDC</RootNamespace>
|
||||
<AssemblyName>GCDC</AssemblyName>
|
||||
<TargetFramework>netstandard20</TargetFramework>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
<ProductVersion>0.0.2.0</ProductVersion>
|
||||
<Product>GCDC</Product>
|
||||
<ProductName>GCDC</ProductName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -33,179 +38,170 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BlockEntityFactory, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\BlockEntityFactory.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\BlockEntityFactory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="CommandLine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\CommandLine.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DataLoader, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\DataLoader.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\DataLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FullGame, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\FullGame.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\FullGame.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Gamecraft.Blocks.ConsoleBlock, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Gamecraft.Blocks.ConsoleBlock.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="GamecraftModdingAPI, Version=0.2.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<Reference Include="GamecraftModdingAPI">
|
||||
<HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\GamecraftModdingAPI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>IllusionPlugin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MultiplayerNetworking, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\MultiplayerNetworking.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\MultiplayerNetworking.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.1.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.AccountPreferences, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.AccountPreferences.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.AccountPreferences.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Blocks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Blocks.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Blocks.Ghost, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Blocks.Ghost.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.Ghost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Blocks.Triggers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Blocks.Triggers.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Blocks.Triggers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Character, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Character.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Character.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Common.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Crosshair, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Crosshair.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Crosshair.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.FrontEnd, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.FrontEnd.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.FrontEnd.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.GUI, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.GUI.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.GUI.DebugDisplay, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.GUI.DebugDisplay.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.DebugDisplay.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.GUI.RemoveBlock, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.GUI.RemoveBlock.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.RemoveBlock.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.GUI.ScaleGhost, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.GUI.ScaleGhost.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUI.ScaleGhost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.GUIs.WorkshopPrefabs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.GUIs.WorkshopPrefabs.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.GUIs.WorkshopPrefabs.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Input, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Input.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Input.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.MachineEditor.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.MachineEditor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.MainGame, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.MainGame.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.MainGame.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.MainSimulation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.MainSimulation.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.MainSimulation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Multiplayer, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Multiplayer.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Multiplayer.NetworkEntityStream, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.MultiplayerInput, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.MultiplayerInput.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.MultiplayerInput.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Party, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Party.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Party.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.PartyGui, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.PartyGui.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.PartyGui.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Physics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Physics.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Physics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.PilotSeat, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.PilotSeat.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.PilotSeat.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Player, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Player.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Player.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Rendering, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Rendering.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Rendering.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Rendering.Mock, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Rendering.Mock.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Rendering.Mock.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.SaveAndLoad, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.SaveAndLoad.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.SaveAndLoad.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.SaveGameDialog, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.SaveGameDialog.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.SaveGameDialog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Serializers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Serializers.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Serializers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Services, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.Services.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Services.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.SignalHandling, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.SignalHandling.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.SignalHandling.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.StateSync, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX.StateSync.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.StateSync.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX_SpawnPoints, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX_SpawnPoints.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX_SpawnPoints.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX_TextBlock, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocraftX_TextBlock.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX_TextBlock.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocratX.SimulationCompositionRoot, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\RobocratX.SimulationCompositionRoot.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Svelto.ECS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Svelto.ECS.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Svelto.ECS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Svelto.Tasks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Svelto.Tasks.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Svelto.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Unity.Entities.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Unity.Entities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Mathematics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Unity.Mathematics.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Unity.Mathematics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Physics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\Unity.Physics.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\Unity.Physics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\UnityEngine.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\UnityEngine.CoreModule.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="uREPL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ref\uREPL.dll</HintPath>
|
||||
<HintPath>..\..\ref\Gamecraft_Data\Managed\uREPL.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="IllusionPlugin.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net.Core" Version="2.1.1" />
|
||||
<PackageReference Include="Discord.Net.WebSocket" Version="2.1.1" />
|
||||
<PackageReference Include="Lib.Harmony" Version="1.2.0.1" />
|
||||
<PackageReference Include="Lib.Harmony" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -1,31 +1,55 @@
|
|||
using System.Reflection;
|
||||
using Harmony;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using GamecraftModdingAPI.App;
|
||||
using GamecraftModdingAPI.Commands;
|
||||
using IllusionPlugin;
|
||||
using RobocraftX.Schedulers;
|
||||
using Svelto.Tasks.ExtraLean;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
|
||||
namespace GCDC
|
||||
{
|
||||
public class GCDCPlugin : IPlugin
|
||||
{
|
||||
public string Name { get; } = "GCDC";
|
||||
public string Version { get; } = "v0.0.1";
|
||||
public static HarmonyInstance harmony { get; protected set; }
|
||||
public const string HarmonyID = "io.github.norbipeti.GCDC";
|
||||
|
||||
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
|
||||
public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
||||
public void OnApplicationStart()
|
||||
{
|
||||
if (harmony == null)
|
||||
{
|
||||
harmony = HarmonyInstance.Create(HarmonyID);
|
||||
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
GamecraftModdingAPI.Main.Init();
|
||||
var client = new DiscordClient(this);
|
||||
CommandBuilder.Builder("dc", "Send messages to Discord.")
|
||||
.Action<string>(client.SendMessage).Build();
|
||||
CommandBuilder.Builder("dcsetup", "Initial setup for GCDC. The argument is the channel ID first. For example: dcsetup \"420159832423923714\"")
|
||||
.Action<string>(client.Setup).Build();
|
||||
Game.Enter += (sender, e) =>
|
||||
client.Ready();
|
||||
Game.Edit += (sender, e) =>
|
||||
client.Update(); //Update text block
|
||||
Game.Exit += (sender, e) =>
|
||||
client.Stop();
|
||||
Debug.Log("GCDC loaded");
|
||||
}
|
||||
|
||||
public void Update(Queue<string> messages)
|
||||
{
|
||||
UpdateEnum(messages).RunOn(ExtraLean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING);
|
||||
}
|
||||
|
||||
private IEnumerator UpdateEnum(Queue<string> messages)
|
||||
{
|
||||
var txt = messages.Count > 0
|
||||
? messages.Aggregate((current, msg) => current + "\n" + msg)
|
||||
: "<No messages yet>";
|
||||
RuntimeCommands.Call("ChangeTextBlockCommand", "Discord", txt);
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void OnApplicationQuit()
|
||||
{
|
||||
harmony?.UnpatchAll(HarmonyID);
|
||||
}
|
||||
|
||||
public void OnLevelWasLoaded(int level)
|
||||
|
|
12
README.md
Normal file
12
README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# GCDC
|
||||
A mod for Gamecraft-Discord chat connection using commands and text blocks.
|
||||
|
||||
## First-time setup
|
||||
First invite the Discord bot to your server using [this link](https://discord.com/oauth2/authorize?client_id=680138144812892371&scope=bot) and make sure it has access to the channel you want to use. Then open the console in Gamecraft (`/` or the key near right shift by default) and do `dcsetup "channelid"` with the quotes. The channel ID can be obtained by enabling developer mode in Discord in User Settings -> Appearance and then right clicking the channel and clicking Copy ID.
|
||||
|
||||
When that is done, a browser window will open, asking you to give access to the Discord bot. This is only used to get basic info like your username to be displayed when you talk from the game and to avoid someone filling the database with junk. Also due to that, currently you can only have one channel linked at a time.
|
||||
|
||||
When you're logged in, the page will show a command to run in Gamecraft (it should be another `dcsetup` with a different argument). Then the initial setup is done.
|
||||
|
||||
## Usage
|
||||
To send messages to Discord, use `dc "message"` with your message inside the quotes. To receive messages, place a text block named Discord. It will automatically update once messages are sent on Discord.
|
Loading…
Reference in a new issue