Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c283059106 | ||
![]() |
422963517f | ||
![]() |
d2ac0e44be | ||
![]() |
c5acf61f7c | ||
![]() |
197d04a661 | ||
![]() |
99ab7d0eea | ||
![]() |
17f97af52f | ||
![]() |
ed7c897bd2 | ||
![]() |
e4d3c3987f | ||
![]() |
067d8802b6 | ||
![]() |
8f32f64ede | ||
![]() |
90ff3f93f0 | ||
![]() |
ad28b302f9 | ||
![]() |
a0d0976a6a |
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
@@ -8,7 +8,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: windows-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ github.ref_name }}
|
VERSION: ${{ github.ref_name }}
|
||||||
BUILD_CONFIGURATION: Release
|
BUILD_CONFIGURATION: Release
|
||||||
@@ -45,6 +45,8 @@ jobs:
|
|||||||
uses: mikepenz/release-changelog-builder-action@v3
|
uses: mikepenz/release-changelog-builder-action@v3
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
commitMode: true
|
||||||
- name: Create release
|
- name: Create release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
@@ -70,4 +72,4 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
id: ${{ steps.create_release.outputs.id }}
|
id: ${{ steps.create_release.outputs.id }}
|
||||||
|
12
README.md
12
README.md
@@ -12,7 +12,10 @@ Torch is the successor to SE Server Extender and gives server admins the tools t
|
|||||||
|
|
||||||
### Fork Difference
|
### Fork Difference
|
||||||
* .NET 6.0 runtime
|
* .NET 6.0 runtime
|
||||||
* Additional options & features
|
* Optimized in-game scripts (also newer compiler & language versions)
|
||||||
|
* Better configuration via cli arguments, environment variables or xml config
|
||||||
|
* Designed to run multiple instance from same install directory without having you to waste disk space
|
||||||
|
* Mostly compatible with original torch's plugins
|
||||||
|
|
||||||
### Discord
|
### Discord
|
||||||
|
|
||||||
@@ -21,10 +24,13 @@ If you have any questions or issues please join our [discord](https://discord.gg
|
|||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
* Unzip the Torch release into its own directory and run the executable. It will automatically download the SE DS and generate the other necessary files.
|
* Unzip the Torch release into its own directory and run the executable. It will automatically download the SE DS and generate the other necessary files.
|
||||||
- If you already have a DS installed you can unzip the Torch files into the folder that contains the DedicatedServer64 folder.
|
- If you already have a DS installed you can:
|
||||||
|
* Unzip the Torch files into the folder that contains the DedicatedServer64 folder.
|
||||||
|
* Pass path to game files using config parameter `gamePath`
|
||||||
|
|
||||||
# Building
|
# Building
|
||||||
To build Torch you must first have a complete SE Dedicated installation somewhere. Before you open the solution, run the Setup batch file and enter the path of that installation's DedicatedServer64 folder. The script will make a symlink to that folder so the Torch solution can find the DLL references it needs.
|
|
||||||
|
As a regular dotnet project with cli by running `dotnet build Torch.Server/Torch.Server.csproj`, with VS 2022 or higher, with JB Rider or Fleet.
|
||||||
|
|
||||||
If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon. (https://www.patreon.com/TorchSE)
|
If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon. (https://www.patreon.com/TorchSE)
|
||||||
|
|
||||||
|
@@ -31,6 +31,23 @@ namespace Torch
|
|||||||
int FontSize { get; set; }
|
int FontSize { get; set; }
|
||||||
UGCServiceType UgcServiceType { get; set; }
|
UGCServiceType UgcServiceType { get; set; }
|
||||||
bool EntityManagerEnabled { get; set; }
|
bool EntityManagerEnabled { get; set; }
|
||||||
|
string LoginToken { get; set; }
|
||||||
|
UpdateSource UpdateSource { get; set; }
|
||||||
|
|
||||||
void Save(string path = null);
|
void Save(string path = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UpdateSource
|
||||||
|
{
|
||||||
|
public UpdateSourceType SourceType { get; set; }
|
||||||
|
public string Url { get; set; }
|
||||||
|
public string Repository { get; set; }
|
||||||
|
public string Branch { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum UpdateSourceType
|
||||||
|
{
|
||||||
|
Github,
|
||||||
|
Jenkins
|
||||||
|
}
|
||||||
}
|
}
|
@@ -8,9 +8,7 @@
|
|||||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||||
<OutputPath>..\bin\$(Platform)\$(Configuration)\</OutputPath>
|
<OutputPath>..\bin\$(Platform)\$(Configuration)\</OutputPath>
|
||||||
<UseWpf>True</UseWpf>
|
<UseWpf>True</UseWpf>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||||
<Configurations>Debug;Release</Configurations>
|
|
||||||
<Platforms>AnyCPU</Platforms>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="$(Configuration) == 'Release'">
|
<PropertyGroup Condition="$(Configuration) == 'Release'">
|
||||||
@@ -18,6 +16,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JorgeSerrano.Json.JsonSnakeCaseNamingPolicy" Version="0.9.0" />
|
||||||
<PackageReference Include="NLog" Version="5.0.4" />
|
<PackageReference Include="NLog" Version="5.0.4" />
|
||||||
<PackageReference Include="SemanticVersioning" Version="2.0.2" />
|
<PackageReference Include="SemanticVersioning" Version="2.0.2" />
|
||||||
<PackageReference Include="SpaceEngineersDedicated.ReferenceAssemblies" Version="1.201.13">
|
<PackageReference Include="SpaceEngineersDedicated.ReferenceAssemblies" Version="1.201.13">
|
||||||
|
128
Torch.API/WebAPI/GithubQuery.cs
Normal file
128
Torch.API/WebAPI/GithubQuery.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JorgeSerrano.Json;
|
||||||
|
using Version = SemanticVersioning.Version;
|
||||||
|
|
||||||
|
namespace Torch.API.WebAPI;
|
||||||
|
|
||||||
|
public class GithubQuery : IUpdateQuery
|
||||||
|
{
|
||||||
|
private readonly HttpClient _client;
|
||||||
|
|
||||||
|
public GithubQuery(string url)
|
||||||
|
{
|
||||||
|
if (url == null) throw new ArgumentNullException(nameof(url));
|
||||||
|
|
||||||
|
_client = new()
|
||||||
|
{
|
||||||
|
BaseAddress = new(url),
|
||||||
|
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
|
||||||
|
DefaultRequestHeaders =
|
||||||
|
{
|
||||||
|
{"User-Agent", "TorchAPI"}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_client?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UpdateRelease> GetLatestReleaseAsync(string repository, string branch = null)
|
||||||
|
{
|
||||||
|
var response = await _client.GetFromJsonAsync<Release>($"/repos/{repository}/releases/latest", new JsonSerializerOptions(JsonSerializerDefaults.Web)
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response is null)
|
||||||
|
throw new($"Unable to get latest release for {repository}");
|
||||||
|
|
||||||
|
return new(Version.Parse(response.TagName), response.Assets.First(b => b.Name == "torch-server.zip").BrowserDownloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Asset(
|
||||||
|
string Url,
|
||||||
|
int Id,
|
||||||
|
string NodeId,
|
||||||
|
string Name,
|
||||||
|
string Label,
|
||||||
|
Uploader Uploader,
|
||||||
|
string ContentType,
|
||||||
|
string State,
|
||||||
|
int Size,
|
||||||
|
int DownloadCount,
|
||||||
|
DateTime CreatedAt,
|
||||||
|
DateTime UpdatedAt,
|
||||||
|
string BrowserDownloadUrl
|
||||||
|
);
|
||||||
|
|
||||||
|
private record Author(
|
||||||
|
string Login,
|
||||||
|
int Id,
|
||||||
|
string NodeId,
|
||||||
|
string AvatarUrl,
|
||||||
|
string GravatarId,
|
||||||
|
string Url,
|
||||||
|
string HtmlUrl,
|
||||||
|
string FollowersUrl,
|
||||||
|
string FollowingUrl,
|
||||||
|
string GistsUrl,
|
||||||
|
string StarredUrl,
|
||||||
|
string SubscriptionsUrl,
|
||||||
|
string OrganizationsUrl,
|
||||||
|
string ReposUrl,
|
||||||
|
string EventsUrl,
|
||||||
|
string ReceivedEventsUrl,
|
||||||
|
string Type,
|
||||||
|
bool SiteAdmin
|
||||||
|
);
|
||||||
|
|
||||||
|
private record Release(
|
||||||
|
string Url,
|
||||||
|
string AssetsUrl,
|
||||||
|
string UploadUrl,
|
||||||
|
string HtmlUrl,
|
||||||
|
int Id,
|
||||||
|
Author Author,
|
||||||
|
string NodeId,
|
||||||
|
string TagName,
|
||||||
|
string TargetCommitish,
|
||||||
|
string Name,
|
||||||
|
bool Draft,
|
||||||
|
bool Prerelease,
|
||||||
|
DateTime CreatedAt,
|
||||||
|
DateTime PublishedAt,
|
||||||
|
IReadOnlyList<Asset> Assets,
|
||||||
|
string TarballUrl,
|
||||||
|
string ZipballUrl,
|
||||||
|
string Body
|
||||||
|
);
|
||||||
|
|
||||||
|
private record Uploader(
|
||||||
|
string Login,
|
||||||
|
int Id,
|
||||||
|
string NodeId,
|
||||||
|
string AvatarUrl,
|
||||||
|
string GravatarId,
|
||||||
|
string Url,
|
||||||
|
string HtmlUrl,
|
||||||
|
string FollowersUrl,
|
||||||
|
string FollowingUrl,
|
||||||
|
string GistsUrl,
|
||||||
|
string StarredUrl,
|
||||||
|
string SubscriptionsUrl,
|
||||||
|
string OrganizationsUrl,
|
||||||
|
string ReposUrl,
|
||||||
|
string EventsUrl,
|
||||||
|
string ReceivedEventsUrl,
|
||||||
|
string Type,
|
||||||
|
bool SiteAdmin
|
||||||
|
);
|
||||||
|
}
|
9
Torch.API/WebAPI/IUpdateQuery.cs
Normal file
9
Torch.API/WebAPI/IUpdateQuery.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Torch.API.WebAPI;
|
||||||
|
|
||||||
|
public interface IUpdateQuery : IDisposable
|
||||||
|
{
|
||||||
|
Task<UpdateRelease> GetLatestReleaseAsync(string repository, string branch = null);
|
||||||
|
}
|
@@ -1,82 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NLog;
|
|
||||||
using Torch.API.Utils;
|
using Torch.API.Utils;
|
||||||
using Version = SemanticVersioning.Version;
|
using Version = SemanticVersioning.Version;
|
||||||
|
|
||||||
namespace Torch.API.WebAPI
|
namespace Torch.API.WebAPI
|
||||||
{
|
{
|
||||||
public class JenkinsQuery
|
public class JenkinsQuery : IUpdateQuery
|
||||||
{
|
{
|
||||||
private const string BRANCH_QUERY = "http://136.243.80.164:2690/job/Torch/job/{0}/" + API_PATH;
|
private const string ApiPath = "api/json";
|
||||||
private const string ARTIFACT_PATH = "artifact/bin/torch-server.zip";
|
private readonly HttpClient _client;
|
||||||
private const string API_PATH = "api/json";
|
|
||||||
|
public JenkinsQuery(string url)
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
private static JenkinsQuery _instance;
|
|
||||||
public static JenkinsQuery Instance => _instance ??= new JenkinsQuery();
|
|
||||||
private HttpClient _client;
|
|
||||||
|
|
||||||
private JenkinsQuery()
|
|
||||||
{
|
{
|
||||||
_client = new HttpClient();
|
if (url == null) throw new ArgumentNullException(nameof(url));
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Job> GetLatestVersion(string branch)
|
|
||||||
{
|
|
||||||
var h = await _client.GetAsync(string.Format(BRANCH_QUERY, branch));
|
|
||||||
if (!h.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
Log.Error($"'{branch}' Branch query failed with code {h.StatusCode}");
|
|
||||||
if(h.StatusCode == HttpStatusCode.NotFound)
|
|
||||||
Log.Error("This likely means you're trying to update a branch that is not public on Jenkins. Sorry :(");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var branchResponse = await h.Content.ReadFromJsonAsync<BranchResponse>();
|
|
||||||
|
|
||||||
if (branchResponse is null)
|
|
||||||
{
|
|
||||||
Log.Error("Error reading branch response");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
h = await _client.GetAsync($"{branchResponse.LastStableBuild.Url}{API_PATH}");
|
_client = new()
|
||||||
if (h.IsSuccessStatusCode)
|
|
||||||
return await h.Content.ReadFromJsonAsync<Job>();
|
|
||||||
|
|
||||||
Log.Error($"Job query failed with code {h.StatusCode}");
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> DownloadRelease(Job job, string path)
|
|
||||||
{
|
|
||||||
var h = await _client.GetAsync(job.Url + ARTIFACT_PATH);
|
|
||||||
if (!h.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
Log.Error($"Job download failed with code {h.StatusCode}");
|
BaseAddress = new(url)
|
||||||
return false;
|
};
|
||||||
}
|
|
||||||
var s = await h.Content.ReadAsStreamAsync();
|
|
||||||
#if !NETFRAMEWORK
|
|
||||||
await using var fs = new FileStream(path, FileMode.Create);
|
|
||||||
#else
|
|
||||||
using var fs = new FileStream(path, FileMode.Create);
|
|
||||||
#endif
|
|
||||||
await s.CopyToAsync(fs);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<UpdateRelease> GetLatestReleaseAsync(string repository, string branch = null)
|
||||||
|
{
|
||||||
|
branch ??= "master";
|
||||||
|
|
||||||
|
var response = await _client.GetFromJsonAsync<BranchResponse>($"/job/{repository}/job/{branch}/{ApiPath}");
|
||||||
|
|
||||||
|
if (response is null)
|
||||||
|
throw new($"Unable to get latest release for {repository}");
|
||||||
|
|
||||||
|
var job = await _client.GetFromJsonAsync<Job>(
|
||||||
|
$"/job/{repository}/job/{branch}/{response.LastBuild.Number}/{ApiPath}");
|
||||||
|
|
||||||
|
if (job is null)
|
||||||
|
throw new($"Unable to get latest release for job {repository}/{response.LastBuild.Number}");
|
||||||
|
|
||||||
|
return new(job.Version, job.Url + job.Artifacts.First(b => b.FileName == "torch-server.zip").RelativePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_client?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record BranchResponse(string Name, string Url, Build LastBuild, Build LastStableBuild);
|
public record BranchResponse(string Name, string Url, Build LastBuild, Build LastStableBuild);
|
||||||
@@ -84,5 +54,12 @@ namespace Torch.API.WebAPI
|
|||||||
public record Build(int Number, string Url);
|
public record Build(int Number, string Url);
|
||||||
|
|
||||||
public record Job(int Number, bool Building, string Description, string Result, string Url,
|
public record Job(int Number, bool Building, string Description, string Result, string Url,
|
||||||
[property: JsonConverter(typeof(SemanticVersionConverter))] Version Version);
|
[property: JsonConverter(typeof(SemanticVersionConverter))] Version Version,
|
||||||
|
IReadOnlyList<Artifact> Artifacts);
|
||||||
|
|
||||||
|
public record Artifact(
|
||||||
|
string DisplayPath,
|
||||||
|
string FileName,
|
||||||
|
string RelativePath
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
5
Torch.API/WebAPI/UpdateRelease.cs
Normal file
5
Torch.API/WebAPI/UpdateRelease.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using SemanticVersioning;
|
||||||
|
|
||||||
|
namespace Torch.API.WebAPI;
|
||||||
|
|
||||||
|
public record UpdateRelease(Version Version, string ArtifactUrl);
|
@@ -57,7 +57,7 @@ namespace Torch.Server
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!configuration.GetValue("noupdate", false))
|
if (!configuration.GetValue("noupdate", false))
|
||||||
RunSteamCmd();
|
RunSteamCmd(configuration);
|
||||||
|
|
||||||
var processPid = configuration.GetValue<int>("waitForPid");
|
var processPid = configuration.GetValue<int>("waitForPid");
|
||||||
if (processPid != 0)
|
if (processPid != 0)
|
||||||
@@ -124,11 +124,12 @@ namespace Torch.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RunSteamCmd()
|
public static void RunSteamCmd(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var log = LogManager.GetLogger("SteamCMD");
|
var log = LogManager.GetLogger("SteamCMD");
|
||||||
|
|
||||||
var path = Environment.GetEnvironmentVariable("TORCH_STEAMCMD") ?? Path.GetFullPath(STEAMCMD_DIR);
|
var path = configuration.GetValue<string>("steamCmdPath") ?? ApplicationContext.Current.TorchDirectory
|
||||||
|
.CreateSubdirectory(STEAMCMD_DIR).FullName;
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
@@ -143,7 +144,8 @@ namespace Torch.Server
|
|||||||
log.Info("Downloading SteamCMD.");
|
log.Info("Downloading SteamCMD.");
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
using (var file = File.Create(STEAMCMD_ZIP))
|
using (var file = File.Create(STEAMCMD_ZIP))
|
||||||
client.GetStreamAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip").Result.CopyTo(file);
|
using (var stream = client.GetStreamAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip").Result)
|
||||||
|
stream.CopyTo(file);
|
||||||
|
|
||||||
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, path);
|
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, path);
|
||||||
File.Delete(STEAMCMD_ZIP);
|
File.Delete(STEAMCMD_ZIP);
|
||||||
@@ -159,7 +161,7 @@ namespace Torch.Server
|
|||||||
log.Info("Checking for DS updates.");
|
log.Info("Checking for DS updates.");
|
||||||
var steamCmdProc = new ProcessStartInfo(steamCmdExePath)
|
var steamCmdProc = new ProcessStartInfo(steamCmdExePath)
|
||||||
{
|
{
|
||||||
Arguments = string.Format(STEAMCMD_ARGS, Environment.GetEnvironmentVariable("TORCH_GAME_PATH") ?? "../"),
|
Arguments = string.Format(STEAMCMD_ARGS, configuration.GetValue("gamePath", "../")),
|
||||||
WorkingDirectory = path,
|
WorkingDirectory = path,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
|
35
Torch.Server/Patches/SteamLoginPatch.cs
Normal file
35
Torch.Server/Patches/SteamLoginPatch.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using NLog;
|
||||||
|
using Steamworks;
|
||||||
|
using Torch.Managers.PatchManager;
|
||||||
|
using Torch.Utils;
|
||||||
|
|
||||||
|
namespace Torch.Patches;
|
||||||
|
|
||||||
|
[PatchShim]
|
||||||
|
public static class SteamLoginPatch
|
||||||
|
{
|
||||||
|
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
[ReflectedMethodInfo(null, "LogOnAnonymous", TypeName = "VRage.Steam.MySteamGameServer, VRage.Steam")]
|
||||||
|
private static MethodInfo LoginMethod = null!;
|
||||||
|
|
||||||
|
public static void Patch(PatchContext context)
|
||||||
|
{
|
||||||
|
context.GetPattern(LoginMethod).AddPrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Prefix()
|
||||||
|
{
|
||||||
|
#pragma warning disable CS0618
|
||||||
|
var token = TorchBase.Instance.Config.LoginToken;
|
||||||
|
#pragma warning restore CS0618
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(token))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Log.Info("Logging in to Steam with GSLT");
|
||||||
|
SteamGameServer.LogOn(token);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -89,8 +89,6 @@ namespace Torch.Server
|
|||||||
var workingDir = AppContext.BaseDirectory;
|
var workingDir = AppContext.BaseDirectory;
|
||||||
var gamePath = configuration.GetValue("gamePath", workingDir);
|
var gamePath = configuration.GetValue("gamePath", workingDir);
|
||||||
var binDir = Path.Combine(gamePath, "DedicatedServer64");
|
var binDir = Path.Combine(gamePath, "DedicatedServer64");
|
||||||
|
|
||||||
Directory.SetCurrentDirectory(gamePath);
|
|
||||||
|
|
||||||
var instanceName = configuration.GetValue("instanceName", "Instance");
|
var instanceName = configuration.GetValue("instanceName", "Instance");
|
||||||
string instancePath;
|
string instancePath;
|
||||||
@@ -105,6 +103,8 @@ namespace Torch.Server
|
|||||||
instancePath = Directory.CreateDirectory(instanceName!).FullName;
|
instancePath = Directory.CreateDirectory(instanceName!).FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Directory.SetCurrentDirectory(gamePath);
|
||||||
|
|
||||||
return new ApplicationContext(new(workingDir), new(gamePath), new(binDir),
|
return new ApplicationContext(new(workingDir), new(gamePath), new(binDir),
|
||||||
new(instancePath), instanceName, isService);
|
new(instancePath), instanceName, isService);
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||||
<NeutralLanguage>en</NeutralLanguage>
|
<NeutralLanguage>en</NeutralLanguage>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -45,6 +45,10 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="6.0.0" />
|
||||||
<PackageReference Include="NLog" Version="5.0.4" />
|
<PackageReference Include="NLog" Version="5.0.4" />
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="4.0.3" PrivateAssets="all" />
|
<PackageReference Include="PropertyChanged.Fody" Version="4.0.3" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="Steamworks.NET" Version="20.1.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>compile</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||||
<PackageReference Include="System.Management" Version="6.0.0" />
|
<PackageReference Include="System.Management" Version="6.0.0" />
|
||||||
<PackageReference Include="nulastudio.NetCoreBeauty" Version="1.2.9.3" />
|
<PackageReference Include="nulastudio.NetCoreBeauty" Version="1.2.9.3" />
|
||||||
|
@@ -109,6 +109,16 @@ public class TorchConfig : ViewModel, ITorchConfig
|
|||||||
GroupName = "Server")]
|
GroupName = "Server")]
|
||||||
public bool EntityManagerEnabled { get; set; } = true;
|
public bool EntityManagerEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[Display(Name = "Login Token", Description = "Steam GSLT (can be used if you have dynamic ip)", GroupName = "Server")]
|
||||||
|
public string LoginToken { get; set; }
|
||||||
|
|
||||||
|
public UpdateSource UpdateSource { get; set; } = new()
|
||||||
|
{
|
||||||
|
Repository = "PveTeam/Torch",
|
||||||
|
Url = "https://api.github.com",
|
||||||
|
SourceType = UpdateSourceType.Github
|
||||||
|
};
|
||||||
|
|
||||||
// for backward compatibility
|
// for backward compatibility
|
||||||
public void Save(string path = null) => Initializer.Instance?.ConfigPersistent?.Save(path);
|
public void Save(string path = null) => Initializer.Instance?.ConfigPersistent?.Save(path);
|
||||||
}
|
}
|
231
Torch/Managers/ScriptCompilationManager.cs
Normal file
231
Torch/Managers/ScriptCompilationManager.cs
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
|
using Microsoft.CodeAnalysis.Emit;
|
||||||
|
using Sandbox.Game.Entities.Blocks;
|
||||||
|
using Sandbox.Game.EntityComponents;
|
||||||
|
using Sandbox.ModAPI;
|
||||||
|
using Sandbox.ModAPI.Ingame;
|
||||||
|
using Torch.API;
|
||||||
|
using Torch.Utils;
|
||||||
|
using VRage;
|
||||||
|
using VRage.ModAPI;
|
||||||
|
using VRage.Scripting;
|
||||||
|
|
||||||
|
namespace Torch.Managers;
|
||||||
|
|
||||||
|
public class ScriptCompilationManager : Manager
|
||||||
|
{
|
||||||
|
[ReflectedSetter(Name = "m_terminationReason")]
|
||||||
|
private static Action<MyProgrammableBlock, MyProgrammableBlock.ScriptTerminationReason> TerminationReasonSetter = null!;
|
||||||
|
|
||||||
|
[ReflectedGetter(Name = "ScriptComponent")]
|
||||||
|
private static Func<MyProgrammableBlock, MyIngameScriptComponent> ScriptComponentGetter = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Action<MyProgrammableBlock, string> SetDetailedInfo = null!;
|
||||||
|
|
||||||
|
[ReflectedSetter(Name = "m_instance")]
|
||||||
|
private static Action<MyProgrammableBlock, IMyGridProgram> InstanceSetter = null!;
|
||||||
|
|
||||||
|
[ReflectedSetter(Name = "m_assembly")]
|
||||||
|
private static Action<MyProgrammableBlock, Assembly> AssemblySetter = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Func<MyProgrammableBlock, Assembly, IEnumerable<string>, string, bool> CreateInstance = null!;
|
||||||
|
|
||||||
|
[ReflectedGetter(Name = "m_compilerErrors")]
|
||||||
|
private static Func<MyProgrammableBlock, List<string>> CompilerErrorsGetter = null!;
|
||||||
|
|
||||||
|
[ReflectedGetter(Name = "m_modApiWhitelistDiagnosticAnalyzer")]
|
||||||
|
private static Func<MyScriptCompiler, DiagnosticAnalyzer> ModWhitelistAnalyzer = null!;
|
||||||
|
|
||||||
|
[ReflectedGetter(Name = "m_ingameWhitelistDiagnosticAnalyzer")]
|
||||||
|
private static Func<MyScriptCompiler, DiagnosticAnalyzer> ScriptWhitelistAnalyzer = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Func<MyScriptCompiler, CSharpCompilation, SyntaxTree, int, SyntaxTree> InjectMod = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Func<MyScriptCompiler, CSharpCompilation, SyntaxTree, SyntaxTree> InjectInstructionCounter = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Func<MyScriptCompiler, CompilationWithAnalyzers, EmitResult, List<Message>, bool, Task<bool>> EmitDiagnostics = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod]
|
||||||
|
private static Func<MyScriptCompiler, MyApiTarget, string, IList<SyntaxTree>, string, Task> WriteDiagnostics = null!;
|
||||||
|
|
||||||
|
[ReflectedMethod(Name = "WriteDiagnostics")]
|
||||||
|
private static Func<MyScriptCompiler, MyApiTarget, string, IEnumerable<Message>, bool, Task> WriteDiagnostics2 = null!;
|
||||||
|
|
||||||
|
[ReflectedGetter(Name = "m_metadataReferences")]
|
||||||
|
private static Func<MyScriptCompiler, List<MetadataReference>> MetadataReferencesGetter = null!;
|
||||||
|
|
||||||
|
private readonly ConditionalWeakTable<MyProgrammableBlock, AssemblyLoadContext> _contexts = new();
|
||||||
|
|
||||||
|
public ScriptCompilationManager(ITorchBase torchInstance) : base(torchInstance)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void CompileAsync(MyProgrammableBlock block, string program, string storage, bool instantiate)
|
||||||
|
{
|
||||||
|
TerminationReasonSetter(block, MyProgrammableBlock.ScriptTerminationReason.None);
|
||||||
|
|
||||||
|
var component = ScriptComponentGetter(block);
|
||||||
|
component.NextUpdate = UpdateType.None;
|
||||||
|
component.NeedsUpdate = MyEntityUpdateEnum.NONE;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_contexts.TryGetValue(block, out var context))
|
||||||
|
{
|
||||||
|
InstanceSetter(block, null);
|
||||||
|
AssemblySetter(block, null);
|
||||||
|
context!.Unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
_contexts.AddOrUpdate(block, context = new AssemblyLoadContext(null, true));
|
||||||
|
|
||||||
|
var messages = new List<Message>();
|
||||||
|
var assembly = await CompileAsync(context, MyApiTarget.Ingame,
|
||||||
|
$"pb_{block.EntityId}_{Random.Shared.NextInt64()}",
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
MyVRage.Platform.Scripting.GetIngameScript(
|
||||||
|
program, "Program", nameof(MyGridProgram))
|
||||||
|
}, messages, $"PB: {block.DisplayName} ({block.EntityId})");
|
||||||
|
AssemblySetter(block, assembly);
|
||||||
|
var errors = CompilerErrorsGetter(block);
|
||||||
|
|
||||||
|
errors.Clear();
|
||||||
|
errors.AddRange(messages.Select(b => b.Text));
|
||||||
|
|
||||||
|
if (instantiate)
|
||||||
|
await Torch.InvokeAsync(() => CreateInstance(block, assembly, errors, storage));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
await Torch.InvokeAsync(() => SetDetailedInfo(block, e.ToString()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Assembly> CompileAsync(AssemblyLoadContext context, MyApiTarget target, string assemblyName, IEnumerable<Script> scripts, List<Message> messages, string friendlyName, bool enableDebugInformation = false)
|
||||||
|
{
|
||||||
|
friendlyName ??= "<No Name>";
|
||||||
|
Func<CSharpCompilation, SyntaxTree, SyntaxTree> syntaxTreeInjector;
|
||||||
|
DiagnosticAnalyzer whitelistAnalyzer;
|
||||||
|
switch (target)
|
||||||
|
{
|
||||||
|
case MyApiTarget.None:
|
||||||
|
whitelistAnalyzer = null;
|
||||||
|
syntaxTreeInjector = null;
|
||||||
|
break;
|
||||||
|
case MyApiTarget.Mod:
|
||||||
|
{
|
||||||
|
var modId = MyModWatchdog.AllocateModId(friendlyName);
|
||||||
|
whitelistAnalyzer = ModWhitelistAnalyzer(MyScriptCompiler.Static);
|
||||||
|
syntaxTreeInjector = (c, st) => InjectMod(MyScriptCompiler.Static, c, st, modId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MyApiTarget.Ingame:
|
||||||
|
syntaxTreeInjector = (c, t) => InjectInstructionCounter(MyScriptCompiler.Static, c, t);
|
||||||
|
whitelistAnalyzer = ScriptWhitelistAnalyzer(MyScriptCompiler.Static);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(target), target, "Invalid compilation target");
|
||||||
|
}
|
||||||
|
var compilation = CreateCompilation(assemblyName, scripts);
|
||||||
|
|
||||||
|
await WriteDiagnostics(MyScriptCompiler.Static, target, assemblyName, compilation.SyntaxTrees, null).ConfigureAwait(false);
|
||||||
|
var injectionFailed = false;
|
||||||
|
var compilationWithoutInjection = compilation;
|
||||||
|
if (syntaxTreeInjector != null)
|
||||||
|
{
|
||||||
|
SyntaxTree[] newSyntaxTrees = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var syntaxTrees = compilation.SyntaxTrees;
|
||||||
|
if (syntaxTrees.Length == 1)
|
||||||
|
{
|
||||||
|
newSyntaxTrees = new[] { syntaxTreeInjector(compilation, syntaxTrees[0]) };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newSyntaxTrees = await Task
|
||||||
|
.WhenAll(syntaxTrees.Select(
|
||||||
|
x => Task.Run(() => syntaxTreeInjector(compilation, x))))
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
injectionFailed = true;
|
||||||
|
}
|
||||||
|
if (!injectionFailed)
|
||||||
|
{
|
||||||
|
await WriteDiagnostics(MyScriptCompiler.Static, target, assemblyName, newSyntaxTrees, ".injected").ConfigureAwait(false);
|
||||||
|
compilation = compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(newSyntaxTrees);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CompilationWithAnalyzers analyticCompilation = null;
|
||||||
|
if (whitelistAnalyzer != null)
|
||||||
|
{
|
||||||
|
analyticCompilation = compilation.WithAnalyzers(ImmutableArray.Create(whitelistAnalyzer));
|
||||||
|
compilation = (CSharpCompilation)analyticCompilation.Compilation;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var assemblyStream = new MemoryStream();
|
||||||
|
|
||||||
|
var emitResult = compilation.Emit(assemblyStream);
|
||||||
|
var success = emitResult.Success;
|
||||||
|
var myBlacklistSyntaxVisitor = new MyBlacklistSyntaxVisitor();
|
||||||
|
foreach (var syntaxTree in compilation.SyntaxTrees)
|
||||||
|
{
|
||||||
|
myBlacklistSyntaxVisitor.SetSemanticModel(compilation.GetSemanticModel(syntaxTree, false));
|
||||||
|
myBlacklistSyntaxVisitor.Visit(await syntaxTree.GetRootAsync());
|
||||||
|
}
|
||||||
|
if (myBlacklistSyntaxVisitor.HasAnyResult())
|
||||||
|
{
|
||||||
|
myBlacklistSyntaxVisitor.GetResultMessages(messages);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = await EmitDiagnostics(MyScriptCompiler.Static, analyticCompilation, emitResult, messages, success).ConfigureAwait(false);
|
||||||
|
await WriteDiagnostics2(MyScriptCompiler.Static, target, assemblyName, messages, success).ConfigureAwait(false);
|
||||||
|
assemblyStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
if (injectionFailed) return null;
|
||||||
|
if (success)
|
||||||
|
return context.LoadFromStream(assemblyStream);
|
||||||
|
|
||||||
|
await EmitDiagnostics(MyScriptCompiler.Static, analyticCompilation, compilationWithoutInjection.Emit(assemblyStream), messages, false).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly CSharpCompilationOptions _compilationOptions = new(OutputKind.DynamicallyLinkedLibrary);
|
||||||
|
private readonly CSharpParseOptions _parseOptions = new(LanguageVersion.CSharp10, DocumentationMode.None);
|
||||||
|
|
||||||
|
private CSharpCompilation CreateCompilation(string assemblyFileName, IEnumerable<Script> scripts)
|
||||||
|
{
|
||||||
|
if (scripts == null)
|
||||||
|
return CSharpCompilation.Create(assemblyFileName, null, MetadataReferencesGetter(MyScriptCompiler.Static),
|
||||||
|
_compilationOptions);
|
||||||
|
|
||||||
|
var parseOptions = _parseOptions.WithPreprocessorSymbols(MyScriptCompiler.Static.ConditionalCompilationSymbols);
|
||||||
|
var enumerable = scripts.Select(s => CSharpSyntaxTree.ParseText(s.Code, parseOptions, s.Name, Encoding.UTF8));
|
||||||
|
|
||||||
|
return CSharpCompilation.Create(assemblyFileName, enumerable, MetadataReferencesGetter(MyScriptCompiler.Static), _compilationOptions);
|
||||||
|
}
|
||||||
|
}
|
@@ -5,6 +5,7 @@ using System.IO.Compression;
|
|||||||
using System.IO.Packaging;
|
using System.IO.Packaging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -21,8 +22,9 @@ namespace Torch.Managers
|
|||||||
public class UpdateManager : Manager
|
public class UpdateManager : Manager
|
||||||
{
|
{
|
||||||
private readonly Timer _updatePollTimer;
|
private readonly Timer _updatePollTimer;
|
||||||
private string _torchDir = new FileInfo(typeof(UpdateManager).Assembly.Location).DirectoryName;
|
private readonly string _torchDir = ApplicationContext.Current.TorchDirectory.FullName;
|
||||||
private Logger _log = LogManager.GetCurrentClassLogger();
|
private readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
[Dependency]
|
[Dependency]
|
||||||
private FilesystemManager _fsManager = null!;
|
private FilesystemManager _fsManager = null!;
|
||||||
|
|
||||||
@@ -50,26 +52,22 @@ namespace Torch.Managers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var job = await JenkinsQuery.Instance.GetLatestVersion(Torch.TorchVersion.Build);
|
var updateSource = Torch.Config.UpdateSource;
|
||||||
if (job == null)
|
|
||||||
{
|
|
||||||
_log.Info("Failed to fetch latest version.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (job.Version > Torch.TorchVersion)
|
IUpdateQuery source = updateSource.SourceType switch
|
||||||
{
|
{
|
||||||
_log.Warn($"Updating Torch from version {Torch.TorchVersion} to version {job.Version}");
|
UpdateSourceType.Github => new GithubQuery(updateSource.Url),
|
||||||
var updateName = Path.Combine(_fsManager.TempDirectory, "torchupdate.zip");
|
UpdateSourceType.Jenkins => new JenkinsQuery(updateSource.Url),
|
||||||
//new WebClient().DownloadFile(new Uri(releaseInfo.Item2), updateName);
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
if (!await JenkinsQuery.Instance.DownloadRelease(job, updateName))
|
};
|
||||||
{
|
|
||||||
_log.Warn("Failed to download new release!");
|
var release = await source.GetLatestReleaseAsync(updateSource.Repository, updateSource.Branch);
|
||||||
return;
|
|
||||||
}
|
if (release.Version > Torch.TorchVersion)
|
||||||
UpdateFromZip(updateName, _torchDir);
|
{
|
||||||
File.Delete(updateName);
|
_log.Warn($"Updating Torch from version {Torch.TorchVersion} to version {release.Version}");
|
||||||
_log.Warn($"Torch version {job.Version} has been installed, please restart Torch to finish the process.");
|
await UpdateAsync(release, _torchDir);
|
||||||
|
_log.Warn($"Torch version {release.Version} has been installed, please restart Torch to finish the process.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -83,23 +81,29 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFromZip(string zipFile, string extractPath)
|
private async Task UpdateAsync(UpdateRelease release, string extractPath)
|
||||||
{
|
{
|
||||||
using (var zip = ZipFile.OpenRead(zipFile))
|
using var client = new HttpClient();
|
||||||
|
await using var stream = await client.GetStreamAsync(release.ArtifactUrl);
|
||||||
|
UpdateFromZip(stream, extractPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateFromZip(Stream zipStream, string extractPath)
|
||||||
|
{
|
||||||
|
using var zip = new ZipArchive(zipStream, ZipArchiveMode.Read, true);
|
||||||
|
|
||||||
|
foreach (var file in zip.Entries)
|
||||||
{
|
{
|
||||||
foreach (var file in zip.Entries)
|
if(file.Name == "NLog-user.config" && File.Exists(Path.Combine(extractPath, file.FullName)))
|
||||||
{
|
continue;
|
||||||
if(file.Name == "NLog-user.config" && File.Exists(Path.Combine(extractPath, file.FullName)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
_log.Debug($"Unzipping {file.FullName}");
|
_log.Debug($"Unzipping {file.FullName}");
|
||||||
var targetFile = Path.Combine(extractPath, file.FullName);
|
var targetFile = Path.Combine(extractPath, file.FullName);
|
||||||
_fsManager.SoftDelete(extractPath, file.FullName);
|
_fsManager.SoftDelete(extractPath, file.FullName);
|
||||||
file.ExtractToFile(targetFile, true);
|
file.ExtractToFile(targetFile, true);
|
||||||
}
|
|
||||||
|
|
||||||
//zip.ExtractToDirectory(extractPath); //throws exceptions sometimes?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//zip.ExtractToDirectory(extractPath); //throws exceptions sometimes?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
#if false
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
@@ -50,4 +51,5 @@ internal static class GcCollectPatch
|
|||||||
yield return instruction;
|
yield return instruction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
33
Torch/Patches/ProgramableBlockPatch.cs
Normal file
33
Torch/Patches/ProgramableBlockPatch.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using Sandbox.Game.Entities.Blocks;
|
||||||
|
using Sandbox.Game.World;
|
||||||
|
using Torch.API.Managers;
|
||||||
|
using Torch.Managers;
|
||||||
|
using Torch.Managers.PatchManager;
|
||||||
|
using Torch.Utils;
|
||||||
|
|
||||||
|
namespace Torch.Patches;
|
||||||
|
|
||||||
|
[PatchShim]
|
||||||
|
public static class ProgramableBlockPatch
|
||||||
|
{
|
||||||
|
[ReflectedMethodInfo(typeof(MyProgrammableBlock), "Compile")]
|
||||||
|
private static MethodInfo CompileMethod = null!;
|
||||||
|
|
||||||
|
public static void Patch(PatchContext context)
|
||||||
|
{
|
||||||
|
context.GetPattern(CompileMethod).AddPrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Prefix(MyProgrammableBlock __instance, string program, string storage, bool instantiate)
|
||||||
|
{
|
||||||
|
if (!MySession.Static.EnableIngameScripts || __instance.CubeGrid is {IsPreview: true} or {CreatePhysics: false})
|
||||||
|
return false;
|
||||||
|
|
||||||
|
#pragma warning disable CS0618
|
||||||
|
TorchBase.Instance.CurrentSession.Managers.GetManager<ScriptCompilationManager>().CompileAsync(__instance, program, storage, instantiate);
|
||||||
|
#pragma warning restore CS0618
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -12,6 +12,7 @@ using System.Reflection.Emit;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
using ParallelTasks;
|
||||||
using ProtoBuf;
|
using ProtoBuf;
|
||||||
using Torch.Managers.PatchManager;
|
using Torch.Managers.PatchManager;
|
||||||
using Torch.Managers.PatchManager.MSIL;
|
using Torch.Managers.PatchManager.MSIL;
|
||||||
@@ -82,6 +83,14 @@ namespace Torch.Patches
|
|||||||
|
|
||||||
using var batch = MyScriptCompiler.Static.Whitelist.OpenBatch();
|
using var batch = MyScriptCompiler.Static.Whitelist.OpenBatch();
|
||||||
batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(ConcurrentQueue<>));
|
batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(ConcurrentQueue<>));
|
||||||
|
batch.AllowNamespaceOfTypes(MyWhitelistTarget.Both, typeof(ImmutableArray), typeof(ArrayExtensions));
|
||||||
|
batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(ProtoContractAttribute).Assembly.GetExportedTypes()
|
||||||
|
.Where(b => b.Namespace == "ProtoBuf" && b.Name.Contains("Attribute"))
|
||||||
|
.Concat(new[]
|
||||||
|
{
|
||||||
|
typeof(DataFormat), typeof(MemberSerializationOptions), typeof(ImplicitFields)
|
||||||
|
}).ToArray());
|
||||||
|
batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(WorkData));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<Platforms>AnyCPU</Platforms>
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="$(Configuration) == 'Release'">
|
<PropertyGroup Condition="$(Configuration) == 'Release'">
|
||||||
|
@@ -92,6 +92,7 @@ namespace Torch
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||||
/// <exception cref="InvalidOperationException">Thrown if a TorchBase instance already exists.</exception>
|
/// <exception cref="InvalidOperationException">Thrown if a TorchBase instance already exists.</exception>
|
||||||
protected TorchBase(ITorchConfig config)
|
protected TorchBase(ITorchConfig config)
|
||||||
{
|
{
|
||||||
@@ -103,14 +104,8 @@ namespace Torch
|
|||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
Config = config;
|
Config = config;
|
||||||
|
|
||||||
var versionString = GetType().Assembly
|
var assemblyVersion = GetType().Assembly.GetName().Version ?? new Version();
|
||||||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!
|
TorchVersion = new(assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Build);
|
||||||
.InformationalVersion;
|
|
||||||
|
|
||||||
if (!SemanticVersioning.Version.TryParse(versionString, out var version))
|
|
||||||
throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
|
|
||||||
|
|
||||||
TorchVersion = version;
|
|
||||||
|
|
||||||
RunArgs = Array.Empty<string>();
|
RunArgs = Array.Empty<string>();
|
||||||
|
|
||||||
@@ -128,11 +123,12 @@ namespace Torch
|
|||||||
Managers.AddManager(sessionManager);
|
Managers.AddManager(sessionManager);
|
||||||
Managers.AddManager(new PatchManager(this));
|
Managers.AddManager(new PatchManager(this));
|
||||||
Managers.AddManager(new FilesystemManager(this));
|
Managers.AddManager(new FilesystemManager(this));
|
||||||
// Managers.AddManager(new UpdateManager(this));
|
Managers.AddManager(new UpdateManager(this));
|
||||||
Managers.AddManager(new EventManager(this));
|
Managers.AddManager(new EventManager(this));
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
Managers.AddManager(Plugins);
|
Managers.AddManager(Plugins);
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
|
Managers.AddManager(new ScriptCompilationManager(this));
|
||||||
TorchAPI.Instance = this;
|
TorchAPI.Instance = this;
|
||||||
|
|
||||||
GameStateChanged += (game, state) =>
|
GameStateChanged += (game, state) =>
|
||||||
@@ -146,6 +142,20 @@ namespace Torch
|
|||||||
PatchManager.CommitInternal();
|
PatchManager.CommitInternal();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var harmonyLog = LogManager.GetLogger("HarmonyX");
|
||||||
|
HarmonyLib.Tools.Logger.ChannelFilter = HarmonyLib.Tools.Logger.LogChannel.Debug;
|
||||||
|
HarmonyLib.Tools.Logger.MessageReceived += (_, args) => harmonyLog.Log(args.LogChannel switch
|
||||||
|
{
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.None => LogLevel.Off,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.Info => LogLevel.Info,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.IL => LogLevel.Trace,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.Warn => LogLevel.Warn,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.Error => LogLevel.Error,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.Debug => LogLevel.Debug,
|
||||||
|
HarmonyLib.Tools.Logger.LogChannel.All => LogLevel.Debug,
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
}, args.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Prefer using Managers.GetManager for global managers")]
|
[Obsolete("Prefer using Managers.GetManager for global managers")]
|
||||||
|
Reference in New Issue
Block a user