Separate MHServerEmu.Core into a library
This commit is contained in:
parent
7c709d5423
commit
b4541cd1df
73 changed files with 79 additions and 25 deletions
|
|
@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MHServerEmu", "src\MHServer
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gazillion", "src\Gazillion\Gazillion.csproj", "{7D085437-F307-49D6-AF7A-C3B3DF4E4189}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHServerEmu.Core", "src\MHServerEmu.Core\MHServerEmu.Core.csproj", "{667BA21C-0E76-450A-9854-93D0C4C3D79E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
|
@ -21,6 +23,10 @@ Global
|
|||
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Debug|x64.Build.0 = Debug|x64
|
||||
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|x64.ActiveCfg = Release|x64
|
||||
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|x64.Build.0 = Release|x64
|
||||
{667BA21C-0E76-450A-9854-93D0C4C3D79E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{667BA21C-0E76-450A-9854-93D0C4C3D79E}.Debug|x64.Build.0 = Debug|x64
|
||||
{667BA21C-0E76-450A-9854-93D0C4C3D79E}.Release|x64.ActiveCfg = Release|x64
|
||||
{667BA21C-0E76-450A-9854-93D0C4C3D79E}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
34
src/MHServerEmu.Core/Helpers/CompressionHelper.cs
Normal file
34
src/MHServerEmu.Core/Helpers/CompressionHelper.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using Free.Ports.zLib;
|
||||
using K4os.Compression.LZ4;
|
||||
|
||||
namespace MHServerEmu.Core.Helpers
|
||||
{
|
||||
public static class CompressionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Decompresses the provided LZ4 buffer.
|
||||
/// </summary>
|
||||
public static void LZ4Decode(byte[] source, byte[] target)
|
||||
{
|
||||
LZ4Codec.Decode(source, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compresses the provided buffer using zlib.
|
||||
/// </summary>
|
||||
public static byte[] ZLibDeflate(byte[] buffer)
|
||||
{
|
||||
// This is used for compressing the achievement database dump before sending it to clients.
|
||||
// We need to compress specifically with a port of zlib rather than various alternatives like SharpZipLib
|
||||
// to produce the same result as the original. zlib.compress() in Python also produces the result we need.
|
||||
|
||||
using (MemoryStream ms = new())
|
||||
using (ZStreamWriter writer = new(ms))
|
||||
{
|
||||
writer.Write(buffer);
|
||||
writer.Close();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/MHServerEmu.Core/MHServerEmu.Core.csproj
Normal file
29
src/MHServerEmu.Core/MHServerEmu.Core.csproj
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Gazillion\Gazillion.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Free.Ports.zLib">
|
||||
<HintPath>..\..\dep\Free.Ports.zLib\Free.Ports.zLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.ProtocolBuffers">
|
||||
<HintPath>..\..\dep\protobuf-csharp\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\..\dep\ini-parser\INIFileParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4">
|
||||
<HintPath>..\..\dep\K4os.Compression.LZ4\K4os.Compression.LZ4.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using Free.Ports.zLib;
|
||||
using Google.ProtocolBuffers;
|
||||
using Gazillion;
|
||||
using MHServerEmu.Core.Helpers;
|
||||
|
|
@ -186,19 +185,13 @@ namespace MHServerEmu.Games.Achievements
|
|||
.SetAchievementNewThresholdUS((ulong)AchievementNewThresholdUS.TotalSeconds)
|
||||
.Build().ToByteArray();
|
||||
|
||||
// We need to compress specifically with a port of zlib rather than various alternatives like SharpZipLib
|
||||
// to produce the same result. zlib.compress() in Python also produces the result we need.
|
||||
// NOTE: If you don't use the right library to compress this it's going to cause client-side errors.
|
||||
// See CompressionHelper.ZLibDeflate() for more details.
|
||||
byte[] compressedBuffer = CompressionHelper.ZLibDeflate(dumpBuffer);
|
||||
|
||||
using (MemoryStream ms = new())
|
||||
using (ZStreamWriter writer = new(ms))
|
||||
{
|
||||
writer.Write(dumpBuffer);
|
||||
writer.Close();
|
||||
|
||||
_cachedDump = NetMessageAchievementDatabaseDump.CreateBuilder()
|
||||
.SetCompressedAchievementDatabaseDump(ByteString.CopyFrom(ms.ToArray()))
|
||||
.Build();
|
||||
}
|
||||
_cachedDump = NetMessageAchievementDatabaseDump.CreateBuilder()
|
||||
.SetCompressedAchievementDatabaseDump(ByteString.CopyFrom(compressedBuffer))
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using K4os.Compression.LZ4;
|
||||
using MHServerEmu.Core.Extensions;
|
||||
using MHServerEmu.Core.Extensions;
|
||||
using MHServerEmu.Core.Helpers;
|
||||
using MHServerEmu.Core.Logging;
|
||||
|
||||
namespace MHServerEmu.Games.GameData
|
||||
|
|
@ -76,7 +76,7 @@ namespace MHServerEmu.Games.GameData
|
|||
}
|
||||
|
||||
byte[] uncompressedData = new byte[entry.UncompressedSize];
|
||||
LZ4Codec.Decode(entry.CompressedData, uncompressedData);
|
||||
CompressionHelper.LZ4Decode(entry.CompressedData, uncompressedData);
|
||||
return new(uncompressedData);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,24 +22,16 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Gazillion\Gazillion.csproj" />
|
||||
<ProjectReference Include="..\MHServerEmu.Core\MHServerEmu.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Dapper">
|
||||
<HintPath>..\..\dep\Dapper\Dapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Free.Ports.zLib">
|
||||
<HintPath>..\..\dep\Free.Ports.zLib\Free.Ports.zLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.ProtocolBuffers">
|
||||
<HintPath>..\..\dep\protobuf-csharp\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\..\dep\ini-parser\INIFileParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4">
|
||||
<HintPath>..\..\dep\K4os.Compression.LZ4\K4os.Compression.LZ4.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>..\..\dep\System.Data.SQLite\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue