mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-29 13:04:59 +00:00
Implemented .net 10 support. Updated all affected libraries and the code. Not testes yet.
This commit is contained in:
parent
5488140261
commit
28834e7a86
10 changed files with 107 additions and 94 deletions
7
.github/workflows/build-and-release.yml
vendored
7
.github/workflows/build-and-release.yml
vendored
|
|
@ -8,7 +8,7 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PROJECT: "MinecraftClient"
|
PROJECT: "MinecraftClient"
|
||||||
target-version: "net8.0"
|
/us target-version: "net10.0"
|
||||||
compile-flags: "--self-contained=true -c Release -p:UseAppHost=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:DebugType=Embedded"
|
compile-flags: "--self-contained=true -c Release -p:UseAppHost=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:DebugType=Embedded"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -45,6 +45,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
echo project-path=${{ github.workspace }}/${{ env.PROJECT }} >> $GITHUB_ENV
|
echo project-path=${{ github.workspace }}/${{ env.PROJECT }} >> $GITHUB_ENV
|
||||||
echo file-ext=${{ (startsWith(matrix.target, 'win') && '.exe') || ' ' }} >> $GITHUB_ENV
|
echo file-ext=${{ (startsWith(matrix.target, 'win') && '.exe') || ' ' }} >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Setup .NET SDK
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: 10.0.x
|
||||||
|
|
||||||
- name: Setup Environment Variables
|
- name: Setup Environment Variables
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ namespace MinecraftClient.ChatBots
|
||||||
if (text != null)
|
if (text != null)
|
||||||
messageBuilder.WithContent(text);
|
messageBuilder.WithContent(text);
|
||||||
|
|
||||||
messageBuilder.WithFiles(new Dictionary<string, Stream>() { { $"attachment://{filePath}", fs } });
|
messageBuilder.AddFiles(new Dictionary<string, Stream>() { { filePath, fs } });
|
||||||
|
|
||||||
discordBotClient!.SendMessageAsync(discordChannel, messageBuilder).Wait(Config.Message_Send_Timeout * 1000);
|
discordBotClient!.SendMessageAsync(discordChannel, messageBuilder).Wait(Config.Message_Send_Timeout * 1000);
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +301,7 @@ namespace MinecraftClient.ChatBots
|
||||||
if (!CanSendMessages())
|
if (!CanSendMessages())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SendMessage(new DiscordMessageBuilder().WithFile(fileStream));
|
SendMessage(new DiscordMessageBuilder().AddFile(fileStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanSendMessages()
|
private bool CanSendMessages()
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,8 @@ namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
using (var image = new MagickImage(fileName))
|
using (var image = new MagickImage(fileName))
|
||||||
{
|
{
|
||||||
var size = new MagickGeometry(Config.Resize_To, Config.Resize_To);
|
uint resizeTo = (uint)Math.Max(Config.Resize_To, 1);
|
||||||
|
var size = new MagickGeometry(resizeTo, resizeTo);
|
||||||
size.IgnoreAspectRatio = true;
|
size.IgnoreAspectRatio = true;
|
||||||
|
|
||||||
image.Resize(size);
|
image.Resize(size);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ using Telegram.Bot.Exceptions;
|
||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.InputFiles;
|
|
||||||
using Tomlet.Attributes;
|
using Tomlet.Attributes;
|
||||||
using File = System.IO.File;
|
using File = System.IO.File;
|
||||||
|
|
||||||
|
|
@ -205,7 +204,7 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
botClient!.SendTextMessageAsync(Config.ChannelId.Trim(), message, ParseMode.Markdown).Wait(Config.Message_Send_Timeout);
|
botClient!.SendMessage(Config.ChannelId.Trim(), message, parseMode: ParseMode.Markdown).Wait(Config.Message_Send_Timeout);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -224,9 +223,9 @@ namespace MinecraftClient.ChatBots
|
||||||
string fileName = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
string fileName = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
||||||
|
|
||||||
Stream stream = File.OpenRead(filePath);
|
Stream stream = File.OpenRead(filePath);
|
||||||
botClient!.SendDocumentAsync(
|
botClient!.SendDocument(
|
||||||
Config.ChannelId.Trim(),
|
Config.ChannelId.Trim(),
|
||||||
document: new InputOnlineFile(content: stream, fileName),
|
document: InputFile.FromStream(stream, fileName),
|
||||||
caption: text,
|
caption: text,
|
||||||
parseMode: ParseMode.Markdown).Wait(Config.Message_Send_Timeout * 1000);
|
parseMode: ParseMode.Markdown).Wait(Config.Message_Send_Timeout * 1000);
|
||||||
}
|
}
|
||||||
|
|
@ -260,14 +259,14 @@ namespace MinecraftClient.ChatBots
|
||||||
cancellationToken = new CancellationTokenSource();
|
cancellationToken = new CancellationTokenSource();
|
||||||
|
|
||||||
botClient.StartReceiving(
|
botClient.StartReceiving(
|
||||||
updateHandler: HandleUpdateAsync,
|
HandleUpdateAsync,
|
||||||
pollingErrorHandler: HandlePollingErrorAsync,
|
HandlePollingErrorAsync,
|
||||||
receiverOptions: new ReceiverOptions
|
new ReceiverOptions
|
||||||
{
|
{
|
||||||
// receive all update types
|
// receive all update types
|
||||||
AllowedUpdates = Array.Empty<UpdateType>()
|
AllowedUpdates = Array.Empty<UpdateType>()
|
||||||
},
|
},
|
||||||
cancellationToken: cancellationToken.Token
|
cancellationToken.Token
|
||||||
);
|
);
|
||||||
|
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
|
|
@ -313,9 +312,9 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
if (text.ToLower().Contains(".chatid"))
|
if (text.ToLower().Contains(".chatid"))
|
||||||
{
|
{
|
||||||
await botClient.SendTextMessageAsync(chatId: chatId,
|
await botClient.SendMessage(chatId: chatId,
|
||||||
replyToMessageId: message.MessageId,
|
|
||||||
text: $"Chat ID: {chatId}",
|
text: $"Chat ID: {chatId}",
|
||||||
|
replyParameters: message.MessageId,
|
||||||
cancellationToken: _cancellationToken,
|
cancellationToken: _cancellationToken,
|
||||||
parseMode: ParseMode.Markdown);
|
parseMode: ParseMode.Markdown);
|
||||||
return;
|
return;
|
||||||
|
|
@ -324,10 +323,10 @@ namespace MinecraftClient.ChatBots
|
||||||
if (Config.Authorized_Chat_Ids.Length > 0 && !Config.Authorized_Chat_Ids.Contains(chatId))
|
if (Config.Authorized_Chat_Ids.Length > 0 && !Config.Authorized_Chat_Ids.Contains(chatId))
|
||||||
{
|
{
|
||||||
LogDebugToConsole($"Unauthorized message '{messageText}' received in a chat with with an ID: {chatId} !");
|
LogDebugToConsole($"Unauthorized message '{messageText}' received in a chat with with an ID: {chatId} !");
|
||||||
await botClient.SendTextMessageAsync(
|
await botClient.SendMessage(
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
replyToMessageId: message.MessageId,
|
|
||||||
text: Translations.bot_TelegramBridge_unauthorized,
|
text: Translations.bot_TelegramBridge_unauthorized,
|
||||||
|
replyParameters: message.MessageId,
|
||||||
cancellationToken: _cancellationToken,
|
cancellationToken: _cancellationToken,
|
||||||
parseMode: ParseMode.Markdown);
|
parseMode: ParseMode.Markdown);
|
||||||
return;
|
return;
|
||||||
|
|
@ -347,10 +346,10 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
if (command.ToLower().Contains("quit") || command.ToLower().Contains("exit"))
|
if (command.ToLower().Contains("quit") || command.ToLower().Contains("exit"))
|
||||||
{
|
{
|
||||||
await botClient.SendTextMessageAsync(
|
await botClient.SendMessage(
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
replyToMessageId: message.MessageId,
|
|
||||||
text: $"{Translations.bot_TelegramBridge_quit_disabled}",
|
text: $"{Translations.bot_TelegramBridge_quit_disabled}",
|
||||||
|
replyParameters: message.MessageId,
|
||||||
cancellationToken: _cancellationToken,
|
cancellationToken: _cancellationToken,
|
||||||
parseMode: ParseMode.Markdown);
|
parseMode: ParseMode.Markdown);
|
||||||
return;;
|
return;;
|
||||||
|
|
@ -359,11 +358,10 @@ namespace MinecraftClient.ChatBots
|
||||||
CmdResult result = new();
|
CmdResult result = new();
|
||||||
PerformInternalCommand(command, ref result);
|
PerformInternalCommand(command, ref result);
|
||||||
|
|
||||||
await botClient.SendTextMessageAsync(
|
await botClient.SendMessage(
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
replyToMessageId:
|
|
||||||
message.MessageId,
|
|
||||||
text: $"{Translations.bot_TelegramBridge_command_executed}:\n\n{result}",
|
text: $"{Translations.bot_TelegramBridge_command_executed}:\n\n{result}",
|
||||||
|
replyParameters: message.MessageId,
|
||||||
cancellationToken: _cancellationToken,
|
cancellationToken: _cancellationToken,
|
||||||
parseMode: ParseMode.Markdown);
|
parseMode: ParseMode.Markdown);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<PublishUrl>publish\</PublishUrl>
|
<PublishUrl>publish\</PublishUrl>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|
@ -28,25 +28,22 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Brigadier.NET" Version="1.2.13" />
|
<PackageReference Include="Brigadier.NET" Version="1.2.13" />
|
||||||
<PackageReference Include="DnsClient" Version="1.7.0" />
|
<PackageReference Include="DnsClient" Version="1.8.0" />
|
||||||
<PackageReference Include="DotNetZip" Version="1.16.0" />
|
<PackageReference Include="DSharpPlus" Version="4.5.1" />
|
||||||
<PackageReference Include="DSharpPlus" Version="4.2.0" />
|
<PackageReference Include="DynamicExpresso.Core" Version="2.19.3" />
|
||||||
<PackageReference Include="DynamicExpresso.Core" Version="2.13.0" />
|
|
||||||
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
||||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.3.0" />
|
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.11.0" />
|
||||||
<PackageReference Include="MessagePack" Version="3.1.0" />
|
<PackageReference Include="MessagePack" Version="3.1.4" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
|
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.5" />
|
||||||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.3" />
|
<PackageReference Include="Samboy063.Tomlet" Version="6.2.0" />
|
||||||
<PackageReference Include="Samboy063.Tomlet" Version="5.0.1" />
|
<PackageReference Include="Sentry" Version="6.2.0" />
|
||||||
<PackageReference Include="Sentry" Version="4.1.0" />
|
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
|
||||||
<PackageReference Include="SingleFileExtractor.Core" Version="1.0.1" />
|
|
||||||
<PackageReference Include="starksoft.aspen" Version="1.1.8">
|
<PackageReference Include="starksoft.aspen" Version="1.1.8">
|
||||||
<NoWarn>NU1701</NoWarn>
|
<NoWarn>NU1701</NoWarn>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
|
<PackageReference Include="Telegram.Bot" Version="22.9.5.3" />
|
||||||
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="config\ChatBots\AutoLeaveOnLowHp.cs" />
|
<Compile Remove="config\ChatBots\AutoLeaveOnLowHp.cs" />
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ namespace MinecraftClient
|
||||||
options.Dsn = SentryDSN;
|
options.Dsn = SentryDSN;
|
||||||
options.AutoSessionTracking = true;
|
options.AutoSessionTracking = true;
|
||||||
options.IsGlobalModeEnabled = true;
|
options.IsGlobalModeEnabled = true;
|
||||||
options.EnableTracing = true;
|
options.TracesSampleRate = 1.0;
|
||||||
options.SendDefaultPii = false;
|
options.SendDefaultPii = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (Ionic.Zlib.ZlibException)
|
catch (System.IO.InvalidDataException)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
using Ionic.Zlib;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
namespace MinecraftClient.Protocol.Handlers
|
namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quick Zlib compression handling for network packet compression.
|
/// Quick Zlib compression handling for network packet compression.
|
||||||
/// Note: Underlying compression handling is taken from the DotNetZip Library.
|
|
||||||
/// This library is open source and provided under the Microsoft Public License.
|
|
||||||
/// More info about DotNetZip at dotnetzip.codeplex.com.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ZlibUtils
|
public static class ZlibUtils
|
||||||
{
|
{
|
||||||
|
|
@ -17,16 +15,13 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// <returns>Compressed data as a byte array</returns>
|
/// <returns>Compressed data as a byte array</returns>
|
||||||
public static byte[] Compress(byte[] to_compress)
|
public static byte[] Compress(byte[] to_compress)
|
||||||
{
|
{
|
||||||
byte[] data;
|
using MemoryStream memstream = new();
|
||||||
using (System.IO.MemoryStream memstream = new())
|
using (ZLibStream stream = new(memstream, CompressionMode.Compress, leaveOpen: true))
|
||||||
{
|
{
|
||||||
using (ZlibStream stream = new(memstream, CompressionMode.Compress))
|
stream.Write(to_compress, 0, to_compress.Length);
|
||||||
{
|
|
||||||
stream.Write(to_compress, 0, to_compress.Length);
|
|
||||||
}
|
|
||||||
data = memstream.ToArray();
|
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
|
return memstream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -37,10 +32,20 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// <returns>Decompressed data as a byte array</returns>
|
/// <returns>Decompressed data as a byte array</returns>
|
||||||
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
|
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
|
||||||
{
|
{
|
||||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||||
|
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||||
|
|
||||||
byte[] packetData_decompressed = new byte[size_uncompressed];
|
byte[] packetData_decompressed = new byte[size_uncompressed];
|
||||||
stream.Read(packetData_decompressed, 0, size_uncompressed);
|
int totalRead = 0;
|
||||||
stream.Close();
|
while (totalRead < size_uncompressed)
|
||||||
|
{
|
||||||
|
int read = stream.Read(packetData_decompressed, totalRead, size_uncompressed - totalRead);
|
||||||
|
if (read <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
totalRead += read;
|
||||||
|
}
|
||||||
|
|
||||||
return packetData_decompressed;
|
return packetData_decompressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,12 +56,14 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// <returns>Decompressed data as byte array</returns>
|
/// <returns>Decompressed data as byte array</returns>
|
||||||
public static byte[] Decompress(byte[] to_decompress)
|
public static byte[] Decompress(byte[] to_decompress)
|
||||||
{
|
{
|
||||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||||
|
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||||
byte[] buffer = new byte[16 * 1024];
|
byte[] buffer = new byte[16 * 1024];
|
||||||
using System.IO.MemoryStream decompressedBuffer = new();
|
using MemoryStream decompressedBuffer = new();
|
||||||
int read;
|
int read;
|
||||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
decompressedBuffer.Write(buffer, 0, read);
|
decompressedBuffer.Write(buffer, 0, read);
|
||||||
|
|
||||||
return decompressedBuffer.ToArray();
|
return decompressedBuffer.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Ionic.Zip;
|
|
||||||
using MinecraftClient.Mapping;
|
using MinecraftClient.Mapping;
|
||||||
using MinecraftClient.Protocol.Handlers;
|
using MinecraftClient.Protocol.Handlers;
|
||||||
using MinecraftClient.Protocol.Handlers.PacketPalettes;
|
using MinecraftClient.Protocol.Handlers.PacketPalettes;
|
||||||
|
|
@ -138,12 +138,18 @@ namespace MinecraftClient.Protocol
|
||||||
using (Stream recordingFile = new FileStream(Path.Combine(temporaryCache, recordingTmpFileName), FileMode.Open))
|
using (Stream recordingFile = new FileStream(Path.Combine(temporaryCache, recordingTmpFileName), FileMode.Open))
|
||||||
{
|
{
|
||||||
using Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open);
|
using Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open);
|
||||||
using ZipOutputStream zs = new(Path.Combine(ReplayFileDirectory, replayFileName));
|
using FileStream replayArchiveFile = new(Path.Combine(ReplayFileDirectory, replayFileName), FileMode.Create, FileAccess.Write);
|
||||||
zs.PutNextEntry(recordingTmpFileName);
|
using ZipArchive replayArchive = new(replayArchiveFile, ZipArchiveMode.Create);
|
||||||
recordingFile.CopyTo(zs);
|
|
||||||
zs.PutNextEntry(MetaData.MetaDataFileName);
|
ZipArchiveEntry recordingEntry = replayArchive.CreateEntry(recordingTmpFileName);
|
||||||
metaDataFile.CopyTo(zs);
|
using (Stream recordingEntryStream = recordingEntry.Open())
|
||||||
zs.Close();
|
{
|
||||||
|
recordingFile.CopyTo(recordingEntryStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipArchiveEntry metadataEntry = replayArchive.CreateEntry(MetaData.MetaDataFileName);
|
||||||
|
using Stream metadataEntryStream = metadataEntry.Open();
|
||||||
|
metaDataFile.CopyTo(metadataEntryStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.Delete(Path.Combine(temporaryCache, recordingTmpFileName));
|
File.Delete(Path.Combine(temporaryCache, recordingTmpFileName));
|
||||||
|
|
@ -167,18 +173,29 @@ namespace MinecraftClient.Protocol
|
||||||
|
|
||||||
using (Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open))
|
using (Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open))
|
||||||
{
|
{
|
||||||
using ZipOutputStream zs = new(replayFileName);
|
using FileStream replayArchiveFile = new(replayFileName, FileMode.Create, FileAccess.Write);
|
||||||
zs.PutNextEntry(recordingTmpFileName);
|
using ZipArchive replayArchive = new(replayArchiveFile, ZipArchiveMode.Create);
|
||||||
// .CopyTo() method start from stream current position
|
|
||||||
// We need to reset position in order to get full content
|
|
||||||
var lastPosition = recordStream!.BaseStream.Position;
|
|
||||||
recordStream.BaseStream.Position = 0;
|
|
||||||
recordStream.BaseStream.CopyTo(zs);
|
|
||||||
recordStream.BaseStream.Position = lastPosition;
|
|
||||||
|
|
||||||
zs.PutNextEntry(MetaData.MetaDataFileName);
|
ZipArchiveEntry recordingEntry = replayArchive.CreateEntry(recordingTmpFileName);
|
||||||
metaDataFile.CopyTo(zs);
|
using (Stream recordingEntryStream = recordingEntry.Open())
|
||||||
zs.Close();
|
{
|
||||||
|
// .CopyTo() method start from stream current position
|
||||||
|
// We need to reset position in order to get full content
|
||||||
|
long lastPosition = recordStream!.BaseStream.Position;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
recordStream.BaseStream.Position = 0;
|
||||||
|
recordStream.BaseStream.CopyTo(recordingEntryStream);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
recordStream.BaseStream.Position = lastPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipArchiveEntry metadataEntry = replayArchive.CreateEntry(MetaData.MetaDataFileName);
|
||||||
|
using Stream metadataEntryStream = metadataEntry.Open();
|
||||||
|
metaDataFile.CopyTo(metadataEntryStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteDebugLog("Backup replay file created.");
|
WriteDebugLog("Backup replay file created.");
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ https://github.com/laurentkempe/DynamicRun/blob/master/LICENSE
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.MemoryMappedFiles;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
@ -117,10 +116,11 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
||||||
File.Copy(executablePath, tempFile);
|
File.Copy(executablePath, tempFile);
|
||||||
|
|
||||||
// Access the contents of the executable.
|
// Access the contents of the executable.
|
||||||
ExecutableReader e = new();
|
using ExecutableReader executableReader = new(tempFile);
|
||||||
var viewAccessor = MemoryMappedFile.CreateFromFile(tempFile, FileMode.Open).CreateViewAccessor();
|
if (!executableReader.IsSingleFile)
|
||||||
var manifest = e.ReadManifest(viewAccessor);
|
throw new InvalidOperationException("[Script Error] The executable is not a single-file bundle.");
|
||||||
var files = manifest.Files;
|
|
||||||
|
var files = executableReader.Bundle.Files;
|
||||||
|
|
||||||
Stream? assemblyStream;
|
Stream? assemblyStream;
|
||||||
|
|
||||||
|
|
@ -133,8 +133,8 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
||||||
if (string.IsNullOrEmpty(loadedAssembly.Location)) {
|
if (string.IsNullOrEmpty(loadedAssembly.Location)) {
|
||||||
// Check if we can access the file from the executable.
|
// Check if we can access the file from the executable.
|
||||||
var reference = files.FirstOrDefault(x =>
|
var reference = files.FirstOrDefault(x =>
|
||||||
x.RelativePath.Remove(x.RelativePath.Length - 4) == refs.Name);
|
Path.GetFileNameWithoutExtension(x.RelativePath) == refs.Name);
|
||||||
var refCount = files.Count(x => x.RelativePath.Remove(x.RelativePath.Length - 4) == refs.Name);
|
var refCount = files.Count(x => Path.GetFileNameWithoutExtension(x.RelativePath) == refs.Name);
|
||||||
if (refCount > 1) {
|
if (refCount > 1) {
|
||||||
// Safety net for the case where the assembly is referenced multiple times.
|
// Safety net for the case where the assembly is referenced multiple times.
|
||||||
// Should not happen normally, but we can make exceptions when it does happen.
|
// Should not happen normally, but we can make exceptions when it does happen.
|
||||||
|
|
@ -147,17 +147,13 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
||||||
"[Script Error] The executable does not contain a referenced assembly. Assembly name: " + refs.Name);
|
"[Script Error] The executable does not contain a referenced assembly. Assembly name: " + refs.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
assemblyStream = GetStreamForFileEntry(viewAccessor, reference);
|
assemblyStream = reference.AsStream();
|
||||||
references.Add(MetadataReference.CreateFromStream(assemblyStream!));
|
references.Add(MetadataReference.CreateFromStream(assemblyStream!));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
references.Add(MetadataReference.CreateFromFile(loadedAssembly.Location));
|
references.Add(MetadataReference.CreateFromFile(loadedAssembly.Location));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup.
|
|
||||||
viewAccessor.Flush();
|
|
||||||
viewAccessor.Dispose();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -176,14 +172,6 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
||||||
assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default));
|
assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream? GetStreamForFileEntry(MemoryMappedViewAccessor viewAccessor, FileEntry file)
|
|
||||||
{
|
|
||||||
if (typeof(BundleExtractor).GetMethod("GetStreamForFileEntry", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, new object[] { viewAccessor, file }) is not Stream stream)
|
|
||||||
throw new InvalidOperationException("[Script Error] The executable does not contain the assembly. Assembly name: " + file.RelativePath);
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal struct CompileResult
|
internal struct CompileResult
|
||||||
{
|
{
|
||||||
internal byte[]? Assembly;
|
internal byte[]? Assembly;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue