From d04f0ce6d6deceaaf303e16596de36555e07e497 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Thu, 21 Aug 2014 09:47:36 -0400 Subject: [PATCH] Added Illusion plugin for Universal Editor --- .../Class1.cs | 11 ++ .../FileSystem/Illusion/PP/PPCodec.cs | 14 ++ .../FileSystem/Illusion/PP/PPDataFormat.cs | 136 ++++++++++++++++ .../FileSystem/Illusion/PP/PPFormatInfo.cs | 13 ++ .../FileSystem/Illusion/PP/PPKnownKeys.cs | 152 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++ .../UniversalEditor.Plugins.Illusion.csproj | 61 +++++++ CSharp/UniversalEditor.WindowsForms.sln | 7 + 8 files changed, 430 insertions(+) create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/Class1.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPCodec.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPDataFormat.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPFormatInfo.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPKnownKeys.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/Properties/AssemblyInfo.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Illusion/UniversalEditor.Plugins.Illusion.csproj diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Class1.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Class1.cs new file mode 100644 index 00000000..813c1f90 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Class1.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.Plugins.Illusion +{ + public class Class1 + { + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPCodec.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPCodec.cs new file mode 100644 index 00000000..6ab2a51a --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPCodec.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.FileSystem.Illusion.PP +{ + public enum PPCodec + { + AG3, + SB3, + SM + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPDataFormat.cs new file mode 100644 index 00000000..083c226a --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPDataFormat.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.Illusion.PP +{ + public class PPDataFormat : DataFormat + { + private static DataFormatReference _dfr = null; + public override DataFormatReference MakeReference() + { + if (_dfr == null) + { + _dfr = base.MakeReference(); + _dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All); + _dfr.Filters.Add("Illusion Games' PP archive", new string[] { "*.pp" }); + } + return _dfr; + } + + + private static byte[] Decrypt(byte[] data) + { + byte[] output = (data.Clone() as byte[]); + for (int i = 0; i < output.Length; i++) + { + output[i] = (byte)(-(output[i])); + } + return output; + } + private static void Decrypt(byte[] buf, int size, PPFormatInfo format) + { + int i; + switch (format.codec) + { + case PPCodec.SB3: + { + // SB3/RL/base.pp + for (i = 0; i < size; i++) + { + buf[i] = (byte)(-(int)buf[i]); + } + break; + } + case PPCodec.SM: + { + // SM and all trials + byte[] key = format.key; + for (i = 0; i < size; i += 4) + { + uint value = BitConverter.ToUInt32(buf, i); + value ^= key[i & 7]; + byte[] bytes = BitConverter.GetBytes(value); + + for (int j = 0; j < 4; j++) + { + key[i + j] = bytes[j]; + } + } + break; + } + case PPCodec.AG3: + { + // AG3/DT/HAKO + int len = size / 2; + + byte[] codeA = new byte[16]; + byte[] codeB = new byte[16]; + + Array.Copy(format.key, 0, codeA, 0, 16); + Array.Copy(format.key, 16, codeB, 0, 16); + + for (i = 0; i < len; i++) + { + codeA[i & 3] += codeB[i & 3]; + + buf[i] = (byte)(buf[i] ^ codeA[i & 3]); + } + break; + } + } + } + + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + Reader br = base.Accessor.Reader; + uint unknown1 = br.ReadUInt32(); + uint unknown2 = br.ReadUInt32(); + + for (uint i = 0; i < unknown1; i++) + { + File file = new File(); + byte[] nameBytes = br.ReadBytes(32); + nameBytes = Decrypt(nameBytes); + + file.Name = Encoding.ShiftJIS.GetString(nameBytes); + file.Name = file.Name.TrimNull(); + fsom.Files.Add(file); + } + + uint offset = (uint)(br.Accessor.Position + (4 * fsom.Files.Count)); + foreach (File file in fsom.Files) + { + byte[] lengthData = br.ReadBytes(4); + lengthData = Decrypt(lengthData); + uint length = BitConverter.ToUInt32(lengthData, 0); + + file.Size = length; + file.Properties.Add("reader", br); + file.Properties.Add("offset", offset); + file.Properties.Add("length", length); + file.DataRequest += file_DataRequest; + offset += length; + } + } + + private void file_DataRequest(object sender, DataRequestEventArgs e) + { + File file = (sender as File); + Reader br = (Reader)file.Properties["reader"]; + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + br.Accessor.Seek(offset, SeekOrigin.Begin); + byte[] data = br.ReadBytes(length); + data = Decrypt(data); + e.Data = data; + } + protected override void SaveInternal(ObjectModel objectModel) + { + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPFormatInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPFormatInfo.cs new file mode 100644 index 00000000..26cb7e30 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPFormatInfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.FileSystem.Illusion.PP +{ + public struct PPFormatInfo + { + public PPCodec codec; + public byte[] key; + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPKnownKeys.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPKnownKeys.cs new file mode 100644 index 00000000..e457df5e --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/DataFormats/FileSystem/Illusion/PP/PPKnownKeys.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.FileSystem.Illusion.PP +{ + public static class PPKnownKeys + { + public static readonly byte[] HakoTrialCode = + { + 0x11,0x73,0x10,0x21,0x5A,0xA1,0xD0,0x8B, + 0x32,0x91,0x63,0x50,0xE9,0xA8,0xF6,0xD8, + 0x40,0x72,0x80,0xF9,0xEC,0x79,0x6E,0x8D, + 0x36,0x72,0x2B,0xA1,0x76,0xB6,0x67,0x92 + }; + + public static readonly byte[] AG3WelcomeCode = + { + 0xE5,0x77,0x64,0x05,0xD2,0x37,0x4D,0x2E, + 0xB7,0x4A,0xB7,0x2B,0x22,0x70,0xF1,0xD6, + 0xC7,0xE7,0x61,0x6D,0x10,0xED,0xF5,0xC1, + 0xD9,0x08,0x28,0xEC,0xE2,0x09,0xEA,0xD7 + }; + + public static readonly byte[] SMTrialCode = + { + 0x7C,0xF2,0x35,0x77,0x54,0x18,0x20,0x6E, + 0x9C,0x7B,0x9E,0x85,0x1F,0xB5,0x71,0x40, + 0x25,0xAD,0x71,0x43,0x64,0x20,0x20,0x7E, + 0xCF,0xE3,0x85,0xC0,0x41,0xDE,0x23,0x12 + }; + + public static readonly byte[] SMRetailCode = + { + 0x1E,0x5D,0x13,0xDD,0x7D,0x4C,0x4F,0xA7, + 0xDB,0xA7,0x29,0x14,0x10,0xF8,0xC0,0xBE, + 0x44,0x7F,0xD0,0x63,0x1C,0x22,0x7C,0x9F, + 0xE8,0xB9,0xF8,0xBE,0x58,0xB3,0xEF,0xF4 + }; + + public static readonly byte[] AtHomeFigureCode = + { + 0xAB,0x2C,0xC4,0x4E,0x7B,0xDF,0xBD,0x17, + 0xDC,0x2E,0x23,0x1E,0x4B,0xE5,0x80,0x3C, + 0x93,0xB1,0x1D,0x8C,0x81,0x36,0xB3,0x88, + 0x35,0x2D,0x30,0x4B,0x10,0x66,0xC8,0xE6 + }; + + public static readonly byte[] AtHomeTrialCode = + { + 0x67,0xF9,0x30,0x5A,0x09,0xAB,0xF5,0x60, + 0xD6,0x9F,0xFD,0x93,0xBA,0x9C,0xF5,0x60, + 0x11,0x6A,0xBA,0x79,0x4C,0x41,0x4A,0x8D, + 0xC7,0xBA,0xBB,0x9C,0x26,0x34,0x0F,0xEF + }; + + public static readonly byte[] RGTrialCode = + { + 0x58,0x62,0x86,0xD2,0x3B,0x2F,0xC4,0x5F, + 0xEE,0x58,0x76,0x2D,0xB4,0x02,0x02,0xCD, + 0x0A,0x08,0x40,0x30,0x08,0x66,0x1D,0xE8, + 0x9B,0xA6,0x61,0xCB,0x63,0xF3,0xF3,0xB4, + }; + + public static readonly byte[] YuushaRetailCode = + { + 0x2B, 0xA8, 0xF2, 0x1E, 0xDD, 0x1D, 0x95, + 0xC8, 0x7E, 0xD4, 0x4F, 0x76, 0x6F, 0x41, + 0xBF, 0xC7 + }; + + public static readonly byte[] YuushaTrialCode = + { + 0xD1,0xEC,0x08,0xA1,0x48,0x7F,0xD6,0x8F, + 0xAD,0x34,0xB2,0xA2,0x35,0x4D,0x55,0xD1, + 0x1F,0xC1,0xB4,0x47,0x2F,0x54,0x89,0x24, + 0x61,0xCE,0xB7,0xA5,0x22,0x80,0x05,0x29, + }; + + public static readonly byte[] EskMateCode = + { + 0xE9,0xEC,0xFC,0x9F,0x67,0x4A,0x91,0x8D, + 0x72,0x4F,0x5F,0xAE,0xBB,0xA5,0xF7,0x0A, + 0x12,0xB9,0x03,0xC5,0x4E,0x1C,0xE3,0x7A, + 0x7E,0xF4,0x05,0x48,0x51,0x18,0x16,0x99 + }; + + public static readonly byte[] CharacolleBenchCode = + { + 0xEB,0xD6,0x6B,0x29,0x21,0x03,0xA9,0x2C, + 0x5F,0x5F,0xEF,0xBB,0xEC,0x10,0xFC,0x4C, + 0x51,0xED,0xD4,0xBE,0x99,0x4D,0x45,0x06, + 0x65,0x51,0x8E,0x25,0x33,0x5C,0x05,0x53, + }; + + public static readonly byte[] SBZeroRetailCode = + { + 0x14,0x6F,0x07,0xB8,0x9A,0x0E,0x84,0x44, + 0x59,0x25,0x8E,0x18,0xBC,0x39,0x9E,0x5C, + 0x99,0x7A,0xA0,0x92,0xD4,0xB7,0xBC,0x55, + 0x1E,0x2E,0x88,0x27,0x14,0xA1,0xE6,0x27, + }; + + public static readonly byte[] AtHomeRetailCode = + { + 0x7E, 0x71, 0x0E, 0x78, 0xE7, 0xAF, 0xA7, + 0x8F, 0x1F, 0x9E, 0xE3, 0xC5, 0x08, 0x00, + 0x3A, 0x71 + }; + + public static readonly byte[] AG3RetailCode = + { + 0xCA, 0x00, 0x6E, 0x00, 0x0D, 0x00, 0xB3, + 0x00, 0x9C, 0x00, 0x36, 0x00, 0x1E, 0x00, + 0xE8, 0x00 + }; + + public static readonly byte[] HakoRetailCode = + { + 0xEE, 0xCB, 0x75, 0x16, 0x33, 0x35, 0xE6, 0x4C, + 0x68, 0x2F, 0x6D, 0x93, 0x0D, 0xF4, 0x39, 0x05 + }; + + public static readonly byte[] DGRetailCode = + { + 0x10, 0x21, 0xD0, 0x8B, 0x63, 0x50, 0xF6, 0xD8, + 0x11, 0x73, 0x5A, 0xA1, 0x32, 0x91, 0xE9, 0xA8 + }; + + public static readonly byte[] SMSweetsRetailCode = + { + 0x86, 0x3F, 0xD5, 0xB8, 0xB4, 0x4A, 0xF4, 0x06, + 0xF6, 0x70, 0x8A, 0x07, 0x26, 0x2F, 0x72, 0x35 + }; + + public static readonly byte[] SM2TrialCode = + { + 0x85, 0x45, 0x1B, 0xBC, 0x6E, 0xDA, 0x0E, 0xA6, + 0x3F, 0xCE, 0x98, 0x7D, 0xD7, 0x68, 0xD9, 0xEF, + 0xB4, 0x3C, 0x86, 0xEF, 0x4B, 0x0D, 0x08, 0x28, + 0xF7, 0xDE, 0x12, 0xA6, 0xB7, 0x0A, 0x61, 0x7A + }; + + public static readonly byte[] SM2RetailCode = + { + 0x43, 0xCE, 0x31, 0x6F, 0x65, 0xFC, 0x2F, + 0x9D, 0x82, 0x41, 0x73, 0xC4, 0x75, 0x9D, + 0xB7, 0xD5 + }; + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Properties/AssemblyInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..f00a5a88 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UniversalEditor.Plugins.Illusion")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("City of Orlando")] +[assembly: AssemblyProduct("UniversalEditor.Plugins.Illusion")] +[assembly: AssemblyCopyright("Copyright © City of Orlando 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("60446a7e-85af-49ed-81c1-007e06433be4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Illusion/UniversalEditor.Plugins.Illusion.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/UniversalEditor.Plugins.Illusion.csproj new file mode 100644 index 00000000..4672c038 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Illusion/UniversalEditor.Plugins.Illusion.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {A968C097-44CE-42BA-B66C-CB3A871EE117} + Library + Properties + UniversalEditor + UniversalEditor.Plugins.Illusion + v3.5 + 512 + + + true + full + false + ..\..\Output\Debug\Plugins\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Output\Release\Plugins\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + {a92d520b-ffa3-4464-8cf6-474d18959e03} + UniversalEditor.Core + + + {30467e5c-05bc-4856-aadc-13906ef4cadd} + UniversalEditor.Essential + + + + + \ No newline at end of file diff --git a/CSharp/UniversalEditor.WindowsForms.sln b/CSharp/UniversalEditor.WindowsForms.sln index 611630ff..b742fc60 100644 --- a/CSharp/UniversalEditor.WindowsForms.sln +++ b/CSharp/UniversalEditor.WindowsForms.sln @@ -119,6 +119,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Ica EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Icarus.UserInterface.WindowsForms", "Engines\WindowsForms\Plugins\UniversalEditor.Plugins.Icarus.UserInterface.WindowsForms\UniversalEditor.Plugins.Icarus.UserInterface.WindowsForms.csproj", "{F19919B7-1D51-4972-8E4A-E59D68D4926A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Illusion", "Plugins\UniversalEditor.Plugins.Illusion\UniversalEditor.Plugins.Illusion.csproj", "{A968C097-44CE-42BA-B66C-CB3A871EE117}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -317,6 +319,10 @@ Global {F19919B7-1D51-4972-8E4A-E59D68D4926A}.Debug|Any CPU.Build.0 = Debug|Any CPU {F19919B7-1D51-4972-8E4A-E59D68D4926A}.Release|Any CPU.ActiveCfg = Release|Any CPU {F19919B7-1D51-4972-8E4A-E59D68D4926A}.Release|Any CPU.Build.0 = Release|Any CPU + {A968C097-44CE-42BA-B66C-CB3A871EE117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A968C097-44CE-42BA-B66C-CB3A871EE117}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A968C097-44CE-42BA-B66C-CB3A871EE117}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A968C097-44CE-42BA-B66C-CB3A871EE117}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -357,6 +363,7 @@ Global {4698BC3F-EC29-42EB-9AED-3D8F9983A108} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {04674541-23C2-4308-A9DF-DBC43AE99814} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {B2DFA94A-A468-48A1-AB31-04EE432E7B2B} = {71CFF024-26F7-4626-A526-B435FDF8D64E} + {A968C097-44CE-42BA-B66C-CB3A871EE117} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {FE016EA3-DC31-4A92-8B0A-8C746EC117E1} = {46041F27-7C1C-4209-B72B-251EDB5D4C61} {ED627DF7-3E78-4428-AB31-810BA1586E62} = {46041F27-7C1C-4209-B72B-251EDB5D4C61} {C1F34183-7A2F-41A6-9958-F6F329099654} = {A846CA33-9CAA-4237-B14F-8721DBA89442}