NotTransorm class moved to common namespace.

This commit is contained in:
morkt 2015-07-23 20:23:14 +04:00
parent 674a1b8c51
commit ce54fb1a4e
3 changed files with 44 additions and 37 deletions

View File

@ -27,6 +27,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
namespace GameRes.Formats namespace GameRes.Formats
@ -296,7 +297,14 @@ namespace GameRes.Formats
Compress, Compress,
}; };
internal sealed class LzssCoroutine public class LzssSettings
{
public int FrameSize { get; set; }
public byte FrameFill { get; set; }
public int FrameInitPos { get; set; }
}
internal sealed class LzssCoroutine : LzssSettings
{ {
byte[] m_buffer; byte[] m_buffer;
int m_offset; int m_offset;
@ -306,9 +314,6 @@ namespace GameRes.Formats
IEnumerator<int> m_unpack; IEnumerator<int> m_unpack;
public int FrameSize { get; set; }
public byte FrameFill { get; set; }
public int FrameInitPos { get; set; }
public bool Eof { get; private set; } public bool Eof { get; private set; }
public LzssCoroutine (Stream input) public LzssCoroutine (Stream input)
@ -394,6 +399,8 @@ namespace GameRes.Formats
m_should_dispose = !leave_open; m_should_dispose = !leave_open;
} }
public LzssSettings Config { get { return m_reader; } }
public override bool CanRead { get { return m_input.CanRead; } } public override bool CanRead { get { return m_input.CanRead; } }
public override bool CanSeek { get { return false; } } public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return false; } } public override bool CanWrite { get { return false; } }
@ -626,4 +633,36 @@ namespace GameRes.Formats
return (uint)(((-1 << m_cached_bits) & mask) >> m_cached_bits); return (uint)(((-1 << m_cached_bits) & mask) >> m_cached_bits);
} }
} }
public sealed class NotTransform : ICryptoTransform
{
private const int BlockSize = 256;
public bool CanReuseTransform { get { return true; } }
public bool CanTransformMultipleBlocks { get { return true; } }
public int InputBlockSize { get { return BlockSize; } }
public int OutputBlockSize { get { return BlockSize; } }
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount,
byte[] outputBuffer, int outputOffset)
{
for (int i = 0; i < inputCount; ++i)
{
outputBuffer[outputOffset++] = (byte)~inputBuffer[inputOffset+i];
}
return inputCount;
}
public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
{
byte[] outputBuffer = new byte[inputCount];
TransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, 0);
return outputBuffer;
}
public void Dispose ()
{
System.GC.SuppressFinalize (this);
}
}
} }

View File

@ -398,36 +398,4 @@ namespace GameRes.Formats.Kogado
} }
} }
} }
public sealed class NotTransform : ICryptoTransform
{
private const int BlockSize = 256;
public bool CanReuseTransform { get { return true; } }
public bool CanTransformMultipleBlocks { get { return true; } }
public int InputBlockSize { get { return BlockSize; } }
public int OutputBlockSize { get { return BlockSize; } }
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount,
byte[] outputBuffer, int outputOffset)
{
for (int i = 0; i < inputCount; ++i)
{
outputBuffer[outputOffset++] = (byte)~inputBuffer[inputOffset+i];
}
return inputCount;
}
public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
{
byte[] outputBuffer = new byte[inputCount];
TransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, 0);
return outputBuffer;
}
public void Dispose ()
{
System.GC.SuppressFinalize (this);
}
}
} }

View File

@ -102,7 +102,7 @@ namespace GameRes.Formats.SPack
if (null == packed_entry || !packed_entry.IsPacked) if (null == packed_entry || !packed_entry.IsPacked)
return input; return input;
if (1 == packed_entry.Method) if (1 == packed_entry.Method)
return new CryptoStream (input, new Kogado.NotTransform(), CryptoStreamMode.Read); return new CryptoStream (input, new NotTransform(), CryptoStreamMode.Read);
if (2 == packed_entry.Method) if (2 == packed_entry.Method)
{ {
using (var reader = new PackedReader (packed_entry, input)) using (var reader = new PackedReader (packed_entry, input))