Skip to content

Commit

Permalink
Added AAUnlimited compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed Nov 14, 2016
1 parent 7af8ef8 commit af1b274
Show file tree
Hide file tree
Showing 49 changed files with 9,602 additions and 13 deletions.
56 changes: 46 additions & 10 deletions AA2Data/AA2Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using PNGNet;

namespace AA2Data
{
Expand All @@ -16,16 +17,40 @@ public byte[] raw
get
{
byte[] buffer = new byte[_image.Length + Offset];
using (MemoryStream mem = new MemoryStream(_image.Length + Offset))
using (MemoryStream mem = new MemoryStream()) //_image.Length + Offset
using (BinaryWriter bw = new BinaryWriter(mem))
{
//AA2Unlimited chunk
using (MemoryStream ms = new MemoryStream(_image))
using (MemoryStream ex = new MemoryStream())
{
var img = new PNGImage(ms);

bool containsChunk = img.Chunks.Any(x => x.Type == "aaUd");

if (!containsChunk && AA2UChunk != null)
{
img.Chunks.Insert(img.Chunks.FindIndex(x => x.Type == "IEND"), AA2UChunk);
}
else if (AA2UChunk != null)
{
int index = img.Chunks.FindIndex(x => x.Type == "aaUd");
img.Chunks.RemoveAt(index);
img.Chunks.Insert(index, AA2UChunk);
}

img.Write(ex, false);

_image = ex.ToArray();
}

bw.Write(_image);
bw.Write(data.raw);
bw.Write(RosterLength);
bw.Write(_RosterImage);
bw.Write(Offset);
mem.Position = 0;
mem.Read(buffer, 0, (int)mem.Length);

buffer = mem.ToArray();
}
return buffer;
}
Expand All @@ -34,17 +59,28 @@ public byte[] raw
using (MemoryStream mem = new MemoryStream(value))
using (BinaryReader br = new BinaryReader(mem))
{
br.BaseStream.Seek(-4, SeekOrigin.End);
int offset = br.ReadInt32();
br.BaseStream.Seek(0, SeekOrigin.Begin);
br.BaseStream.Seek(-4, SeekOrigin.End);
int offset = br.ReadInt32();
br.BaseStream.Seek(0, SeekOrigin.Begin);

_image = br.ReadBytes((int)br.BaseStream.Length - offset);
data.raw = br.ReadBytes(3011);
int length = br.ReadInt32();
_RosterImage = br.ReadBytes(length);
_image = br.ReadBytes((int)br.BaseStream.Length - offset);

//AA2Unlimited chunk
using (MemoryStream ms = new MemoryStream(_image))
{
var img = new PNGImage(ms);

AA2UChunk = img.Chunks.DefaultIfEmpty(null).FirstOrDefault(x => x.Type == "aaUd");
}

data.raw = br.ReadBytes(3011);
int length = br.ReadInt32();
_RosterImage = br.ReadBytes(length);
}
}
}

private Chunk AA2UChunk = null;

private byte[] _image;
public Image Image
Expand Down
6 changes: 6 additions & 0 deletions AA2Data/AA2Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<Compile Include="LST.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PNGNet\PNGNet.csproj">
<Project>{d5cb46e9-e69b-4b45-a15a-c0087833dd4d}</Project>
<Name>PNGNet</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
10 changes: 10 additions & 0 deletions AA2Snowflake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchClothPlugin", "Plugins
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoseViewerPlugin", "Plugins\PoseViewerPlugin\PoseViewerPlugin.csproj", "{66CF33CD-7987-4B0A-958A-C9D7A2B07F8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PNGNet", "PNGNet\PNGNet.csproj", "{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -77,6 +79,14 @@ Global
{66CF33CD-7987-4B0A-958A-C9D7A2B07F8B}.Release|Any CPU.Build.0 = Release|Any CPU
{66CF33CD-7987-4B0A-958A-C9D7A2B07F8B}.Release|x86.ActiveCfg = Release|x86
{66CF33CD-7987-4B0A-958A-C9D7A2B07F8B}.Release|x86.Build.0 = Release|x86
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Debug|x86.Build.0 = Debug|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Release|Any CPU.Build.0 = Release|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Release|x86.ActiveCfg = Release|Any CPU
{D5CB46E9-E69B-4B45-A15A-C0087833DD4D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion AA2Snowflake/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
v2.2
v2.3
+ Added AAUnlimited compatibility

v2.2
+ Changed TGA handler to something more stable
+ Increased the limits of pose numbers again
+ Updated SB3U libary
Expand Down
4 changes: 2 additions & 2 deletions AA2Snowflake/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
96 changes: 96 additions & 0 deletions PNGNet/ByteStreamReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace PNGNet
{
public class ByteStreamReader : Stream
{
private byte[] _data;
private long _position;

public ByteStreamReader(byte[] data)
{
_data = data;
_position = 0;
}

public override bool CanRead
{
get { return true; }
}

public override bool CanSeek
{
get { return true; }
}

public override bool CanWrite
{
get { return false; }
}

public override void Flush()
{
// don't need to flush
}

public override long Length
{
get { return _data.LongLength; }
}

public override long Position
{
get { return _position; }
set { _position = value; }
}

public override int Read(byte[] buffer, int offset, int count)
{
long length = (_position + count > _data.Length) ? _data.Length - _position - 1 : count;

if (_position >= _data.Length)
return 0;

for (long i = 0; i < length; i++, _position++)
buffer[offset + i] = _data[_position];

return (int)length;
}

public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
_position = offset;
break;

case SeekOrigin.Current:
_position += offset;
break;

case SeekOrigin.End:
_position = _data.Length - 1 + offset;
break;

default:
throw new ArgumentException();
}

return _position;
}

public override void SetLength(long value)
{
throw new NotSupportedException();
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}
}
72 changes: 72 additions & 0 deletions PNGNet/CRC32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* PNG.Net
*
* Copyright (C) 2008 wj32
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace PNGNet
{
/// <summary>
/// Provides functions to calculate CRC32 hashes of data.
/// </summary>
public static class CRC32
{
private const uint Polynomial = 0xedb88320;
private static uint[] Table;

/// <summary>
/// Initializes the CRC32 table.
/// </summary>
public static void Initialize()
{
uint h = 1;

Table = new uint[256];
Table[0] = 0;

for (int i = 128; i != 0; i >>= 1)
{
h = (h >> 1) ^ (((h & 1) != 0) ? Polynomial : 0);

for (int j = 0; j < 256; j += 2 * i)
Table[i + j] = Table[j] ^ h;
}
}

/// <summary>
/// Performs CRC32 on a sequence of bytes. Initializes the table if not already intialized.
/// </summary>
/// <param name="crc32">Specify the value of the previous hash, or specify 0.</param>
/// <param name="data">The data to be hashed.</param>
/// <returns></returns>
public static uint Hash(uint crc32, byte[] data, int offset, int length)
{
if (Table == null)
Initialize();

crc32 ^= 0xffffffff;

for (int i = offset; i < offset + length; i++)
crc32 = (crc32 >> 8) ^ Table[(crc32 ^ data[i]) & 0xff];

return crc32 ^ 0xffffffff;
}
}
}
Loading

0 comments on commit af1b274

Please sign in to comment.