bunch of stuff.

This commit is contained in:
morkt
2023-08-24 01:33:50 +04:00
parent ea096c52ef
commit 77fde27d26
119 changed files with 11078 additions and 619 deletions

View File

@@ -23,13 +23,15 @@
// IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using GameRes.Compression;
using ICSharpCode.SharpZipLib.BZip2;
// [000224][Uran] P.S. 3 ~Harem Night~
// [980828][Uran] College Terra Story
// [971218][Uran] GirlDollToy
namespace GameRes.Formats.Uran
{
@@ -38,9 +40,7 @@ namespace GameRes.Formats.Uran
public byte Method;
}
#if DEBUG
[Export(typeof(ArchiveFormat))]
#endif
public class NclOpener : ArchiveFormat
{
public override string Tag { get { return "NCL"; } }
@@ -96,9 +96,7 @@ namespace GameRes.Formats.Uran
if (2 == nclent.Method)
input = new ZLibStream (input, CompressionMode.Decompress);
else if (3 == nclent.Method)
{
// XXX bzip2 compression not implemented
}
input = new BZip2InputStream (input);
}
return input;
}
@@ -130,7 +128,7 @@ namespace GameRes.Formats.Uran
int b = BaseStream.ReadByte();
if (-1 != b)
{
b -= m_key;
b = (byte)(b - m_key);
}
return b;
}

145
Legacy/Uran/ImageDAR.cs Normal file
View File

@@ -0,0 +1,145 @@
//! \file ImageDAR.cs
//! \date 2022 May 11
//! \brief Uran image format.
//
// Copyright (C) 2022 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
using System.ComponentModel.Composition;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
// [970525][Uran] High School Terra Story
namespace GameRes.Formats.Uran
{
public class DarMetaData : ImageMetaData
{
public byte Version;
public int FrameCount;
public long FrameOffset;
public int RowSize;
}
[Export(typeof(ImageFormat))]
public class DarFormat : ImageFormat
{
public override string Tag { get { return "DAR"; } }
public override string Description { get { return "Uran image format"; } }
public override uint Signature { get { return 0x3A524144; } } // 'DAR:'
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (12);
byte version = header[5];
int frame_count = header.ToUInt16 (6);
if (header[4] != '8' || version > 1 || frame_count < 1)
return null;
file.Position = 0x40C;
int header_size = 8;
if (version != 0)
header_size = file.ReadUInt16();
long frame_offset = file.Position;
ushort width = file.ReadUInt16(); // +0
ushort height = file.ReadUInt16(); // +1
ushort row_size = file.ReadUInt16(); // +2
file.ReadUInt16(); // +3
int bpp = 8;
if (header_size >= 14)
{
file.ReadInt16(); // +4
file.ReadInt16(); // +5
file.ReadUInt16(); // +6 height
if (header_size >= 16)
{
int count = file.ReadUInt8(); // [14]
if (count + 18 <= header_size)
{
file.Seek (count - 1, SeekOrigin.Current);
bpp = file.ReadUInt8(); // [count+14]
}
}
}
return new DarMetaData {
Width = width,
Height = height,
BPP = bpp,
Version = version,
FrameCount = frame_count,
FrameOffset = frame_offset + header_size,
RowSize = row_size,
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var reader = new DarReader (file, (DarMetaData)info);
return reader.Unpack();
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("DarFormat.Write not implemented");
}
}
internal class DarReader
{
IBinaryStream m_input;
DarMetaData m_info;
public ImageMetaData Info { get { return m_info; } }
public BitmapPalette Palette { get; private set; }
public DarReader (IBinaryStream input, DarMetaData info)
{
m_input = input;
m_info = info;
}
public ImageData Unpack ()
{
if (8 == m_info.BPP)
{
m_input.Position = 0x0C;
Palette = ImageFormat.ReadPalette (m_input.AsStream);
}
int depth = m_info.BPP / 8;
long row_pos = m_info.FrameOffset;
int stride = m_info.iWidth * depth;
var pixels = new byte[stride * m_info.iHeight];
int dst = pixels.Length - stride;
while (dst >= 0)
{
m_input.Position = row_pos;
int x = m_input.ReadInt16();
int row_length = m_input.ReadUInt16();
if (row_length != 0)
m_input.Read (pixels, dst + x, row_length);
row_pos += m_info.RowSize;
dst -= stride;
}
PixelFormat format = depth == 1 ? PixelFormats.Indexed8 : PixelFormats.Bgr24;
return ImageData.Create (m_info, format, Palette, pixels, stride);
}
}
}

101
Legacy/Uran/ImageNCL.cs Normal file
View File

@@ -0,0 +1,101 @@
//! \file ImageNCL.cs
//! \date 2022 May 11
//! \brief Uran multi-frame image.
//
// Copyright (C) 2022 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
using GameRes.Compression;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace GameRes.Formats.Uran
{
public class NclMetaData : ImageMetaData
{
public int DataOffset;
}
[Export(typeof(ImageFormat))]
public class NclFormat : ImageFormat
{
public override string Tag { get { return "NCL/URAN"; } }
public override string Description { get { return "Uran multi-frame image format"; } }
public override uint Signature { get { return 0; } }
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
if (!file.Name.HasExtension (".ncl"))
return null;
var header = file.ReadHeader (0x10);
int size = header.ToInt32 (0);
int name_length = header.ToUInt16 (8);
if (size <= 1 || 0 == name_length || name_length > 0x100)
return null;
int pos = 10 + name_length + 6;
header = file.ReadHeader (pos + 9);
var name = header.GetCString (10, name_length);
if (!name.HasExtension (".bmp"))
return null;
int header_size = header.ToUInt16 (pos-2);
if (header_size < 9 || header_size > 0x40 || pos + header_size + size > file.Length)
return null;
uint width = header.ToUInt32 (pos+1);
uint height = header.ToUInt32 (pos+5);
return new NclMetaData {
Width = width,
Height = height,
BPP = 8,
DataOffset = pos + header_size,
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (NclMetaData)info;
file.Position = meta.DataOffset;
Stream input = new NclSubStream (file.AsStream, 10, true);
try
{
int method = input.ReadByte();
if (2 == method)
input = new ZLibStream (input, CompressionMode.Decompress);
var decoder = new BmpBitmapDecoder (input,
BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
var frame = decoder.Frames[0];
frame.Freeze();
return new ImageData (frame, info);
}
finally
{
input.Dispose();
}
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("NclFormat.Write not implemented");
}
}
}