Copied DC code over, converted project, fixes

This commit is contained in:
Norbi Peti 2019-12-05 00:07:20 +01:00
parent 04233dffa0
commit ef380a03bc
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 97 additions and 17 deletions

1
GCDC/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
ref

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GCDC</RootNamespace>
<AssemblyName>GCDC</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFramework>netstandard20</TargetFramework>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ -44,6 +44,9 @@
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>ref\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Robocraft.MainGame.AutoEnterSimulation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>ref\Robocraft.MainGame.AutoEnterSimulation.dll</HintPath>
</Reference>
@ -202,19 +205,14 @@
<HintPath>ref\uREPL.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DiscordEngineInjectionPatch.cs" />
<Compile Include="GCDCPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextBlockUpdateEngine.cs" />
</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" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
<Target Name="BeforeBuild">

View file

@ -4,11 +4,7 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GCDC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GCDC")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -31,5 +27,3 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -1,5 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RobocraftX.Blocks.GUI;
using RobocraftX.Common;
using RobocraftX.Common.Input;
@ -9,14 +18,86 @@ using RobocraftX.StateSync;
using Svelto.ECS;
using Svelto.ECS.Experimental;
using Unity.Jobs;
using UnityEngine.Diagnostics;
using uREPL;
namespace GCDC
{
public class TextBlockUpdateEngine : IQueryingEntitiesEngine, IEngine, IDeterministicSim
public class TextBlockUpdateEngine : IQueryingEntitiesEngine, IDeterministicSim, IInitializeOnBuildStart
{
private DiscordSocketClient _client;
public void Ready()
{
try
{
/*Console.WriteLine("Current directory: " + Environment.CurrentDirectory);
Console.WriteLine(Assembly.LoadFrom("Discord.Net.WebSocket.dll")?.DefinedTypes?.Select(t => t.FullName)
.Aggregate((a, b) => a + "\n" + b));*/ //Spent a couple hours trying to figure out why it doesn't even load anymore - somehow I got a completely different System.Collections.Immutable.dll
if (!RuntimeCommands.HasRegistered("dc"))
RuntimeCommands.Register<string>("dc", AddMessage);
Start();
}
catch (TypeLoadException e)
{
Console.WriteLine("Type load exception for type: "+e.TypeName);
Console.WriteLine(e);
}
}
private void Start()
{
_client=new DiscordSocketClient(new DiscordSocketConfig()
{
LogLevel = LogSeverity.Debug,
DefaultRetryMode = RetryMode.RetryRatelimit
});
_client.Log += msg=>
{
Log.Output(msg.Message);
//Window.selected.OutputLog(new Log.Data(msg.Message, "Discord", Log.Level.Verbose));
return Task.CompletedTask;
};
Setup();
}
private async void Setup()
{
try
{
const string path = "discordToken.json";
const string notoken =
"Please add your bot token to the discordToken.json file in game files and run this again.";
if (!File.Exists(path))
{
var obj = new JObject {["token"] = "Put your token here"};
File.WriteAllText(path, obj.ToString());
Log.Error(notoken);
return;
}
string token;
try
{
token = (string) JObject.Parse(File.ReadAllText(path))["token"];
if (token.Contains(" "))
{
Log.Error(notoken);
return;
}
}
catch (JsonReaderException exception)
{
Log.Error("Failed to read token! " + exception);
return;
}
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
public IEntitiesDB entitiesDB { get; set; }
@ -45,5 +126,11 @@ namespace GCDC
messages.Dequeue();
updatedTextBlock = false;
}
public JobHandle OnInitializeBuildMode()
{
updatedTextBlock = false; //Update text block
return new JobHandle();
}
}
}