Skip to content

Commit

Permalink
Implemented dat decompression, 256 and WAKU0 image editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkmet98 committed Mar 9, 2021
1 parent 8e52ae8 commit 4af5d98
Show file tree
Hide file tree
Showing 20 changed files with 540 additions and 21 deletions.
6 changes: 6 additions & 0 deletions AdolTranslator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{326CED66-327B-482F-8146-9DDBA1D54B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Debug|x86.ActiveCfg = Debug|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Debug|x86.Build.0 = Debug|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Release|Any CPU.Build.0 = Release|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Release|x86.ActiveCfg = Release|Any CPU
{326CED66-327B-482F-8146-9DDBA1D54B22}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
23 changes: 22 additions & 1 deletion AdolTranslator/AdolTranslator.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsmResolver" Version="4.3.0" />
<PackageReference Include="AsmResolver.PE" Version="4.3.0" />
<PackageReference Include="AsmResolver.PE.File" Version="4.3.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.1" />
<PackageReference Include="Yarhl" Version="3.1.0" />
<PackageReference Include="Yarhl.Media" Version="3.1.0" />
</ItemGroup>
Expand All @@ -18,6 +27,18 @@
<Reference Include="ElfManipulator">
<HintPath>lib\ElfManipulator.dll</HintPath>
</Reference>
<Reference Include="Texim">
<HintPath>lib\Texim.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="Diary.po">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="GUI 2.po">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
50 changes: 35 additions & 15 deletions AdolTranslator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
using AdolTranslator.Containers.Dat;
using AdolTranslator.Elf;
using AdolTranslator.Image._256;
using AdolTranslator.Image.Waku0;
using AdolTranslator.Text.Dat;
using Yarhl.FileSystem;
using Yarhl.IO;
using Yarhl.Media.Text;
using Binary2Dat = AdolTranslator.Text.Dat.Binary2Dat;

Expand All @@ -17,7 +19,10 @@ static void Main(string[] args)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

Console.WriteLine("AdolTranslator - A simple Ys translator By Darkmet98.");
Console.WriteLine("AdolTranslator 1.0 - A simple program for Ys fan-translations by Darkmet98.\n" +
"Thanks to Twn for ASM Hacks and explanations.\n" +
"Thanks to Kaplas for waku0 swizzling and C to C# code port.\n" +
"Thanks to Pleonex for Yarhl libraries.");

if (args.Length > 3 || args.Length == 0)
{
Expand Down Expand Up @@ -55,23 +60,38 @@ static void Main(string[] args)
case ".EXE":
var exePatch = new PatchExe(args[0]);
break;
}

}
/*case ".256":
var pal = NodeFactory.FromFile("COLOR.PAL").TransformWith(new Binary2Palette())
.GetFormatAs<Palette>();
var image = NodeFactory.FromFile(args[0]).TransformWith(new Binary2Image256()
{
PalettePassed = pal
}).GetFormatAs<Image256>();
//image.Palette.ToWinPaletteFormat("paleta.pal", 0, false);
image.Pixels.CreateBitmap(image.Palette, 0).Save(args[0] + ".png");
break;*/
case ".BIN":
if (args[0].Contains("WAKU0"))
{
var imageWaku = NodeFactory.FromFile(args[0]).TransformWith(new Binary2Waku0()).GetFormatAs<Waku0>();
imageWaku.Pixels.Save(args[0] + ".png");
}
else
throw new NotSupportedException();

public static void Decompress(string path)
{
using (FileStream originalFileStream = new FileStream(path, FileMode.Append))
{
using (FileStream decompressedFileStream = File.Create(path + ".dev"))
{
using (DeflateStream decompressionStream = new DeflateStream(originalFileStream, CompressionMode.Compress))
break;
case ".PNG":
if (args[0].Contains("WAKU0"))
{
decompressionStream.CopyTo(decompressedFileStream);

var waku02Binary = new Waku02Binary(args[0]);
File.WriteAllBytes(args[0] + "_new.bin", waku02Binary.Convert());
}
}
else
throw new NotSupportedException();

break;
}

}
}
}
2 changes: 1 addition & 1 deletion AdolTranslator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"AdolTranslator": {
"commandName": "Project",
"commandLineArgs": "ys1plus.exe"
"commandLineArgs": "WAKU0.BIN.png"
}
}
}
114 changes: 114 additions & 0 deletions AdolTranslator/Ys I - II Chronicles+/Compression/DatDecompression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;

