-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanislav
authored
Dec 29, 2020
1 parent
0c61a26
commit 09a5b24
Showing
6 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.IO; | ||
using zlib; | ||
|
||
namespace oceanhornTXT | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
if (args.Length > 0) | ||
{ | ||
if (args[0] == "-d") | ||
{ | ||
DecryptTXT(args[1]); | ||
} | ||
else if (args[0] == "-e") | ||
{ | ||
EncryptTXT(args[1], args[1] + ".txt"); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Usage:"); | ||
Console.WriteLine("-d Decrypt TXT file"); | ||
Console.WriteLine("-e Encrypt text file into game TXT"); | ||
} | ||
} | ||
|
||
static void EncryptTXT(string inputFile, string outputFile) | ||
{ | ||
var inFileName = File.ReadAllBytes(inputFile); | ||
if (File.Exists(outputFile)) File.Delete(outputFile); | ||
var outFileName = File.OpenWrite(outputFile); | ||
using (var writer = new BinaryWriter(outFileName)) | ||
{ | ||
byte[] cData = CompressZlib(inFileName); | ||
writer.Write(inFileName.Length); | ||
writer.Write(cData); | ||
} | ||
} | ||
|
||
static void DecryptTXT(string inputFile) | ||
{ | ||
var fileName = File.OpenRead(inputFile); | ||
using (var reader = new BinaryReader(fileName)) | ||
{ | ||
var uSize = reader.ReadInt32(); | ||
if (uSize < 0) | ||
{ | ||
reader.BaseStream.Seek(0x02, SeekOrigin.Begin); //skip first 2 bytes. Based on example i've got. | ||
uSize = reader.ReadInt32(); | ||
var data = reader.ReadBytes((int)(fileName.Length - 4)); | ||
byte[] uncArray = DecompressZlib(data); | ||
File.WriteAllBytes(Path.GetFileNameWithoutExtension(inputFile) + ".dec.txt", uncArray); | ||
} | ||
else | ||
{ | ||
var data = reader.ReadBytes((int)(fileName.Length - 4)); | ||
byte[] uncArray = DecompressZlib(data); | ||
File.WriteAllBytes(Path.GetFileNameWithoutExtension(inputFile) + ".dec.txt", uncArray); | ||
} | ||
} | ||
} | ||
|
||
static byte[] CompressZlib(byte[] input) | ||
{ | ||
using (var outMS = new MemoryStream()) | ||
using (var outZStream = new ZOutputStream(outMS, 8)) //8 - compression level, similar to original size | ||
using (Stream inMemoryStream = new MemoryStream(input)) | ||
{ | ||
CopyStream(inMemoryStream, outZStream); | ||
outZStream.finish(); | ||
byte[] output = outMS.ToArray(); | ||
return output; | ||
} | ||
} | ||
|
||
static byte[] DecompressZlib(byte[] input) | ||
{ | ||
using (var outMS = new MemoryStream()) | ||
using (var outZStream = new ZOutputStream(outMS)) | ||
using (Stream inMemoryStream = new MemoryStream(input)) | ||
{ | ||
CopyStream(inMemoryStream, outZStream); | ||
outZStream.finish(); | ||
byte[] output = outMS.ToArray(); | ||
return output; | ||
} | ||
} | ||
|
||
public static void CopyStream(Stream input, Stream output) | ||
{ | ||
byte[] buffer = new byte[2000]; | ||
int len; | ||
while ((len = input.Read(buffer, 0, 2000)) > 0) | ||
{ | ||
output.Write(buffer, 0, len); | ||
} | ||
output.Flush(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// Общие сведения об этой сборке предоставляются следующим набором | ||
// набора атрибутов. Измените значения этих атрибутов для изменения сведений, | ||
// связанные с этой сборкой. | ||
[assembly: AssemblyTitle("oceanhornTXT")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("oceanhornTXT")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми | ||
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через | ||
// из модели COM задайте для атрибута ComVisible этого типа значение true. | ||
[assembly: ComVisible(false)] | ||
|
||
// Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM | ||
[assembly: Guid("1d53c280-5734-4e79-8af9-e3ca5ccc808d")] | ||
|
||
// Сведения о версии сборки состоят из указанных ниже четырех значений: | ||
// | ||
// Основной номер версии | ||
// Дополнительный номер версии | ||
// Номер сборки | ||
// Номер редакции | ||
// | ||
// Можно задать все значения или принять номера сборки и редакции по умолчанию | ||
// используя "*", как показано ниже: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" 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> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>oceanhornTXT</RootNamespace> | ||
<AssemblyName>oceanhornTXT</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="zlib.net, Version=1.0.3.0, Culture=neutral, PublicKeyToken=47d7877cb3620160"> | ||
<HintPath>packages\zlib.net.1.0.4.0\lib\zlib.net.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30717.126 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "oceanhornTXT", "oceanhornTXT.csproj", "{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1D53C280-5734-4E79-8AF9-E3CA5CCC808D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {6CD1B175-CE00-4FB5-9C0D-CF27677E588B} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="zlib.net" version="1.0.4.0" targetFramework="net472" /> | ||
</packages> |