Release v0.4.7.1

A3DA
This commit is contained in:
Kuji Kitamura
2019-08-07 21:24:59 +03:00
parent 6e2f5746b0
commit b26cdc8b5c
41 changed files with 625 additions and 539 deletions
+2
View File
@@ -1,5 +1,7 @@
.vs
build
KKdBaseLib/bin
KKdBaseLib/obj
KKdMainLib/bin
KKdMainLib/obj
KKdMathLib/bin
+13 -3
View File
@@ -99,7 +99,6 @@ namespace KKdBaseLib
{ if (IsBE) { for (byte i = 0; i < Len; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < Len; i++) { LE |= bufPtr[i]; if (i < Len - 1) LE <<= 8; } } return LE; }
public static sbyte CITSB(this int c)
{ if (c > 0x0000007F) c = 0x0000007F;
else if (c < -0x00000080) c = -0x00000080; return ( sbyte)c; }
@@ -162,6 +161,16 @@ namespace KKdBaseLib
{ c = c.Round(); if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
else if (c < 0x00000000) c = 0x00000000; return ( uint)c; }
public static int ToInt32(this float f) => *( int*)&f;
public static uint ToUInt32(this float f) => *( uint*)&f;
public static long ToInt64(this double f) => *( long*)&f;
public static ulong ToUInt64(this double f) => *(ulong*)&f;
public static float ToSingle(this int i) => *( float*)&i;
public static float ToSingle(this uint i) => *( float*)&i;
public static double ToSingle(this long i) => *(double*)&i;
public static double ToSingle(this ulong i) => *(double*)&i;
public static sbyte* GetPtr(this sbyte[] array) { fixed ( sbyte* tempPtr = array) return tempPtr; }
public static byte* GetPtr(this byte[] array) { fixed ( byte* tempPtr = array) return tempPtr; }
public static short* GetPtr(this short[] array) { fixed ( short* tempPtr = array) return tempPtr; }
@@ -179,8 +188,9 @@ namespace KKdBaseLib
public static string ToString(this object d)
{
if (d == null) return "Null";
else if (d is float F32) return ToString(F32);
else if (d is double F64) return ToString(F64);
else if (d is bool Boolean) return Boolean ? "true" : "false";
else if (d is float F32 ) return ToString(F32);
else if (d is double F64 ) return ToString(F64);
return d.ToString();
}
+18
View File
@@ -0,0 +1,18 @@
namespace KKdBaseLib
{
public enum Format : byte
{
NULL = 0,
DT = 1,
PDA = 2,
DT2 = 3,
DTe = 4,
F = 5,
FT = 6,
F2LE = 7,
F2BE = 8,
MGF = 9,
X = 10,
XHD = 11,
}
}
+6 -4
View File
@@ -2,6 +2,8 @@
{
public interface IKeyFrame<TKey, TVal>
{
TKey Frame { get; set; }
IKeyFrame<TKey, TVal> Check();
IKeyFrame<TKey, TVal> ToKeyFrameT0();
IKeyFrame<TKey, TVal> ToKeyFrameT1();
@@ -13,7 +15,7 @@
public struct KeyFrameT0<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TKey Frame { get; set; }
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
@@ -34,7 +36,7 @@
public struct KeyFrameT1<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TKey Frame { get; set; }
public TVal Value;
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
@@ -57,7 +59,7 @@
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TKey Frame { get; set; }
public TVal Value;
public TVal Interpolation;
@@ -94,7 +96,7 @@
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TKey Frame { get; set; }
public TVal Value;
public TVal Interpolation1;
public TVal Interpolation2;
+3 -1
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?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>
@@ -41,9 +41,11 @@
<ItemGroup>
<Compile Include="DCC.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Format.cs" />
<Compile Include="Half.cs" />
<Compile Include="IKeyFrame.cs" />
<Compile Include="KKdList.cs" />
<Compile Include="MsgPack.cs" />
<Compile Include="Pointer.cs" />
<Compile Include="Text.cs" />
<Compile Include="Vector.cs" />
+20 -12
View File
@@ -1,4 +1,5 @@
using System.Collections;
using System.Collections.Generic;
namespace KKdBaseLib
{
@@ -17,20 +18,12 @@ namespace KKdBaseLib
public bool NotNull => array != null;
public int Capacity { get => array != null ? array.Length : -1;
set
{
if (array != null) System.Array.Resize(ref array, value);
else array = new T[value];
}
}
set { if (array != null) System.Array.Resize(ref array, value); else array = new T[value];
if (Count >= value) Count = value; } }
public KKdList(T[] Array)
{
index = 0;
Count = Array.Length;
array = Array;
}
{ index = 0; Count = Array.Length; array = Array; }
public T Current => index < Count ? array[index] : default;
@@ -66,15 +59,17 @@ namespace KKdBaseLib
for (int i = index + 1; i < Count; i++)
array[i - 1] = array[i];
Count--;
}
public void RemoveRange(int IndexStart, int IndexEnd)
{
if (IndexEnd - IndexStart < 1) return;
if (IsNull) return;
if (IndexEnd - IndexStart < 1) return;
for (int i = IndexStart; i < Count; i++)
array[i] = array[i + IndexEnd - IndexStart];
Count -= IndexEnd - IndexStart;
}
public T[] ToArray() => array;
@@ -98,5 +93,18 @@ namespace KKdBaseLib
else if (array[i] .Equals(val) ) return i;
return -1;
}
public void Sort()
{ List<T> List = (List<T>)this; List.Sort(); array = List.ToArray(); Count = List.Count; }
public static explicit operator KKdList<T>( List<T> List) =>
new KKdList<T> { array = List.ToArray(), Count = List.Count };
public static explicit operator List<T>(KKdList<T> List)
{
List<T> list = new List<T>();
for (int i = 0; i < List.Count; i++) list.Add(List[i]);
return list;
}
}
}
@@ -1,7 +1,6 @@
using System;
using KKdBaseLib;
namespace KKdMainLib.MessagePack
namespace KKdBaseLib
{
public struct MsgPack : IDisposable, IEquatable<MsgPack>
{
@@ -107,7 +106,7 @@ namespace KKdMainLib.MessagePack
public MsgPack Add(string Val, ulong val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
public byte ReadUInt8(string Name) => ReadNUInt8(Name).GetValueOrDefault();
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyVersion("0.0.1.1")]
[assembly: AssemblyFileVersion("0.0.1.1")]
+1 -2
View File
@@ -10,8 +10,7 @@
{ this.X = X; this.Y = Y; this.Z = Z; }
public double Length => (X * X + Y * Y + Z * Z).Sqrt();
public Vector3 Normalized => this = new Vector3()
{ X = X * (1 / Length), Y = Y * (1 / Length), Z = Z * (1 / Length) };
public Vector3 Normalized => this = Length == 0 ? new Vector3() : this / Length;
public static Vector3 operator +(Vector3 left, Vector3 right)
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; return left; }
+1 -2
View File
@@ -11,8 +11,7 @@
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public double Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
public Vector4 Normalized => this = new Vector4()
{ X = X * (1 / Length), Y = Y * (1 / Length), Z = Z * (1 / Length), W = W * (1 / Length) };
public Vector4 Normalized => this = Length == 0 ? new Vector4() : this / Length;
public static Vector4 operator +(Vector4 left, Vector4 right)
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; }
Binary file not shown.
@@ -1 +0,0 @@
add7b87062355c62d41e72dacf09abaf3e41d478
@@ -1,3 +0,0 @@
F:\Source\PD_Tool\KKdBaseLib\bin\KKdBaseLib.dll
F:\Source\PD_Tool\KKdBaseLib\obj\Release\KKdBaseLib.csproj.CoreCompileInputs.cache
F:\Source\PD_Tool\KKdBaseLib\obj\Release\KKdBaseLib.dll
Binary file not shown.
+50 -60
View File
@@ -3,13 +3,13 @@ using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.F2nd;
using KKdMainLib.MessagePack;
using Extensions = KKdBaseLib.Extensions;
namespace KKdMainLib.A3DA
{
public class A3DA
{
private const bool A3DCOpt = true;
private bool A3DCOpt = true;
private const string d = ".";
private int i, i0, i1;
@@ -24,7 +24,7 @@ namespace KKdMainLib.A3DA
private Dictionary<int?, double?> UsedValues;
private Dictionary<string, object> Dict;
private bool IsX => Data.Format == Main.Format.X || Data.Format == Main.Format.XHD;
private bool IsX => Data.Format == Format.X || Data.Format == Format.XHD;
public Stream IO;
public A3DAData Data;
@@ -48,7 +48,7 @@ namespace KKdMainLib.A3DA
Data = new A3DAData();
Header Header = new Header();
Data.Format = IO.Format = Main.Format.F;
Data.Format = IO.Format = Format.F;
Header.SectionSignature = IO.ReadInt32();
if (Header.SectionSignature == 0x41443341)
{ Header = IO.ReadHeader(true, true); Data.Format = Header.Format; }
@@ -60,7 +60,7 @@ namespace KKdMainLib.A3DA
if (Header.SectionSignature == 0x5F5F5F41)
{
IO.Position = 0x10;
Header.Format = IO.Format = Main.Format.DT;
Header.Format = IO.Format = Format.DT;
}
else if (Header.SectionSignature == 0x5F5F5F43)
{
@@ -82,7 +82,7 @@ namespace KKdMainLib.A3DA
}
else { IO.Close(); return 0; }
if (Header.Format == Main.Format.DT)
if (Header.Format == Format.DT)
Data.StringLength = IO.Length - 0x10;
string[] STRData = IO.ReadString(Data.StringLength).Replace("\r", "").Split('\n');
@@ -110,6 +110,7 @@ namespace KKdMainLib.A3DA
nameView = "";
dataArray = null;
Dict = null;
IO = null;
return 1;
}
@@ -168,14 +169,14 @@ namespace KKdMainLib.A3DA
if (Dict.FindValue(out value, "dof.name"))
{
Data.DOF = new DOF { Name = value };
Data.Format = Main.Format.FT;
Data.Format = Format.FT;
Data.DOF.MT = Dict.ReadMT("dof" + d);
}
if (Dict.FindValue(out value, "ambient.length"))
{
Data.Ambient = new Ambient[int.Parse(value)];
Data.Format = Main.Format.MGF;
Data.Format = Format.MGF;
for (i0 = 0; i0 < Data.Ambient.Length; i0++)
{
name = "ambient" + d + i0 + d;
@@ -343,7 +344,7 @@ namespace KKdMainLib.A3DA
if (Dict.FindValue(out value, "material_list.length"))
{
Data.MaterialList = new MaterialList[int.Parse(value)];
Data.Format = Main.Format.X;
Data.Format = Format.X;
for (i0 = 0; i0 < Data.MaterialList.Length; i0++)
{
name = "material_list" + d + i0 + d;
@@ -488,7 +489,7 @@ namespace KKdMainLib.A3DA
IO.Write("_.file_name=", Data._.FileName);
IO.Write("_.property.version=", Data._.PropertyVersion);
if (Data.Ambient != null && Data.Format == Main.Format.MGF)
if (Data.Ambient != null && Data.Format == Format.MGF)
{
SO0 = Data.Ambient.Length.SortWriter();
SOi0 = 0;
@@ -569,7 +570,7 @@ namespace KKdMainLib.A3DA
IO.Write("curve.length=", Data.Curve.Length);
}
if (Data.DOF != null && Data.Format == Main.Format.FT)
if (Data.DOF != null && Data.Format == Format.FT)
{
IO.Write("dof.name=", Data.DOF.Name);
IO.Write(Data.DOF.MT, "dof" + d, A3DC, IsX);
@@ -1014,7 +1015,7 @@ namespace KKdMainLib.A3DA
public byte[] A3DCWriter()
{
if (A3DCOpt) UsedValues = new Dictionary<int?, double?>();
if (Data.Format < Main.Format.F2LE) Data._.CompressF16 = null;
if (Data.Format < Format.F2LE) Data._.CompressF16 = null;
IO = File.OpenWriter();
for (byte i = 0; i < 2; i++)
@@ -1025,9 +1026,9 @@ namespace KKdMainLib.A3DA
if (Data.CameraRoot != null)
for (i0 = 0; i0 < Data.CameraRoot.Length; i0++)
{
IO.WriteOffset(ref Data.CameraRoot[i0].Interest, ReturnToOffset);
IO.WriteOffset(ref Data.CameraRoot[i0]. MT, ReturnToOffset);
IO.WriteOffset(ref Data.CameraRoot[i0].VP. MT, ReturnToOffset);
IO.WriteOffset(ref Data.CameraRoot[i0].Interest, ReturnToOffset);
}
if (Data.DOF != null)
@@ -1085,12 +1086,12 @@ namespace KKdMainLib.A3DA
if (Data.CameraRoot != null)
for (i0 = 0; i0 < Data.CameraRoot.Length; i0++)
{
Write(ref Data.CameraRoot[i0].Interest);
Write(ref Data.CameraRoot[i0]. MT);
Write(ref Data.CameraRoot[i0].VP. MT);
Write(ref Data.CameraRoot[i0].VP.FOV );
Write(ref Data.CameraRoot[i0].VP.FocalLength);
Write(ref Data.CameraRoot[i0].VP.Roll );
Write(ref Data.CameraRoot[i0].VP.FocalLength);
Write(ref Data.CameraRoot[i0].VP.FOV );
Write(ref Data.CameraRoot[i0].Interest);
}
if (Data.Chara != null)
@@ -1101,16 +1102,14 @@ namespace KKdMainLib.A3DA
for (i0 = 0; i0 < Data.Curve.Length; i0++)
Write(ref Data.Curve[i0].CV);
if (Data.DOF != null && Data.Format == Main.Format.FT)
if (Data.DOF != null && Data.Format == Format.FT)
Write(ref Data.DOF.MT);
if (Data.Fog != null)
for (i0 = 0; i0 < Data.Fog.Length; i0++)
if (Data.Light != null)
for (i0 = 0; i0 < Data.Light.Length; i0++)
{
Write(ref Data.Fog[i0].Density);
Write(ref Data.Fog[i0].Diffuse);
Write(ref Data.Fog[i0].End );
Write(ref Data.Fog[i0].Start );
Write(ref Data.Light[i0].Position );
Write(ref Data.Light[i0].SpotDirection);
}
if (Data.Light != null)
@@ -1120,8 +1119,15 @@ namespace KKdMainLib.A3DA
Write(ref Data.Light[i0].Diffuse );
Write(ref Data.Light[i0].Incandescence);
Write(ref Data.Light[i0].Specular );
Write(ref Data.Light[i0].Position );
Write(ref Data.Light[i0].SpotDirection);
}
if (Data.Fog != null)
for (i0 = 0; i0 < Data.Fog.Length; i0++)
{
Write(ref Data.Fog[i0].Density);
Write(ref Data.Fog[i0].Diffuse);
Write(ref Data.Fog[i0].Start );
Write(ref Data.Fog[i0].End );
}
if (Data.MObjectHRC != null)
@@ -1178,8 +1184,8 @@ namespace KKdMainLib.A3DA
Write(ref Data.PostProcess.Diffuse );
Write(ref Data.PostProcess.Specular );
Write(ref Data.PostProcess.LensFlare);
Write(ref Data.PostProcess.LensGhost);
Write(ref Data.PostProcess.LensShaft);
Write(ref Data.PostProcess.LensGhost);
}
IO.Align(0x10, true);
@@ -1188,7 +1194,7 @@ namespace KKdMainLib.A3DA
byte[] A3DAData = A3DAWriter(true);
IO = File.OpenWriter();
IO.Offset = Data.Format > Main.Format.FT ? 0x40 : 0;
IO.Offset = Data.Format > Format.FT ? 0x40 : 0;
IO.Position = 0x40;
Data.StringOffset = IO.Position;
@@ -1218,13 +1224,13 @@ namespace KKdMainLib.A3DA
IO.WriteEndian(Data.BinaryLength, true);
IO.WriteEndian(0x20, true);
if (Data.Format > Main.Format.FT)
if (Data.Format > Format.FT)
{
IO.Position = A3DCEnd;
IO.WriteEOFC(0);
IO.Offset = 0;
IO.Position = 0;
Header Header = new Header { Signature = 0x41443341, Format = Main.Format.F2LE,
Header Header = new Header { Signature = 0x41443341, Format = Format.F2LE,
DataSize = A3DCEnd, SectionSize = A3DCEnd, InnerSignature = 0x01131010 };
IO.Write(Header, true);
}
@@ -1254,7 +1260,7 @@ namespace KKdMainLib.A3DA
Key.BinOffset = IO.Position;
int Type = Key.Type.Value;
if (Key.EPTypePost.HasValue) Type |= (Key.EPTypePost.Value & 0xF) << 12;
if (Key.EPTypePre .HasValue) Type |= (Key.EPTypePre .Value & 0xF) << 12;
if (Key.EPTypePre .HasValue) Type |= (Key.EPTypePre .Value & 0xF) << 8;
IO.Write(Type);
IO.Write(0x00);
IO.Write((float)Key.Max);
@@ -2162,7 +2168,7 @@ namespace KKdMainLib.A3DA
else if (Key.RawData.KeyType == 3) for (i = 0; i < Key.Trans.Length; i++)
IO.Write(Key.Trans[i].ToKeyFrameT3().ToString(false) +
((i + 1 < Key.Trans.Length) ? "," : ""));
IO.Position = IO.Position - 1;
IO.Position--;
IO.Write('\n');
IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize);
IO.Write(Temp + "raw_data.value_type=" , Key.RawData.ValueType );
@@ -2220,7 +2226,7 @@ namespace KKdMainLib.A3DA
if (Key.EPTypePost == 0) Key.EPTypePost = null;
if (Key.EPTypePre == 0) Key.EPTypePre = null;
}
Key.Type = Key.Type & 0xFF;
Key.Type &= 0xFF;
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
KeyFrameT3<double, double> Temp;
for (int i = 0; i < Key.Length; i++)
@@ -2386,38 +2392,21 @@ namespace KKdMainLib.A3DA
if (Key.RawData.KeyType != null) Keys.Add("RawData", true);
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
MsgPack K;
for (int i = 0; i < Key.Trans.Length; i++)
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
{
K = new MsgPack(1);
K[0] = (MsgPack)KeyFrameT0.Frame;
Trans[i] = K;
}
Trans[i] = new MsgPack(null, new MsgPack[]
{ (MsgPack)KeyFrameT0.Frame });
else if (Key.Trans[i] is KeyFrameT1<double, double> KeyFrameT1)
{
K = new MsgPack(2);
K[0] = (MsgPack)KeyFrameT1.Frame;
K[1] = (MsgPack)KeyFrameT1.Value;
Trans[i] = K;
}
Trans[i] = new MsgPack(null, new MsgPack[]
{ (MsgPack)KeyFrameT1.Frame, (MsgPack)KeyFrameT1.Value });
else if (Key.Trans[i] is KeyFrameT2<double, double> KeyFrameT2)
{
K = new MsgPack(3);
K[0] = (MsgPack)KeyFrameT2.Frame;
K[1] = (MsgPack)KeyFrameT2.Value;
K[2] = (MsgPack)KeyFrameT2.Interpolation;
Trans[i] = K;
}
Trans[i] = new MsgPack(null, new MsgPack[]
{ (MsgPack)KeyFrameT2.Frame, (MsgPack)KeyFrameT2.Value,
(MsgPack)KeyFrameT2.Interpolation });
else if (Key.Trans[i] is KeyFrameT3<double, double> KeyFrameT3)
{
K = new MsgPack(4);
K[0] = (MsgPack)KeyFrameT3.Frame;
K[1] = (MsgPack)KeyFrameT3.Value;
K[2] = (MsgPack)KeyFrameT3.Interpolation1;
K[3] = (MsgPack)KeyFrameT3.Interpolation2;
Trans[i] = K;
}
Trans[i] = new MsgPack(null, new MsgPack[]
{ (MsgPack)KeyFrameT3.Frame, (MsgPack)KeyFrameT3.Value,
(MsgPack)KeyFrameT3.Interpolation1, (MsgPack)KeyFrameT3.Interpolation2 });
Keys.Add(Trans);
}
else if (Key.Value != 0) Keys.Add("Value", Key.Value);
@@ -2457,6 +2446,8 @@ namespace KKdMainLib.A3DA
public int StringLength;
public int StringOffset;
public Format Format;
public string[] Motion;
public string[] ObjectList;
public string[] ObjectHRCList;
@@ -2472,7 +2463,6 @@ namespace KKdMainLib.A3DA
public ObjectHRC[] ObjectHRC;
public CameraRoot[] CameraRoot;
public MObjectHRC[] MObjectHRC;
public Main.Format Format;
public PlayControl PlayControl;
public PostProcess PostProcess;
public MaterialList[] MaterialList;
-1
View File
@@ -3,7 +3,6 @@
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.F2nd;
using KKdMainLib.MessagePack;
namespace KKdMainLib.Aet
{
-1
View File
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
+2 -2
View File
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.A3DA;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
@@ -20,7 +20,7 @@ namespace KKdMainLib.DB
IO = File.OpenReader(file + ".bin");
IO.Format = Main.Format.F;
IO.Format = Format.F;
Signature = IO.ReadInt32();
if (Signature != 0x44334123) return;
Signature = IO.ReadInt32();
+2 -3
View File
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
@@ -85,8 +84,8 @@ namespace KKdMainLib.DB
List<string> SetName = new List<string>();
List<string> SetFileName = new List<string>();
List<int> Ids = new List<int>();
List<int> SetIds = new List<int>();
List<int> Ids = new List<int>();
List<int> SetIds = new List<int>();
List<int> NotAdd = new List<int>();
SpriteTexture temp;
+7 -7
View File
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.F2nd;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
@@ -21,7 +21,7 @@ namespace KKdMainLib
Header = new Header();
IO = File.OpenReader(filepath + ext);
Header.Format = Main.Format.F;
Header.Format = Format.F;
Header.SectionSignature = IO.ReadInt32();
if (Header.SectionSignature == 0x43505845)
Header = IO.ReadHeader(true);
@@ -31,7 +31,7 @@ namespace KKdMainLib
Offset = IO.Position - 0x4;
Dex = new EXP[IO.ReadInt32()];
int DEXOffset = IO.ReadInt32();
if (IO.ReadInt32() == 0x00) Header.Format = Main.Format.X;
if (IO.ReadInt32() == 0x00) Header.Format = Format.X;
int DEXNameOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
@@ -92,13 +92,13 @@ namespace KKdMainLib
return 1;
}
public void DEXWriter(string filepath, Main.Format Format)
public void DEXWriter(string filepath, Format Format)
{
Header = new Header();
IO = File.OpenWriter(filepath + (Format > Main.Format.F ? ".dex" : ".bin"), true);
IO = File.OpenWriter(filepath + (Format > Format.F ? ".dex" : ".bin"), true);
Header.Format = IO.Format = Format;
IO.Offset = Format > Main.Format.F ? 0x20 : 0;
IO.Offset = Format > Format.F ? 0x20 : 0;
IO.Write(0x64);
IO.Write(Dex.Length);
@@ -157,7 +157,7 @@ namespace KKdMainLib
IO.Position = Position0 - (Header.IsX ? 8 : 4);
IO.Write(Position1);
if (Format > Main.Format.F)
if (Format > Format.F)
{
Offset = IO.Length;
IO.Offset = 0;
-1
View File
@@ -2,7 +2,6 @@
using System.Net;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
+87 -112
View File
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.F2nd;
@@ -10,22 +9,20 @@ namespace KKdMainLib
public static Header ReadHeader(this Stream stream, bool Seek, bool ReadSectionSignature = true)
{
if (Seek)
if (stream.Position > 4) stream.LongPosition -= 4;
else stream.LongPosition = 0;
if (stream.LongPosition > 4) stream.LongPosition -= 4;
else stream.LongPosition = 0;
return stream.ReadHeader(ReadSectionSignature);
}
public static Header ReadHeader(this Stream stream, bool ReadSectionSignature = true)
{
Header Header = new Header
{ Format = Main.Format.F2LE, Signature = stream.ReadInt32(),
DataSize = stream.ReadInt32(),
Length = stream.ReadInt32() };
Header Header = new Header { Format = Format.F2LE, Signature = stream.ReadInt32(),
DataSize = stream.ReadInt32(), Length = stream.ReadInt32() };
if (stream.ReadUInt32() == 0x18000000)
{ Header.Format = Main.Format.F2BE; }
{ Header.Format = Format.F2BE; }
Header.ID = stream.ReadInt32();
Header.SectionSize = stream.ReadInt32();
Header.Count = stream.ReadInt32();
Header.SubID = stream.ReadInt32();
stream.ReadInt32();
if (Header.Length == 0x40)
{
@@ -44,15 +41,15 @@ namespace KKdMainLib
{
stream.Write(Header.Signature);
stream.Write(Header.DataSize);
stream.Write((Header.Format < Main.Format.X && Extended) ? 0x40 : 0x20);
stream.Write(Header.Format == Main.Format.F2BE ? 0x18000000 : 0x10000000);
stream.Write((Header.Format < Format.X && Extended) ? 0x40 : 0x20);
stream.Write(Header.Format == Format.F2BE ? 0x18000000 : 0x10000000);
stream.Write(Header.ID);
stream.Write(Header.SectionSize);
stream.Write(Header.SubID);
stream.Write(0x00);
stream.Write(0x00);
if (Header.Format < Main.Format.X && Extended)
if (Header.Format < Format.X && Extended)
{
stream.Write(Header.Format < Main.Format.MGF ? (int)((Header.SectionSignature ^
stream.Write(Header.Format < Format.MGF ? (int)((Header.SectionSignature ^
(Header.DataSize * (long)Header.Signature)) - Header.ID + Header.SectionSize) : 0);
stream.Write(0x00);
stream.Write(0x00L);
@@ -68,114 +65,92 @@ namespace KKdMainLib
public static class POFExtensions
{
public static POF AddPOF(this Header Header) =>
new POF { Offsets = new List<long>(), Offset = Header.DataSize + Header.Length };
public static void GetOffset(this Stream stream, ref POF POF)
{ if (stream.Format > Main.Format.F) POF.Offsets.Add(stream.Position + (stream.IsX ? stream.Offset : 0x00)); }
public static void ReadPOF(this Stream stream, ref POF POF)
public static void Write(this Stream stream, ref KKdList<long> Offsets, int ID, bool ShiftX)
{
if (stream.ReadString(3) == "POF")
{
POF.Type = byte.Parse(stream.ReadString(1));
int IsX = POF.Type + 2;
stream.Seek(-4, SeekOrigin.Current);
POF.Header = stream.ReadHeader();
stream.Seek(POF.Offset + POF.Header.Length, 0);
POF.Length = stream.ReadInt32();
while (POF.Length + POF.Offset + POF.Header.Length > stream.Position)
{
int a = stream.ReadByte();
if (a >> 6 == 0) break;
else if (a >> 6 == 1) a = a & 0x3F;
else if (a >> 6 == 2)
{
a = a & 0x3F;
a = (a << 8) | stream.ReadByte();
}
else if (a >> 6 == 3)
{
a = a & 0x3F;
a = (a << 8) | stream.ReadByte();
a = (a << 8) | stream.ReadByte();
a = (a << 8) | stream.ReadByte();
}
a <<= IsX;
POF.LastOffset += a;
}
}
}
public static void Write(this Stream stream, ref POF POF, int ID)
{
POF.Offsets.Sort();
long CurrentPOFOffset = 0;
long POFOffset = 0;
byte BitShift = (byte)(2 + POF.Type);
int Max1 = (0x00FF >> BitShift) << BitShift;
int Max2 = (0xFFFF >> BitShift) << BitShift;
POF.Length = 5 + ID;
for (int i = 0; i < POF.Offsets.Count; i++)
{
POFOffset = POF.Offsets[i] - CurrentPOFOffset;
CurrentPOFOffset = POF.Offsets[i];
if (POFOffset <= Max1) POF.Length += 1;
else if (POFOffset <= Max2) POF.Length += 2;
else POF.Length += 4;
POF.Offsets[i] = POFOffset;
}
long POFLengthAling = POF.Length.Align(16);
POF.Header = new Header { DataSize = (int)POFLengthAling, ID = ID, Format = Main.Format.F2LE,
Length = 0x20, SectionSize = (int)POFLengthAling, Signature = 0x30464F50 };
POF.Header.Signature += POF.Type << 24;
stream.Write(POF.Header);
stream.Write(POF.Length);
for (int i = 0; i < POF.Offsets.Count; i++)
{
POFOffset = POF.Offsets[i];
if (POFOffset <= Max1) stream.Write (( byte)((1 << 6) | (POFOffset >> BitShift)));
else if (POFOffset <= Max2) stream.WriteEndian((ushort)((2 << 14) | (POFOffset >> BitShift)), true);
else stream.WriteEndian(( uint)((3 << 30) | (POFOffset >> BitShift)), true);
}
stream.Write(0x00);
stream.Align(16, true);
byte[] data = POF.Write(Offsets, ShiftX);
Header Header = new Header { ID = ID, Format = Format.F2LE,
Length = 0x20, Signature = ShiftX ? 0x31464F50 : 0x30464F50 };
Header.DataSize = Header.SectionSize = data.Length;
stream.Write(Header);
stream.Write(data);
stream.WriteEOFC(ID);
}
}
public static class PointerExt
public static class MPExt
{
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static MsgPack ReadMP(this byte[] array, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSON IO = new JSON(File.OpenReader(array));
MsgPack = IO.Read(); IO.Close(); }
else
{ MP IO = new MP(File.OpenReader(array));
MsgPack = IO.Read(); IO.Close(); }
return MsgPack;
}
public static Pointer<string> ReadPointerString(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static MsgPack ReadMPAllAtOnce(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSON IO = new JSON(File.OpenReader(file + ".json", true));
MsgPack = IO.Read(); IO.Close(); }
else
{ MP IO = new MP(File.OpenReader(file + ".mp" , true));
MsgPack = IO.Read(); IO.Close(); }
return MsgPack;
}
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
public static MsgPack ReadMP(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSON IO = new JSON(File.OpenReader(file + ".json"));
MsgPack = IO.Read(); IO.Close(); }
else
{ MP IO = new MP(File.OpenReader(file + ".mp" ));
MsgPack = IO.Read(); IO.Close(); }
return MsgPack;
}
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).Write(file, JSON).Dispose();
else mp .Write(file, JSON); }
public static Pointer<T> ReadPointerEndian<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32Endian() };
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
{
if (JSON)
{ JSON IO = new JSON(File.OpenWriter(file + ".json", true));
IO.Write(mp, "\n", " ").Close(); }
else
{ MP IO = new MP(File.OpenWriter(file + ".mp" , true));
IO.Write(mp ).Close(); }
return mp;
}
public static Pointer<string> ReadPointerStringEndian(this Stream IO)
{ Pointer<string> val = IO.ReadPointerEndian<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).WriteAfterAll(file, JSON).Dispose();
else mp .WriteAfterAll(file, JSON); }
public static CountPointer<T> ReadCountPointerEndian<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32Endian(), Offset = IO.ReadInt32Endian() };
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
{
byte[] data = null;
if (JSON)
{ JSON IO = new JSON(File.OpenWriter());
IO.Write(mp, true); data = IO.ToArray(true); }
else
{ MP IO = new MP(File.OpenWriter());
IO.Write(mp ); data = IO.ToArray(true); }
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
return mp;
}
public static Pointer<T> ReadPointerX<T>(this Stream IO) =>
new Pointer<T> { Offset = (int)IO.ReadIntX() };
public static void ToJSON (this string file) =>
file.ReadMP( ).Write(file, true).Dispose();
public static Pointer<string> ReadPointerStringX(this Stream IO)
{ Pointer<string> val = IO.ReadPointerX<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static CountPointer<T> ReadCountPointerX<T>(this Stream IO) =>
new CountPointer<T> { Count = (int)IO.ReadIntX(), Offset = (int)IO.ReadIntX() };
public static void ToMsgPack(this string file) =>
file.ReadMP(true).Write(file ).Dispose();
}
}
+104
View File
@@ -0,0 +1,104 @@
using KKdBaseLib;
namespace KKdMainLib.F2nd
{
public struct ENRS
{
public int Offset;
public int Count;
public int Size;
public int Repeat;
public SubENRS[] Sub;
public struct SubENRS
{
public int Skip;
public int Reverse;
public Type Type;
public override string ToString() => "Skip: " + Skip + "; Reverse: " + Reverse + "; Type: " + Type;
}
public static unsafe ENRS[] Read(byte[] data)
{
byte* ptr = data.GetPtr();
int i, i0;
int ENRSCount = ((int*)ptr)[1];
ENRS[] ENRSArr = new ENRS[ENRSCount];
ptr = ptr + 0x10;
ENRS ENR = new ENRS();
for (i = 0; i < ENRSCount; i++)
{
ENR.Offset = ReadENRSValue(ref ptr) + ENR.Offset;
ENR.Count = ReadENRSValue(ref ptr);
ENR.Size = ReadENRSValue(ref ptr);
ENR.Repeat = ReadENRSValue(ref ptr);
if (ENR.Repeat > 0)
{
ENR.Sub = new SubENRS[ENR.Count];
for (i0 = 0; i0 < ENR.Count; i0++)
{
ENR.Sub[i0].Skip = ReadENRSValue(ref ptr, out ENR.Sub[i0].Type);
ENR.Sub[i0].Reverse = ReadENRSValue(ref ptr);
if (ENR.Sub[i0].Type == Type.Invalid) return null;
if (i0 > 0) ENR.Sub[i0].Skip += ENR.Sub[i0 - 1].Skip + ENR.Sub[i0 - 1].Reverse *
((ENR.Sub[i0].Type == Type.WORD) ? 2 : (ENR.Sub[i0].Type == Type.DWORD) ? 4 : 8);
}
}
else ENR.Sub = null;
ENRSArr[i] = ENR;
}
return ENRSArr;
}
private static unsafe int ReadENRSValue(ref byte* ptr, out Type Rev)
{
int V = *ptr & 0xF;
Rev = (Type)(*ptr & 0x30);
Value Val = (Value)(*ptr & 0xC0);
ptr++;
if (Val == Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (Val == Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (Val == Value.Invalid) V = 0;
return V;
}
private static unsafe int ReadENRSValue(ref byte* ptr)
{
int V = *ptr & 0x3F;
Value Val = (Value)(*ptr & 0xC0);
ptr++;
if (Val == Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (Val == Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (Val == Value.Invalid) V = 0;
return V;
}
public enum Type : byte
{
WORD = 0b00000000,
DWORD = 0b00010000,
QWORD = 0b00100000,
Invalid = 0b00110000,
}
public enum Value : byte
{
Int8 = 0b00000000,
Int16 = 0b01000000,
Int32 = 0b10000000,
Invalid = 0b11000000,
}
public override string ToString() =>
"Offset: " + Offset + "; Count: " + Count + "; " + "Size: " + Size + "; Repeat: " + Repeat;
}
}
+4 -4
View File
@@ -7,15 +7,15 @@ namespace KKdMainLib.F2nd
public int Signature;
public int DataSize;
public int Length;
public Main.Format Format;
public Format Format;
public int ID;
public int SectionSize;
public int Count;
public int SubID;
public int InnerSignature;
public int SectionSignature;
public bool IsBE => Format == Main.Format.F2BE;
public bool IsX => Format == Main.Format.X || Format == Main.Format.XHD;
public bool IsBE => Format == Format.F2BE;
public bool IsX => Format == Format.X || Format == Format.XHD;
public override string ToString() => Signature.ToString(false);
}
+76 -7
View File
@@ -1,14 +1,83 @@
using System.Collections.Generic;
using KKdBaseLib;
namespace KKdMainLib.F2nd
{
public struct POF
{
public byte Type;
public int Length;
public int Offset;
public int LastOffset;
public List<long> Offsets;
public Header Header;
public static unsafe KKdList<long> Read(byte[] data, bool ShiftX)
{
Value Val = 0;
KKdList<long> Offsets = KKdList<long>.New;
byte* ptr = data.GetPtr();
int i = 0, Offset = 0, V = 0;
byte BitShift = (byte)(ShiftX ? 3 : 2);
int Length = *(int*)ptr - 4; ptr += 4;
while (Length > i)
{
V = *ptr & 0x3F;
Val = (Value)(*ptr & 0xC0);
ptr++; i++;
if (Val == Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; i += 3; }
else if (Val == Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; i += 3; }
else if (Val == Value.Invalid) break;
Offset += V;
Offsets.Add(Offset << BitShift);
}
return Offsets;
}
public static unsafe byte[] Write(KKdList<long> Offsets, bool ShiftX)
{
Offsets.Sort();
int Length = 5;
long Offset = 0;
byte BitShift = (byte)(ShiftX ? 3 : 2);
int Max1 = 0x00FF >> BitShift;
int Max2 = 0xFFFF >> BitShift;
for (int i = 0; i < Offsets.Count; i++)
{
Offset = Offsets[i];
if (i > 0) { Offset -= Offsets[i - 1]; if (Offset == 0) continue; }
Offset >>= BitShift;
if (Offset <= Max1) Length += 1;
else if (Offset <= Max2) Length += 2;
else Length += 4;
}
byte[] data = new byte[Length.Align(0x10)];
byte* ptr = data.GetPtr();
Value Val = 0;
*(int*)ptr = Length; ptr += 4;
for (int i = 0; i < Offsets.Count; i++)
{
Offset = Offsets[i];
if (i > 0) { Offset -= Offsets[i - 1]; if (Offset == 0) continue; }
Offset >>= BitShift;
Val = Offset > Max2 ? Value.Int32 : Offset > Max1 ? Value.Int16 : Value.Int8;
if (Offset <= Max1) *ptr = (byte)((byte)Val | Offset );
else if (Offset <= Max2) { *ptr = (byte)((byte)Val | (Offset >> 8)); ptr++;
*ptr = (byte) Offset ; }
else { *ptr = (byte)((byte)Val | (Offset >> 24)); ptr++;
*ptr = (byte) (Offset >> 16) ; ptr++;
*ptr = (byte) (Offset >> 8) ; ptr++;
*ptr = (byte) Offset ; }
ptr++;
}
return data;
}
public enum Value : byte
{
Invalid = 0b00000000,
Int8 = 0b01000000,
Int16 = 0b10000000,
Int32 = 0b11000000,
}
}
}
+14 -32
View File
@@ -8,15 +8,15 @@ namespace KKdMainLib.F2nd
public Header Header;
public byte[] Data;
public Struct[] SubStructs;
public bool HasEOFC;
public Mini POF;
public Mini ENRS;
public bool EOFC;
public ENRS[] ENRS;
public KKdList<long> POF;
public long DataOffset;
public override string ToString() => Header.ToString() + (SubStructs != null ? "; SubStructs: " +
SubStructs.Length : "") + (POF != null ? "; Has " + POF.Header.ToString() : "") +
(ENRS != null ? "; Has ENRS" : "") + (HasEOFC ? "; Has EOFC" : "");
public override string ToString() => Header.ToString() + (SubStructs != null ?
"; SubStructs: " + SubStructs.Length : "")+ (ENRS != null ? "; Has ENRS" : "") +
(POF.NotNull ? "; Has POF" : "") + (EOFC ? "; Has EOFC" : "");
public static Struct ReadStruct(byte[] Data)
{
@@ -40,48 +40,30 @@ namespace KKdMainLib.F2nd
Header = stream.ReadHeader(false);
Position += Header.Length + Header.DataSize;
if (Header.ID == ID && Header.Signature == 0x43464F45)
{ Struct.HasEOFC = true; break; }
else if (Header.ID == 0 && Header.Signature == 0x53524E45)
{ Struct.EOFC = true; break; }
else if (Header.ID == 0 && (Header.Signature == 0x30464F50 ||
Header.Signature == 0x31464F50 || Header.Signature == 0x53524E45))
SubStructs.Add(new Struct { Header = Header, DataOffset =
stream.Position, Data = stream.ReadBytes(Header.SectionSize) });
else if (Header.ID <= ID)
{ stream.LongPosition -= Header.Length; break; }
else SubStructs.Add(ReadStruct(ref stream, Header));
//(Header.Signature == 0x30464F50 || Header.Signature ==
// 0x31464F50 || Header.Signature == 0x53524E45)
}
for (int i = 0; i < SubStructs.Capacity; i++)
{
string Sig = SubStructs[i].Header.ToString();
if (Sig == "ENRS" || Sig == "POF0" || Sig == "POF1")
if (Sig == "ENRS" || Sig == "EOFC" || Sig == "POF0" || Sig == "POF1")
{
if (Sig == "ENRS") Struct.ENRS = (Mini)SubStructs[i];
else Struct.POF = (Mini)SubStructs[i];
if (Sig == "EOFC") Struct.EOFC = true;
else if (Sig == "ENRS") Struct.ENRS = F2nd.ENRS.Read(SubStructs[i].Data);
else Struct.POF = F2nd.POF .Read(SubStructs[i].Data, Sig == "POF1");
SubStructs.RemoveAt(i); SubStructs.Capacity--; i--;
}
}
if (SubStructs.Capacity > 0)
{
Struct.SubStructs = SubStructs.ToArray();
}
if (SubStructs.Capacity > 0) Struct.SubStructs = SubStructs.ToArray();
return Struct;
}
public class Mini
{
public Header Header;
public byte[] Data;
public bool HasEOFC;
public static explicit operator Mini(Struct Struct) =>
new Mini() { Header = Struct.Header, Data = Struct.Data, HasEOFC = Struct.HasEOFC };
public static explicit operator Struct( Mini Struct) =>
new Struct() { Header = Struct.Header, Data = Struct.Data, HasEOFC = Struct.HasEOFC };
public override string ToString() => Header.ToString() + (HasEOFC ? "; Has EOFC" : "");
}
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using MSIO = System.IO;
using MSIO = System.IO;
namespace KKdMainLib.IO
{
@@ -2,7 +2,7 @@
namespace KKdMainLib.IO
{
public static class IOExtensions
public static class Extensions
{
public static string NullTerminatedASCII(this Stream stream, byte End = 0) =>
stream.NullTerminated(End).ToASCII();
@@ -43,6 +43,13 @@ namespace KKdMainLib.IO
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
public static void WriteX(this Stream stream, long val, ref KKdList<long> POF)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); POF.Add(stream.Position); }
public static void WriteX(this Stream stream, long val, ref KKdList<long> POF, bool IsBE)
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); POF.Add(stream.Position); }
public static void WriteX(this Stream stream, long val)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); }
@@ -50,26 +57,26 @@ namespace KKdMainLib.IO
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); }
public static byte[] ReadAtOffset(this Stream stream, long Offset = 0, long Length = 0)
public static byte[] ReadAtOffset(this Stream stream, long Offset = -1, long Length = -1)
{
byte[] arr = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) arr = stream.NullTerminated();
else arr = stream.ReadBytes(Length);
if (Length == -1) arr = stream.NullTerminated();
else arr = stream.ReadBytes(Length);
stream.LongPosition = Position;
return arr;
}
public static string ReadStringAtOffset(this Stream stream, long Offset = 0, long Length = 0)
public static string ReadStringAtOffset(this Stream stream, long Offset = -1, long Length = -1)
{
string s = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) s = stream.NullTerminatedUTF8();
else s = stream.ReadStringUTF8(Length);
if (Length == -1) s = stream.NullTerminatedUTF8();
else s = stream.ReadStringUTF8(Length);
stream.LongPosition = Position;
return s;
}
@@ -83,5 +90,35 @@ namespace KKdMainLib.IO
public static void WriteShiftJIS(this Stream IO, string String) =>
IO.Write(Text.ShiftJIS.GetBytes(String));
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static Pointer<string> ReadPointerString(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
public static Pointer<T> ReadPointerEndian<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32Endian() };
public static Pointer<string> ReadPointerStringEndian(this Stream IO)
{ Pointer<string> val = IO.ReadPointerEndian<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static CountPointer<T> ReadCountPointerEndian<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32Endian(), Offset = IO.ReadInt32Endian() };
public static Pointer<T> ReadPointerX<T>(this Stream IO) =>
new Pointer<T> { Offset = (int)IO.ReadIntX() };
public static Pointer<string> ReadPointerStringX(this Stream IO)
{ Pointer<string> val = IO.ReadPointerX<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static CountPointer<T> ReadCountPointerX<T>(this Stream IO) =>
new CountPointer<T> { Count = (int)IO.ReadIntX(), Offset = (int)IO.ReadIntX() };
}
}
@@ -1,16 +1,15 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using KKdBaseLib;
using KKdMainLib.IO;
using BaseExtensions = KKdBaseLib.Extensions;
namespace KKdMainLib.MessagePack
namespace KKdMainLib.IO
{
public class JSONIO
public struct JSON
{
public Stream _IO;
public JSON(Stream IO) => _IO = IO;
public JSONIO( ) => _IO = File.OpenWriter();
public JSONIO(Stream IO) => _IO = IO;
private Stream _IO;
public void Close() => _IO.Close();
@@ -66,7 +65,8 @@ namespace KKdMainLib.MessagePack
}
}
else if (c == '"') break;
else if (char.IsControl(c)) return null;
else if (char.IsControl(c))
return null;
else s += c;
}
@@ -83,7 +83,8 @@ namespace KKdMainLib.MessagePack
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
if (_IO.SkipWhitespace().PeekCharUTF8() == '}')
{ _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
@@ -110,7 +111,8 @@ namespace KKdMainLib.MessagePack
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
if (_IO.SkipWhitespace().PeekCharUTF8() == ']')
{ _IO.ReadCharUTF8(); return null; }
char c;
while (true)
@@ -171,13 +173,13 @@ namespace KKdMainLib.MessagePack
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
public JSONIO Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
public JSON Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
{ Write(MsgPack, End, TabChar, "", true); return this; }
public JSONIO Write(MsgPack MsgPack, bool Style = false)
public JSON Write(MsgPack MsgPack, bool Style = false)
{ Write(MsgPack, "\n", " ", "", Style); return this; }
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false)
private JSON Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false)
{
string OldTab = Tab;
Tab += TabChar;
@@ -239,21 +241,20 @@ namespace KKdMainLib.MessagePack
switch (obj)
{
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
case bool val: Write(val); break;
case string val: Write(val); break;
case sbyte val: _IO.Write(Extensions.ToString(val)); break;
case byte val: _IO.Write(Extensions.ToString(val)); break;
case short val: _IO.Write(Extensions.ToString(val)); break;
case ushort val: _IO.Write(Extensions.ToString(val)); break;
case int val: _IO.Write(Extensions.ToString(val)); break;
case uint val: _IO.Write(Extensions.ToString(val)); break;
case long val: _IO.Write(Extensions.ToString(val)); break;
case ulong val: _IO.Write(Extensions.ToString(val)); break;
case float val: _IO.Write(Extensions.ToString(val)); break;
case double val: _IO.Write(Extensions.ToString(val)); break;
case bool Boolean:
case sbyte Int8 :
case byte UInt8 :
case short Int16:
case ushort UInt16:
case int Int32:
case uint UInt32:
case long Int64:
case ulong UInt64:
case float Float32:
case double Float64: _IO.Write(BaseExtensions.ToString(obj)); break;
}
}
private void Write( bool val) => _IO.Write(val ? "true" : "false");
private void Write(string val) => _IO.Write("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
@@ -1,15 +1,13 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
namespace KKdMainLib.MessagePack
namespace KKdMainLib.IO
{
public class IO
public struct MP
{
public Stream _IO;
public MP(Stream IO) => _IO = IO;
public IO( ) => _IO = File.OpenWriter();
public IO(Stream IO) => _IO = IO;
private Stream _IO;
public void Close() => _IO.Close();
@@ -18,51 +16,38 @@ namespace KKdMainLib.MessagePack
public MsgPack Read(bool Array = false)
{
MsgPack MsgPack = MsgPack.New;
if (!Array) MsgPack.Name = ReadString((Types)_IO.ReadByte());
byte Unk = _IO.ReadByte();
Types Type = (Types)Unk;
if (!Array)
{
MsgPack.Name = ReadString(Type);
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); Type = (Types)Unk; }
}
bool FixArr = Type >= Types.FixArr && Type <= Types.FixArrMax;
bool FixMap = Type >= Types.FixMap && Type <= Types.FixMapMax;
bool FixStr = Type >= Types.FixStr && Type <= Types.FixStrMax;
bool PosInt = Type >= Types.PosInt && Type <= Types.PosIntMax;
bool NegInt = Type >= Types.NegInt && Type <= Types.NegIntMax;
if (FixArr || FixMap || FixStr || PosInt || NegInt)
if (Type >= Types.FixMap && Type <= Types.FixMapMax)
{
if (FixMap)
{
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
}
else if (FixArr)
{
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
}
else if (FixStr) MsgPack.Object = ReadString( Type);
else if (PosInt) MsgPack.Object = Unk;
else if (NegInt) MsgPack.Object = (sbyte)Unk;
return MsgPack;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
}
while (true)
else if (Type >= Types.FixArr && Type <= Types.FixArrMax)
{
if (ReadNil (ref MsgPack, ref Type)) break;
if (ReadArr (ref MsgPack, ref Type)) break;
if (ReadMap (ref MsgPack, ref Type)) break;
if (ReadExt (ref MsgPack, ref Type)) break;
if (ReadString (ref MsgPack, ref Type)) break;
if (ReadBoolean(ref MsgPack, ref Type)) break;
if (ReadBytes (ref MsgPack, ref Type)) break;
if (ReadInt (ref MsgPack, ref Type)) break;
if (ReadUInt (ref MsgPack, ref Type)) break;
if (ReadFloat (ref MsgPack, ref Type)) break;
break;
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
}
else if (Type >= Types.FixStr && Type <= Types.FixStrMax) MsgPack.Object = ReadString( Type);
else if (Type >= Types.PosInt && Type <= Types.PosIntMax) MsgPack.Object = Unk;
else if (Type >= Types.NegInt && Type <= Types.NegIntMax) MsgPack.Object = (sbyte)Unk;
else
while (true)
{
if (ReadNil (ref MsgPack, ref Type)) break;
if (ReadArr (ref MsgPack, ref Type)) break;
if (ReadMap (ref MsgPack, ref Type)) break;
if (ReadExt (ref MsgPack, ref Type)) break;
if (ReadString (ref MsgPack, ref Type)) break;
if (ReadBoolean(ref MsgPack, ref Type)) break;
if (ReadBytes (ref MsgPack, ref Type)) break;
if (ReadInt (ref MsgPack, ref Type)) break;
if (ReadUInt (ref MsgPack, ref Type)) break;
if (ReadFloat (ref MsgPack, ref Type)) break;
break;
}
return MsgPack;
}
@@ -182,7 +167,7 @@ namespace KKdMainLib.MessagePack
return true;
}
public IO Write(MsgPack MsgPack, bool IsArray = false)
public MP Write(MsgPack MsgPack, bool IsArray = false)
{
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
Write(MsgPack.Object);
+26 -24
View File
@@ -7,18 +7,16 @@ namespace KKdMainLib.IO
public unsafe class Stream : IDisposable
{
private MSIO.Stream stream;
private int I, i, i0, TempBitRead, TempBitWrite;
private ushort ValRead;
private byte BitRead, BitWrite, ValWrite;
private int I, i, i0, BitRead, BitWrite, TempBitRead, TempBitWrite, ValRead, ValWrite;
private byte[] buf;
private Main.Format _format = Main.Format.NULL;
private Format _format = Format.NULL;
public Main.Format Format
public Format Format
{ get => _format;
set { _format = value;
IsBE = _format == Main.Format.F2BE;
IsX = _format == Main.Format.X || _format == Main.Format.XHD; } }
IsBE = _format == Format.F2BE;
IsX = _format == Format.X || _format == Format.XHD; } }
public bool IsBE = false;
public bool IsX = false;
@@ -27,9 +25,12 @@ namespace KKdMainLib.IO
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
public long LongOffset;
public int Length { get => ( int)stream.Length - Offset; set => stream.SetLength(value + Offset); }
public uint UIntLength { get => (uint)stream.Length - UIntOffset; set => stream.SetLength(value + UIntOffset); }
public long LongLength { get => stream.Length - LongOffset; set => stream.SetLength(value + LongOffset); }
public int Length { get => ( int)stream.Length - Offset;
set => stream.SetLength(value + Offset); }
public uint UIntLength { get => (uint)stream.Length - UIntOffset;
set => stream.SetLength(value + UIntOffset); }
public long LongLength { get => stream.Length - LongOffset;
set => stream.SetLength(value + LongOffset); }
public int Position
{ get => ( int)stream.Position - Offset; set => stream.Position = value + Offset; }
@@ -52,7 +53,7 @@ namespace KKdMainLib.IO
BitRead = 8;
ValRead = ValRead = BitWrite = 0;
stream = output;
Format = Main.Format.NULL;
Format = Format.NULL;
buf = new byte[128];
IsBE = isBE;
}
@@ -322,18 +323,18 @@ namespace KKdMainLib.IO
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
public byte[] ReadBytes(long Length, int Offset = 0)
{ byte[] Buf = new byte[Length]; if (Offset > 0) stream.Position = Offset;
public byte[] ReadBytes(long Length, int Offset = -1)
{ byte[] Buf = new byte[Length]; if (Offset > -1) stream.Position = Offset;
stream.Read(Buf, 0, (int)Length); return Buf; }
public void ReadBytes(long Length, byte[] Buf, long Offset = 0)
{ if (Offset > 0) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
public void ReadBytes(long Length, byte[] Buf, long Offset = -1)
{ if (Offset > -1) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
public byte[] ReadBytes(long? Length, int Offset = 0)
public byte[] ReadBytes(long? Length, int Offset = -1)
{ if (Length == null) return new byte[0]; else return ReadBytes((long)Length, Offset); }
public void ReadBytes(long Length, byte Bits, byte[] Buf, long Offset = 0)
{ if (Offset > 0) stream.Seek(Offset, 0);
public void ReadBytes(long Length, byte Bits, byte[] Buf, long Offset = -1)
{ if (Offset > -1) stream.Seek(Offset, 0);
if (Bits > 0 && Bits < 8) for (i0 = 0; i0 < Length; i0++) Buf[i0] = ReadBits(Bits); }
public byte ReadBits(byte Bits)
@@ -351,8 +352,9 @@ namespace KKdMainLib.IO
public byte ReadHalfByte() => ReadBits(4);
public void Write(byte val, byte Bits)
public void Write(int val, byte Bits)
{
val &= (1 << Bits) - 1;
BitWrite += Bits;
TempBitWrite = 8 - BitWrite;
if (TempBitWrite < 0)
@@ -362,11 +364,12 @@ namespace KKdMainLib.IO
stream.WriteByte((byte)(ValWrite | (val >> BitWrite)));
ValWrite = 0;
}
ValWrite |= (byte)(val << TempBitWrite);
ValWrite |= val << TempBitWrite;
ValWrite &= 0xFF;
}
public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; }
public void CheckWrited() { if (BitWrite > 0) { Write(ValWrite); ValWrite = BitWrite = 0; } }
public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; }
public void CheckWrited() { if (BitWrite > 0) { Write(ValWrite); ValWrite = 0; BitWrite = 0; } }
public byte[] ToArray(bool Close)
{ byte[] Data = ToArray(); if (Close) this.Close(); return Data; }
@@ -374,8 +377,7 @@ namespace KKdMainLib.IO
public byte[] ToArray()
{
long Position = stream.Position;
stream.Position = 0;
byte[] Data = ReadBytes(stream.Length);
byte[] Data = ReadBytes(stream.Length, 0);
stream.Position = Position;
return Data;
}
+4 -5
View File
@@ -42,18 +42,17 @@
<Compile Include="DB\Aet.cs" />
<Compile Include="DB\Auth.cs" />
<Compile Include="DB\Spr.cs" />
<Compile Include="F2nd\ENRS.cs" />
<Compile Include="F2nd\Header.cs" />
<Compile Include="F2nd\POF.cs" />
<Compile Include="F2nd\Struct.cs" />
<Compile Include="IO\Directory.cs" />
<Compile Include="IO\Extensions.cs" />
<Compile Include="IO\File.cs" />
<Compile Include="IO\IOExtensions.cs" />
<Compile Include="IO\JSON.cs" />
<Compile Include="IO\MP.cs" />
<Compile Include="IO\Path.cs" />
<Compile Include="IO\Stream.cs" />
<Compile Include="MessagePack\JSONIO.cs" />
<Compile Include="MessagePack\MPExt.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\IO.cs" />
<Compile Include="A3DA.cs" />
<Compile Include="Aet.cs" />
<Compile Include="DataBank.cs" />
+17 -22
View File
@@ -111,14 +111,18 @@ namespace KKdMainLib
if (ofd.ShowDialog() == DialogResult.OK)
FileNames = ofd.FileNames;
ofd.Dispose();
}
else if (code == 2)
{
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
ValidateNames = false, CheckFileExists = false, Filter = " | ", CheckPathExists = true,
Title = "Choose any file in folder:", FileName = "Folder Selection." };
string Return = "";
if (ofd.ShowDialog() == DialogResult.OK)
return Path.GetDirectoryName(ofd.FileName);
Return = Path.GetDirectoryName(ofd.FileName);
ofd.Dispose();
return Return;
}
return "";
}
@@ -141,6 +145,7 @@ namespace KKdMainLib
InitialDirectory = sfd.InitialDirectory.ToString();
FileNames = sfd.FileNames;
}
sfd.Dispose();
}
public static string NullTerminated(this string Source, ref int i, byte End)
@@ -164,8 +169,10 @@ namespace KKdMainLib
public static bool StartsWith(this Dictionary<string, object> Dict, string[] args)
{
Dictionary<string, object> bufDict = new Dictionary<string, object>();
if (Dict == null)
Dict = new Dictionary<string, object>();
if (Dict == null) return false;
else if (args.Length < 1) return false;
args[0] = args[0].ToLower();
if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
@@ -231,10 +238,11 @@ namespace KKdMainLib
out string value, string[] args)
{
value = "";
if (Dict == null) return false;
if (Dict == null) return false;
else if (args.Length < 1) return false;
if (!Dict.ContainsKey(args[0])) return false;
args[0] = args[0].ToLower();
if (!Dict.ContainsKey(args[0])) return false;
else if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
@@ -260,7 +268,10 @@ namespace KKdMainLib
string[] args, string value)
{
Dictionary<string, object> bufDict = new Dictionary<string, object>();
if (Dict == null) Dict = new Dictionary<string, object>();
if (Dict == null) Dict = new Dictionary<string, object>();
else if (args.Length < 1) return;
args[0] = args[0].ToLower();
if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
@@ -295,21 +306,5 @@ namespace KKdMainLib
for (i = 0; i < Length; i++) B[i] = int.Parse(A[i]);
return B;
}
public enum Format : byte
{
NULL = 0,
DT = 1,
PDA = 2,
DT2 = 3,
DTe = 4,
F = 5,
FT = 6,
F2LE = 7,
F2BE = 8,
MGF = 9,
X = 10,
XHD = 11,
}
}
}
-70
View File
@@ -1,70 +0,0 @@
using KKdMainLib.IO;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib.MessagePack
{
public static class MPExt
{
public static MsgPack ReadMPAllAtOnce(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json", true));
MsgPack = IO.Read(); IO.Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" , true));
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static MsgPack ReadMP(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
MsgPack = IO.Read(); IO.Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).Write(file, JSON).Dispose();
else mp .Write(file, JSON); }
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
{
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
IO.Write(mp, "\n", " ").Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
IO.Write(mp ).Close(); IO = null; }
return mp;
}
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).WriteAfterAll(file, JSON).Dispose();
else mp .WriteAfterAll(file, JSON); }
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
{
byte[] data = null;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter());
IO.Write(mp, true); data = IO.ToArray(true); }
else
{ MPIO IO = new MPIO(File.OpenWriter());
IO.Write(mp ); data = IO.ToArray(true); }
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
return mp;
}
public static void ToJSON (this string file) =>
file.ReadMP( ).Write(file, true).Dispose();
public static void ToMsgPack(this string file) =>
file.ReadMP(true).Write(file ).Dispose();
}
}
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.7.0")]
[assembly: AssemblyFileVersion("0.4.7.0")]
[assembly: AssemblyVersion("0.4.7.1")]
[assembly: AssemblyFileVersion("0.4.7.1")]
+32 -29
View File
@@ -1,7 +1,6 @@
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.F2nd;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
@@ -12,7 +11,7 @@ namespace KKdMainLib
private long Offset;
private long OffsetX;
private POF POF;
private KKdList<long> POF;
private Header Header;
private Stream IO;
@@ -23,13 +22,12 @@ namespace KKdMainLib
IO = File.OpenReader(filepath + ext);
Header = new Header();
IO.Format = Main.Format.F;
IO.Format = Format.F;
Header.Signature = IO.ReadInt32();
if (Header.Signature == 0x41525453)
{
Header = IO.ReadHeader(true);
POF = Header.AddPOF();
IO.Position = Header.Length;
Header = IO.ReadHeader(true, false);
POF = KKdList<long>.New;
long Count = IO.ReadInt32Endian();
Offset = IO.ReadInt32Endian();
@@ -40,7 +38,7 @@ namespace KKdMainLib
OffsetX = IO.ReadInt64();
Count = IO.ReadInt64();
IO.Offset = Header.Length;
IO.Format = Main.Format.X;
IO.Format = Format.X;
IO.LongOffset += Offset;
IO.Position = 0;
}
@@ -48,13 +46,16 @@ namespace KKdMainLib
STRs = new String[Count];
for (int i = 0; i < Count; i++)
STRs[i].ID = IO.ReadInt32Endian();
{
STRs[i].Str.Offset = IO.ReadInt32Endian();
STRs[i].ID = IO.ReadInt32Endian();
}
if (IO.IsX)
{
IO.Offset = Header.Length;
IO.LongOffset = Header.Length + OffsetX;
for (int i = 0; i < Count; i++)
STRs[i].Str.Value = IO.ReadStringAtOffset(STRs[i].Str.Offset + OffsetX);
STRs[i].Str.Value = IO.ReadStringAtOffset(STRs[i].Str.Offset);
}
else
{
@@ -63,9 +64,6 @@ namespace KKdMainLib
STRs[i].Str.Value = STRs[i].Str.Offset > 0 ?
IO.ReadStringAtOffset(STRs[i].Str.Offset) : null;
}
IO.Position = POF.Offset;
IO.ReadPOF(ref POF);
}
else
{
@@ -92,20 +90,19 @@ namespace KKdMainLib
public void STRWriter(string filepath)
{
if (STRs == null || STRs.Length == 0 || Header.Format > Main.Format.F2BE) return;
if (STRs == null || STRs.Length == 0 || Header.Format > Format.F2BE) return;
uint Offset = 0;
uint CurrentOffset = 0;
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.FT ? ".str" : ".bin"), true);
IO = File.OpenWriter(filepath + (Header.Format > Format.FT ? ".str" : ".bin"), true);
IO.Format = Header.Format;
POF = new POF();
IO.IsBE = IO.Format == Main.Format.F2BE;
POF = KKdList<long>.New;
IO.IsBE = IO.Format == Format.F2BE;
long Count = STRs.LongLength;
if (IO.Format > Main.Format.FT)
if (IO.Format > Format.FT)
{
IO.Position = 0x40;
IO.WriteX(Count);
IO.GetOffset(ref POF);
IO.WriteX(Count, ref POF);
IO.WriteX(0x80);
IO.Position = 0x80;
for (int i = 0; i < Count; i++) IO.Write(0x00L);
@@ -120,6 +117,10 @@ namespace KKdMainLib
KKdList<string> UsedSTR = KKdList<string>.New;
KKdList<int> UsedSTRPos = KKdList<int>.New;
int[] STRPos = new int[Count];
UsedSTRPos.Add(IO.Position);
UsedSTR.Add("");
IO.WriteByte(0);
for (int i = 0; i < Count; i++)
{
if (!UsedSTR.Contains(STRs[i].Str.Value))
@@ -127,35 +128,35 @@ namespace KKdMainLib
STRPos[i] = IO.Position;
UsedSTRPos.Add(STRPos[i]);
UsedSTR.Add(STRs[i].Str.Value);
IO.Write(STRs[i].Str.Value + "\0");
IO.Write(STRs[i].Str.Value);
IO.WriteByte(0);
}
else
for (int i2 = 0; i2 < Count; i2++)
if (UsedSTR[i2] == STRs[i].Str.Value)
{ STRPos[i] = UsedSTRPos[i2]; break; }
if (UsedSTR[i2] == STRs[i].Str.Value) { STRPos[i] = UsedSTRPos[i2]; break; }
}
if (IO.Format > Main.Format.FT)
if (IO.Format > Format.FT)
{
IO.Align(0x10);
Offset = IO.UIntPosition;
IO.Position = 0x80;
for (int i = 0; i < Count; i++)
{
IO.GetOffset(ref POF);
POF.Add(IO.Position);
IO.WriteEndian(STRPos[i]);
IO.WriteEndian(STRs[i].ID);
}
IO.UIntPosition = Offset;
IO.Write(ref POF, 1);
IO.Write(ref POF, 0, false);
CurrentOffset = IO.UIntPosition;
IO.WriteEOFC(0);
Header.DataSize = (int)(CurrentOffset - 0x40);
Header.Signature = 0x41525453;
Header.SectionSize = (int)(Offset - 0x40);
IO.Position = 0;
IO.Write(Header);
IO.Write(Header, true);
}
else
{
@@ -179,6 +180,7 @@ namespace KKdMainLib
{
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
STRs[i].Str.Value = Strings[i].ReadString("Str");
if (STRs[i].Str.Value == null) STRs[i].Str.Value = "";
}
MsgPack = MsgPack.New;
@@ -192,8 +194,9 @@ namespace KKdMainLib
for (int i = 0; i < STRs.Length; i++)
{
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
if (STRs[i].Str.Value != null || STRs[i].Str.Value != "")
Strings[i] = Strings[i].Add("Str", STRs[i].Str.Value);
if (STRs[i].Str.Value != null)
if (STRs[i].Str.Value != "")
Strings[i] = Strings[i].Add("Str", STRs[i].Str.Value);
}
STR_.Add(Strings);
+2 -2
View File
@@ -112,9 +112,9 @@ namespace PD_Tool
{
KKdMain.Choose(1, JSON ? "mp" : "json", out string[] FileNames);
if (JSON) foreach (string file in FileNames)
KKdMainLib.MessagePack.MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
KKdMainLib.MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
else foreach (string file in FileNames)
KKdMainLib.MessagePack.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
KKdMainLib.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
}
}
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.7.0")]
[assembly: AssemblyFileVersion("0.4.7.0")]
[assembly: AssemblyVersion("0.4.7.1")]
[assembly: AssemblyFileVersion("0.4.7.1")]
+2 -13
View File
@@ -8,12 +8,7 @@ namespace PD_Tool
public static void Decrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() != 0x454C494641564944)
{
reader.Close();
Encrypt(file);
return;
}
if (reader.ReadInt64() != 0x454C494641564944) { reader.Close(); return; }
reader.Close();
file.Decrypt();
}
@@ -21,13 +16,7 @@ namespace PD_Tool
public static void Encrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() == 0x454C494641564944)
{
reader.Close();
Decrypt(file);
return;
}
if (reader.ReadInt64() == 0x454C494641564944) { reader.Close(); return; }
file.Encrypt();
}
}
+14 -20
View File
@@ -1,7 +1,7 @@
using System;
using KKdMainLib;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
using KKdMainLib;
using KKdA3DA = KKdMainLib.A3DA.A3DA;
using KKdFARC = KKdMainLib.FARC;
@@ -19,11 +19,9 @@ namespace PD_Tool.Tools
bool MP = false;
foreach (string file in FileNames)
if (file.EndsWith(".mp" )) { MP = true; break; }
else if (file.EndsWith(".json")) { MP = true; break; }
else if (file.EndsWith(".farc")) { MP = true; break; }
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { MP = true; break; }
Main.Format Format = Main.Format.NULL;
Format Format = Format.NULL;
string format = "";
if (MP)
{
@@ -42,13 +40,13 @@ namespace PD_Tool.Tools
Main.ConsoleDesign(true);
Console.WriteLine();
format = Console.ReadLine();
if (format == "1") Format = Main.Format.DT ;
else if (format == "2") Format = Main.Format.F ;
else if (format == "3") Format = Main.Format.FT ;
else if (format == "4") Format = Main.Format.FT ;
else if (format == "5") Format = Main.Format.F2LE;
else if (format == "6") Format = Main.Format.MGF ;
else if (format == "7") Format = Main.Format.X ;
if (format == "1") Format = Format.DT ;
else if (format == "2") Format = Format.F ;
else if (format == "3") Format = Format.FT ;
else if (format == "4") Format = Format.FT ;
else if (format == "5") Format = Format.F2LE;
else if (format == "6") Format = Format.MGF ;
else if (format == "7") Format = Format.X ;
else return;
}
@@ -79,12 +77,9 @@ namespace PD_Tool.Tools
A3DA = A.MsgPackWriter();
A = new KKdA3DA();
A.MsgPackReader(A3DA);
A.IO = File.OpenWriter();
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
FARC.Files[i].Data = (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter();
FARC.Files[i].Data = (format != "1" && format != "3") ? A.A3DCWriter() : A.A3DAWriter();
}
}
FARC.Save();
@@ -97,8 +92,7 @@ namespace PD_Tool.Tools
else if (ext == ".mp" || ext == ".json")
{
A.MsgPackReader(filepath, ext == ".json");
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
+8 -7
View File
@@ -1,6 +1,7 @@
using System;
using KKdMainLib;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib;
using KKdDEX = KKdMainLib.DEX;
namespace PD_Tool.Tools
@@ -39,11 +40,11 @@ namespace PD_Tool.Tools
Console.WriteLine();
format = Console.ReadLine();
Main.Format Format = Main.Format.NULL;
if (format == "1") Format = Main.Format.F ;
else if (format == "2") Format = Main.Format.F2LE;
else if (format == "3") Format = Main.Format.X ;
else if (format == "9" && (MP && _JSON)) Format = Main.Format.NULL;
Format Format = Format.NULL;
if (format == "1") Format = Format.F ;
else if (format == "2") Format = Format.F2LE;
else if (format == "3") Format = Format.X ;
else if (format == "9" && (MP && _JSON)) Format = Format.NULL;
else return;
foreach (string file in FileNames)
@@ -58,7 +59,7 @@ namespace PD_Tool.Tools
DEX. DEXReader(filepath, ext );
else DEX.MsgPackReader(filepath, JSON);
if (Format > Main.Format.NULL)
if (Format > Format.NULL)
DEX. DEXWriter(filepath, Format);
else DEX.MsgPackWriter(filepath, JSON );
DEX = null;