namespace AdolTranslator.Compression
{
class DatDecompression
{
// Thanks to twn for explaining how decompression works.
byte cVar1;
uint bVar2;
int addr_pixel;
int pcVar3;
int iVar4;
uint uVar5;
int pcVar6;
ushort short_read;
List<byte> result = new List<byte>();
public byte[] Decompression(int size, byte[] array, int fileLength)
{
result.Clear();
cVar1 = array[6];

if (size < 5)
{
return array;
}

iVar4 = size - 5;
pcVar6 = 5;
do
{
do
{
while (true)
{
while (true)
{
while (true)
{
if (iVar4 == 0)
{
return result.ToArray();
}

if (array[pcVar6] == cVar1)
break;
result.Add(array[pcVar6]);
addr_pixel++;
pcVar6 += 1;
iVar4 += -1;

}

bVar2 = array[pcVar6 + 1];

if (4 < bVar2) break;
if (bVar2 != 0)
{
return result.ToArray();
}

result.Add(cVar1);
addr_pixel++;
pcVar6 += 2;
iVar4 += -2;
}

uVar5 = bVar2;

short_read = BitConverter.ToUInt16(array, pcVar6 + 2);
pcVar3 = addr_pixel + (-1 - short_read);

pcVar6 += 4;
iVar4 += -4;
if (pcVar6 > fileLength)
return result.ToArray();

if (pcVar3 < 0)
break;

DecompressionRoutine();
}
} while (bVar2 == 0);



do
{

result.Add(0);
addr_pixel++;
pcVar3 += 1;
uVar5 -= 1;

if (0 <= pcVar3)
DecompressionRoutine();

} while (uVar5 != 0);
} while (true);
}

private void DecompressionRoutine()
{
while (uVar5 != 0)
{

result.Add(result[pcVar3]);
addr_pixel++;
pcVar3 += 1;
uVar5 -= 1;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DatContainer Convert(BinaryFormat source)
{
reader = new DataReader(source.Stream)
{
Stream = { Position = 0 }
Stream = {Position = 0}
};

datContainer = new DatContainer();
Expand All @@ -39,13 +39,46 @@ private void DumpHeader()

private void DumpData()
{
var i = 0;
foreach (var datPosition in datContainer.Positions)
{
var datDec = new Compression.DatDecompression();
reader.Stream.Position = datPosition;
var size = reader.ReadInt32();
reader.Stream.Position -= 4;
datContainer.Blocks.Add(reader.ReadBytes(size));
var dec = datDec.Decompression(size, reader.ReadBytes(size), (int) reader.Stream.Length);
datContainer.Blocks.Add(dec);
GetBlockInfo(dec.Length, i++);
}
}

private void GetBlockInfo(int arrayLength, int i)
{
datContainer.Information = "DUMMY";
return;
int delW = 16;
int delH = 8;
int width = 0;
int height = 0;
int dresult;

do
{
width += delW;
height += delH;
dresult = width * height;
if (dresult > arrayLength)
{
delW = 16;
delH = 16;
width = 0;
height = 0;
}
}
while (dresult != (arrayLength));

datContainer.Information += $"{i}.bin\nWIDTH:{width}\nHEIGHT:{height}\n\n";

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class DatContainer : IFormat
{
public List<int> Positions { get; }
public List<byte[]> Blocks { get; }
public string Information { get; set; }

public DatContainer()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Yarhl.FileFormat;
using System.Text;
using Yarhl.FileFormat;
using Yarhl.FileSystem;

namespace AdolTranslator.Containers.Dat
Expand All @@ -15,6 +16,8 @@ public NodeContainerFormat Convert(DatContainer source)
container.Root.Add(GenerateSingleNode($"{i}.bin", source.Blocks[i]));
}

container.Root.Add(GenerateSingleNode("Info.txt", Encoding.UTF8.GetBytes(source.Information)));

return container;
}

Expand Down
37 changes: 37 additions & 0 deletions AdolTranslator/Ys I - II Chronicles+/Image/256/Binary2Image256.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Drawing;
using Texim;
using Yarhl.FileFormat;
using Yarhl.IO;

namespace AdolTranslator.Image._256
{
class Binary2Image256 : IConverter<BinaryFormat, Image256>
{
public Palette PalettePassed { get; set; }
public Image256 Convert(BinaryFormat source)
{
var result = new Image256();
var reader = new DataReader(source.Stream);

var width = reader.ReadInt32();
var height = reader.ReadInt32();


result.Pixels = new PixelArray
{
Width = width,
Height = height,
};

result.Palette = PalettePassed;
result.Pixels.SetData(
reader.ReadBytes((int)reader.Stream.Length-0x8),
PixelEncoding.HorizontalTiles,
ColorFormat.Indexed_8bpp,
new Size(width, height));

return result;
}
}
}
Loading

0 comments on commit 4af5d98

Please sign in to comment.