diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/BaseComponentMode.cs b/AutofaceXlua/unity/AppFrameCore/Core/BaseComponentMode.cs similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/BaseComponentMode.cs rename to AutofaceXlua/unity/AppFrameCore/Core/BaseComponentMode.cs diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/BaseComponentMode.cs.meta b/AutofaceXlua/unity/AppFrameCore/Core/BaseComponentMode.cs.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/BaseComponentMode.cs.meta rename to AutofaceXlua/unity/AppFrameCore/Core/BaseComponentMode.cs.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionAttribute.cs b/AutofaceXlua/unity/AppFrameCore/Core/InjectionAttribute.cs similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionAttribute.cs rename to AutofaceXlua/unity/AppFrameCore/Core/InjectionAttribute.cs diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionAttribute.cs.meta b/AutofaceXlua/unity/AppFrameCore/Core/InjectionAttribute.cs.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionAttribute.cs.meta rename to AutofaceXlua/unity/AppFrameCore/Core/InjectionAttribute.cs.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionEnter.cs b/AutofaceXlua/unity/AppFrameCore/Core/InjectionEnter.cs similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionEnter.cs rename to AutofaceXlua/unity/AppFrameCore/Core/InjectionEnter.cs diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionEnter.cs.meta b/AutofaceXlua/unity/AppFrameCore/Core/InjectionEnter.cs.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/InjectionEnter.cs.meta rename to AutofaceXlua/unity/AppFrameCore/Core/InjectionEnter.cs.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Plugins.meta b/AutofaceXlua/unity/AppFrameCore/Core/Plugins.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Plugins.meta rename to AutofaceXlua/unity/AppFrameCore/Core/Plugins.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Singleton.cs b/AutofaceXlua/unity/AppFrameCore/Core/Singleton.cs similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Singleton.cs rename to AutofaceXlua/unity/AppFrameCore/Core/Singleton.cs diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Singleton.cs.meta b/AutofaceXlua/unity/AppFrameCore/Core/Singleton.cs.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Singleton.cs.meta rename to AutofaceXlua/unity/AppFrameCore/Core/Singleton.cs.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/SingletonMono.cs b/AutofaceXlua/unity/AppFrameCore/Core/SingletonMono.cs similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/SingletonMono.cs rename to AutofaceXlua/unity/AppFrameCore/Core/SingletonMono.cs diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/SingletonMono.cs.meta b/AutofaceXlua/unity/AppFrameCore/Core/SingletonMono.cs.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/SingletonMono.cs.meta rename to AutofaceXlua/unity/AppFrameCore/Core/SingletonMono.cs.meta diff --git a/AutofaceXlua/unity/AppFrameCore/Core/XXTEA.cs b/AutofaceXlua/unity/AppFrameCore/Core/XXTEA.cs new file mode 100644 index 0000000..0671634 --- /dev/null +++ b/AutofaceXlua/unity/AppFrameCore/Core/XXTEA.cs @@ -0,0 +1,178 @@ +namespace Xxtea { + using System; + using System.Text; + + public sealed class XXTEA { + private static readonly UTF8Encoding utf8 = new UTF8Encoding(); + + private const UInt32 delta = 0x9E3779B9; + + private static UInt32 MX(UInt32 sum, UInt32 y, UInt32 z, Int32 p, UInt32 e, UInt32[] k) { + return (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z); + } + + private XXTEA() { + } + + public static Byte[] Encrypt(Byte[] data, Byte[] key) { + if (data.Length == 0) { + return data; + } + return ToByteArray(Encrypt(ToUInt32Array(data, true), ToUInt32Array(FixKey(key), false)), false); + } + + public static Byte[] Encrypt(String data, Byte[] key) { + return Encrypt(utf8.GetBytes(data), key); + } + + public static Byte[] Encrypt(Byte[] data, String key) { + return Encrypt(data, utf8.GetBytes(key)); + } + + public static Byte[] Encrypt(String data, String key) { + return Encrypt(utf8.GetBytes(data), utf8.GetBytes(key)); + } + + public static String EncryptToBase64String(Byte[] data, Byte[] key) { + return Convert.ToBase64String(Encrypt(data, key)); + } + + public static String EncryptToBase64String(String data, Byte[] key) { + return Convert.ToBase64String(Encrypt(data, key)); + } + + public static String EncryptToBase64String(Byte[] data, String key) { + return Convert.ToBase64String(Encrypt(data, key)); + } + + public static String EncryptToBase64String(String data, String key) { + return Convert.ToBase64String(Encrypt(data, key)); + } + + public static Byte[] Decrypt(Byte[] data, Byte[] key) { + if (data.Length == 0) { + return data; + } + return ToByteArray(Decrypt(ToUInt32Array(data, false), ToUInt32Array(FixKey(key), false)), true); + } + + public static Byte[] Decrypt(Byte[] data, String key) { + return Decrypt(data, utf8.GetBytes(key)); + } + + public static Byte[] DecryptBase64String(String data, Byte[] key) { + return Decrypt(Convert.FromBase64String(data), key); + } + + public static Byte[] DecryptBase64String(String data, String key) { + return Decrypt(Convert.FromBase64String(data), key); + } + + public static String DecryptToString(Byte[] data, Byte[] key) { + return utf8.GetString(Decrypt(data, key)); + } + + public static String DecryptToString(Byte[] data, String key) { + return utf8.GetString(Decrypt(data, key)); + } + + public static String DecryptBase64StringToString(String data, Byte[] key) { + return utf8.GetString(DecryptBase64String(data, key)); + } + + public static String DecryptBase64StringToString(String data, String key) { + return utf8.GetString(DecryptBase64String(data, key)); + } + + private static UInt32[] Encrypt(UInt32[] v, UInt32[] k) { + Int32 n = v.Length - 1; + if (n < 1) { + return v; + } + UInt32 z = v[n], y, sum = 0, e; + Int32 p, q = 6 + 52 / (n + 1); + unchecked { + while (0 < q--) { + sum += delta; + e = sum >> 2 & 3; + for (p = 0; p < n; p++) { + y = v[p + 1]; + z = v[p] += MX(sum, y, z, p, e, k); + } + y = v[0]; + z = v[n] += MX(sum, y, z, p, e, k); + } + } + return v; + } + + private static UInt32[] Decrypt(UInt32[] v, UInt32[] k) { + Int32 n = v.Length - 1; + if (n < 1) { + return v; + } + UInt32 z, y = v[0], sum, e; + Int32 p, q = 6 + 52 / (n + 1); + unchecked { + sum = (UInt32)(q * delta); + while (sum != 0) { + e = sum >> 2 & 3; + for (p = n; p > 0; p--) { + z = v[p - 1]; + y = v[p] -= MX(sum, y, z, p, e, k); + } + z = v[n]; + y = v[0] -= MX(sum, y, z, p, e, k); + sum -= delta; + } + } + return v; + } + + private static Byte[] FixKey(Byte[] key) { + if (key.Length == 16) return key; + Byte[] fixedkey = new Byte[16]; + if (key.Length < 16) { + key.CopyTo(fixedkey, 0); + } + else { + Array.Copy(key, 0, fixedkey, 0, 16); + } + return fixedkey; + } + + private static UInt32[] ToUInt32Array(Byte[] data, Boolean includeLength) { + Int32 length = data.Length; + Int32 n = (((length & 3) == 0) ? (length >> 2) : ((length >> 2) + 1)); + UInt32[] result; + if (includeLength) { + result = new UInt32[n + 1]; + result[n] = (UInt32)length; + } + else { + result = new UInt32[n]; + } + for (Int32 i = 0; i < length; i++) { + result[i >> 2] |= (UInt32)data[i] << ((i & 3) << 3); + } + return result; + } + + private static Byte[] ToByteArray(UInt32[] data, Boolean includeLength) { + Int32 n = data.Length << 2; + if (includeLength) { + Int32 m = (Int32)data[data.Length - 1]; + n -= 4; + if ((m < n - 3) || (m > n)) { + return null; + } + n = m; + } + Byte[] result = new Byte[n]; + for (Int32 i = 0; i < n; i++) { + result[i] = (Byte)(data[i >> 2] >> ((i & 3) << 3)); + } + return result; + } + } +} \ No newline at end of file diff --git a/AutofaceXlua/unity/AppFrameCore/Properties/AssemblyInfo.cs b/AutofaceXlua/unity/AppFrameCore/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..901927f --- /dev/null +++ b/AutofaceXlua/unity/AppFrameCore/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("AppFrameCore")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AppFrameCore")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("50802f8d-5d0f-49ca-a13c-1c25bfd1f8f6")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.dll new file mode 100644 index 0000000..396d53e Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.dll differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.pdb b/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.pdb new file mode 100644 index 0000000..7b652cc Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/AppFrameCore.pdb differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.dll new file mode 100644 index 0000000..7f7592a Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.dll differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Plugins/Autofac/Autofac.xml b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.xml similarity index 97% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Plugins/Autofac/Autofac.xml rename to AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.xml index 849b42e..cc39281 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/Project/Code/Core/Plugins/Autofac/Autofac.xml +++ b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Autofac.xml @@ -188,52 +188,6 @@ Tag applied to matching lifetime scopes. A registration builder allowing further configuration of the component. - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - Service type. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - Service type. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - The service type provided by the component. - Key to associate with the component. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - Key to associate with the component. - The service type provided by the component. - A registration builder allowing further configuration of the component. - Configure the services that the component will provide. The generic parameter(s) to As() @@ -4170,52 +4124,6 @@ Tag applied to matching lifetime scopes. A registration builder allowing further configuration of the component. - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - The service type provided by the component. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - The service type provided by the component. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - The service type provided by the component. - Key to associate with the component. - A registration builder allowing further configuration of the component. - - - - Configure the component so that every dependent component or call to Resolve() - within a ILifetimeScope created by an owned instance gets the same, shared instance. - Dependent components in lifetime scopes that are children of the owned instance scope will - share the parent's instance. If no appropriate owned instance scope can be found in the - hierarchy an is thrown. - - Key to associate with the component. - The service type provided by the component. - A registration builder allowing further configuration of the component. - Configure the services that the component will provide. The generic parameter(s) to As() @@ -4456,21 +4364,6 @@ The builder to register the module with. The module to add. - - - Registers modules found in an assembly. - - Container builder. - The assemblies from which to register modules. - - - - Registers modules found in an assembly. - - Container builder. - The assemblies from which to register modules. - The type of the module to add. - Add a component to the container. diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.dll new file mode 100644 index 0000000..e56a30a Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.dll differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.pdb b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.pdb new file mode 100644 index 0000000..4c98a49 Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/Core.pdb differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.UI.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.UI.dll new file mode 100644 index 0000000..355188d Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.UI.dll differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.dll new file mode 100644 index 0000000..2fa5381 Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEditor.dll differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.UI.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.UI.dll new file mode 100644 index 0000000..67bdd24 Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.UI.dll differ diff --git a/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.dll b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.dll new file mode 100644 index 0000000..7577bdc Binary files /dev/null and b/AutofaceXlua/unity/AppFrameCore/bin/Debug/UnityEngine.dll differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip.meta similarity index 67% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip.meta index dc05db6..e6749a3 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: fce1230ad23650f43b70ae9e815448a7 +guid: fdeeead475e69e249a466b68f67d6fbe folderAsset: yes -timeCreated: 1503382209 +timeCreated: 1503974380 licenseType: Pro DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common.meta similarity index 67% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common.meta index dfae9a2..6550195 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 0c2493fccdb6a2141933ed2ec5d4786b +guid: c056693968539cd49b4a77c570e99d76 folderAsset: yes -timeCreated: 1486348159 +timeCreated: 1502467325 licenseType: Free DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs new file mode 100644 index 0000000..82cc857 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs @@ -0,0 +1,55 @@ +// Common/CRC.cs + +namespace SevenZip +{ + class CRC + { + public static readonly uint[] Table; + + static CRC() + { + Table = new uint[256]; + const uint kPoly = 0xEDB88320; + for (uint i = 0; i < 256; i++) + { + uint r = i; + for (int j = 0; j < 8; j++) + if ((r & 1) != 0) + r = (r >> 1) ^ kPoly; + else + r >>= 1; + Table[i] = r; + } + } + + uint _value = 0xFFFFFFFF; + + public void Init() { _value = 0xFFFFFFFF; } + + public void UpdateByte(byte b) + { + _value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); + } + + public void Update(byte[] data, uint offset, uint size) + { + for (uint i = 0; i < size; i++) + _value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); + } + + public uint GetDigest() { return _value ^ 0xFFFFFFFF; } + + static uint CalculateDigest(byte[] data, uint offset, uint size) + { + CRC crc = new CRC(); + // crc.Init(); + crc.Update(data, offset, size); + return crc.GetDigest(); + } + + static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) + { + return (CalculateDigest(data, offset, size) == digest); + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs.meta new file mode 100644 index 0000000..3ceaa7e --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CRC.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 37bdc708db9edfe449f2d009539ae9e1 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs new file mode 100644 index 0000000..8eabf59 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs @@ -0,0 +1,274 @@ +// CommandLineParser.cs + +using System; +using System.Collections; + +namespace SevenZip.CommandLineParser +{ + public enum SwitchType + { + Simple, + PostMinus, + LimitedPostString, + UnLimitedPostString, + PostChar + } + + public class SwitchForm + { + public string IDString; + public SwitchType Type; + public bool Multi; + public int MinLen; + public int MaxLen; + public string PostCharSet; + + public SwitchForm(string idString, SwitchType type, bool multi, + int minLen, int maxLen, string postCharSet) + { + IDString = idString; + Type = type; + Multi = multi; + MinLen = minLen; + MaxLen = maxLen; + PostCharSet = postCharSet; + } + public SwitchForm(string idString, SwitchType type, bool multi, int minLen): + this(idString, type, multi, minLen, 0, "") + { + } + public SwitchForm(string idString, SwitchType type, bool multi): + this(idString, type, multi, 0) + { + } + } + + public class SwitchResult + { + public bool ThereIs; + public bool WithMinus; + public ArrayList PostStrings = new ArrayList(); + public int PostCharIndex; + public SwitchResult() + { + ThereIs = false; + } + } + + public class Parser + { + public ArrayList NonSwitchStrings = new ArrayList(); + SwitchResult[] _switches; + + public Parser(int numSwitches) + { + _switches = new SwitchResult[numSwitches]; + for (int i = 0; i < numSwitches; i++) + _switches[i] = new SwitchResult(); + } + + bool ParseString(string srcString, SwitchForm[] switchForms) + { + int len = srcString.Length; + if (len == 0) + return false; + int pos = 0; + if (!IsItSwitchChar(srcString[pos])) + return false; + while (pos < len) + { + if (IsItSwitchChar(srcString[pos])) + pos++; + const int kNoLen = -1; + int matchedSwitchIndex = 0; + int maxLen = kNoLen; + for (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++) + { + int switchLen = switchForms[switchIndex].IDString.Length; + if (switchLen <= maxLen || pos + switchLen > len) + continue; + if (String.Compare(switchForms[switchIndex].IDString, 0, + srcString, pos, switchLen, true) == 0) + { + matchedSwitchIndex = switchIndex; + maxLen = switchLen; + } + } + if (maxLen == kNoLen) + throw new Exception("maxLen == kNoLen"); + SwitchResult matchedSwitch = _switches[matchedSwitchIndex]; + SwitchForm switchForm = switchForms[matchedSwitchIndex]; + if ((!switchForm.Multi) && matchedSwitch.ThereIs) + throw new Exception("switch must be single"); + matchedSwitch.ThereIs = true; + pos += maxLen; + int tailSize = len - pos; + SwitchType type = switchForm.Type; + switch (type) + { + case SwitchType.PostMinus: + { + if (tailSize == 0) + matchedSwitch.WithMinus = false; + else + { + matchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus); + if (matchedSwitch.WithMinus) + pos++; + } + break; + } + case SwitchType.PostChar: + { + if (tailSize < switchForm.MinLen) + throw new Exception("switch is not full"); + string charSet = switchForm.PostCharSet; + const int kEmptyCharValue = -1; + if (tailSize == 0) + matchedSwitch.PostCharIndex = kEmptyCharValue; + else + { + int index = charSet.IndexOf(srcString[pos]); + if (index < 0) + matchedSwitch.PostCharIndex = kEmptyCharValue; + else + { + matchedSwitch.PostCharIndex = index; + pos++; + } + } + break; + } + case SwitchType.LimitedPostString: + case SwitchType.UnLimitedPostString: + { + int minLen = switchForm.MinLen; + if (tailSize < minLen) + throw new Exception("switch is not full"); + if (type == SwitchType.UnLimitedPostString) + { + matchedSwitch.PostStrings.Add(srcString.Substring(pos)); + return true; + } + String stringSwitch = srcString.Substring(pos, minLen); + pos += minLen; + for (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++) + { + char c = srcString[pos]; + if (IsItSwitchChar(c)) + break; + stringSwitch += c; + } + matchedSwitch.PostStrings.Add(stringSwitch); + break; + } + } + } + return true; + + } + + public void ParseStrings(SwitchForm[] switchForms, string[] commandStrings) + { + int numCommandStrings = commandStrings.Length; + bool stopSwitch = false; + for (int i = 0; i < numCommandStrings; i++) + { + string s = commandStrings[i]; + if (stopSwitch) + NonSwitchStrings.Add(s); + else + if (s == kStopSwitchParsing) + stopSwitch = true; + else + if (!ParseString(s, switchForms)) + NonSwitchStrings.Add(s); + } + } + + public SwitchResult this[int index] { get { return _switches[index]; } } + + public static int ParseCommand(CommandForm[] commandForms, string commandString, + out string postString) + { + for (int i = 0; i < commandForms.Length; i++) + { + string id = commandForms[i].IDString; + if (commandForms[i].PostStringMode) + { + if (commandString.IndexOf(id) == 0) + { + postString = commandString.Substring(id.Length); + return i; + } + } + else + if (commandString == id) + { + postString = ""; + return i; + } + } + postString = ""; + return -1; + } + + static bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms, + string commandString, ArrayList indices) + { + indices.Clear(); + int numUsedChars = 0; + for (int i = 0; i < numForms; i++) + { + CommandSubCharsSet charsSet = forms[i]; + int currentIndex = -1; + int len = charsSet.Chars.Length; + for (int j = 0; j < len; j++) + { + char c = charsSet.Chars[j]; + int newIndex = commandString.IndexOf(c); + if (newIndex >= 0) + { + if (currentIndex >= 0) + return false; + if (commandString.IndexOf(c, newIndex + 1) >= 0) + return false; + currentIndex = j; + numUsedChars++; + } + } + if (currentIndex == -1 && !charsSet.EmptyAllowed) + return false; + indices.Add(currentIndex); + } + return (numUsedChars == commandString.Length); + } + const char kSwitchID1 = '-'; + const char kSwitchID2 = '/'; + + const char kSwitchMinus = '-'; + const string kStopSwitchParsing = "--"; + + static bool IsItSwitchChar(char c) + { + return (c == kSwitchID1 || c == kSwitchID2); + } + } + + public class CommandForm + { + public string IDString = ""; + public bool PostStringMode = false; + public CommandForm(string idString, bool postStringMode) + { + IDString = idString; + PostStringMode = postStringMode; + } + } + + class CommandSubCharsSet + { + public string Chars = ""; + public bool EmptyAllowed = false; + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs.meta new file mode 100644 index 0000000..ac212d3 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/CommandLineParser.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ea75322b092b431419ca2c6a7fa92539 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs new file mode 100644 index 0000000..7c51f0b --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs @@ -0,0 +1,72 @@ +// InBuffer.cs + +namespace SevenZip.Buffer +{ + public class InBuffer + { + byte[] m_Buffer; + uint m_Pos; + uint m_Limit; + uint m_BufferSize; + System.IO.Stream m_Stream; + bool m_StreamWasExhausted; + ulong m_ProcessedSize; + + public InBuffer(uint bufferSize) + { + m_Buffer = new byte[bufferSize]; + m_BufferSize = bufferSize; + } + + public void Init(System.IO.Stream stream) + { + m_Stream = stream; + m_ProcessedSize = 0; + m_Limit = 0; + m_Pos = 0; + m_StreamWasExhausted = false; + } + + public bool ReadBlock() + { + if (m_StreamWasExhausted) + return false; + m_ProcessedSize += m_Pos; + int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize); + m_Pos = 0; + m_Limit = (uint)aNumProcessedBytes; + m_StreamWasExhausted = (aNumProcessedBytes == 0); + return (!m_StreamWasExhausted); + } + + + public void ReleaseStream() + { + // m_Stream.Close(); + m_Stream = null; + } + + public bool ReadByte(byte b) // check it + { + if (m_Pos >= m_Limit) + if (!ReadBlock()) + return false; + b = m_Buffer[m_Pos++]; + return true; + } + + public byte ReadByte() + { + // return (byte)m_Stream.ReadByte(); + if (m_Pos >= m_Limit) + if (!ReadBlock()) + return 0xFF; + return m_Buffer[m_Pos++]; + } + + public ulong GetProcessedSize() + { + return m_ProcessedSize + m_Pos; + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs.meta new file mode 100644 index 0000000..312fce0 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/InBuffer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c4bc7a612d151c142888b3904f198836 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs new file mode 100644 index 0000000..2da16e1 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs @@ -0,0 +1,47 @@ +// OutBuffer.cs + +namespace SevenZip.Buffer +{ + public class OutBuffer + { + byte[] m_Buffer; + uint m_Pos; + uint m_BufferSize; + System.IO.Stream m_Stream; + ulong m_ProcessedSize; + + public OutBuffer(uint bufferSize) + { + m_Buffer = new byte[bufferSize]; + m_BufferSize = bufferSize; + } + + public void SetStream(System.IO.Stream stream) { m_Stream = stream; } + public void FlushStream() { m_Stream.Flush(); } + public void CloseStream() { m_Stream.Close(); } + public void ReleaseStream() { m_Stream = null; } + + public void Init() + { + m_ProcessedSize = 0; + m_Pos = 0; + } + + public void WriteByte(byte b) + { + m_Buffer[m_Pos++] = b; + if (m_Pos >= m_BufferSize) + FlushData(); + } + + public void FlushData() + { + if (m_Pos == 0) + return; + m_Stream.Write(m_Buffer, 0, (int)m_Pos); + m_Pos = 0; + } + + public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs.meta new file mode 100644 index 0000000..1dec00e --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Common/OutBuffer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a6dc743d3c62ed248a752e49d92371ce +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod/GenericMethod.unity.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress.meta similarity index 58% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod/GenericMethod.unity.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress.meta index f94e1da..d036bc6 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Examples/09_GenericMethod/GenericMethod.unity.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 -guid: 19477d725133da049be476cb4caedf7d -timeCreated: 1486350257 +guid: 1685fa93be8d9b546b0c0ca8c14fa4d5 +folderAsset: yes +timeCreated: 1502467325 licenseType: Free DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ.meta new file mode 100644 index 0000000..5efd639 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c154ca6d87bdc60489ac6153a46c2611 +folderAsset: yes +timeCreated: 1502467325 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs new file mode 100644 index 0000000..10ca2b3 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs @@ -0,0 +1,24 @@ +// IMatchFinder.cs + +using System; + +namespace SevenZip.Compression.LZ +{ + interface IInWindowStream + { + void SetStream(System.IO.Stream inStream); + void Init(); + void ReleaseStream(); + Byte GetIndexByte(Int32 index); + UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit); + UInt32 GetNumAvailableBytes(); + } + + interface IMatchFinder : IInWindowStream + { + void Create(UInt32 historySize, UInt32 keepAddBufferBefore, + UInt32 matchMaxLen, UInt32 keepAddBufferAfter); + UInt32 GetMatches(UInt32[] distances); + void Skip(UInt32 num); + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs.meta new file mode 100644 index 0000000..823d781 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/IMatchFinder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 79a3b15c9826f974ab40f326fbbaf2f0 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs new file mode 100644 index 0000000..c1c006b --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs @@ -0,0 +1,367 @@ +// LzBinTree.cs + +using System; + +namespace SevenZip.Compression.LZ +{ + public class BinTree : InWindow, IMatchFinder + { + UInt32 _cyclicBufferPos; + UInt32 _cyclicBufferSize = 0; + UInt32 _matchMaxLen; + + UInt32[] _son; + UInt32[] _hash; + + UInt32 _cutValue = 0xFF; + UInt32 _hashMask; + UInt32 _hashSizeSum = 0; + + bool HASH_ARRAY = true; + + const UInt32 kHash2Size = 1 << 10; + const UInt32 kHash3Size = 1 << 16; + const UInt32 kBT2HashSize = 1 << 16; + const UInt32 kStartMaxLen = 1; + const UInt32 kHash3Offset = kHash2Size; + const UInt32 kEmptyHashValue = 0; + const UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1; + + UInt32 kNumHashDirectBytes = 0; + UInt32 kMinMatchCheck = 4; + UInt32 kFixHashSize = kHash2Size + kHash3Size; + + public void SetType(int numHashBytes) + { + HASH_ARRAY = (numHashBytes > 2); + if (HASH_ARRAY) + { + kNumHashDirectBytes = 0; + kMinMatchCheck = 4; + kFixHashSize = kHash2Size + kHash3Size; + } + else + { + kNumHashDirectBytes = 2; + kMinMatchCheck = 2 + 1; + kFixHashSize = 0; + } + } + + public new void SetStream(System.IO.Stream stream) { base.SetStream(stream); } + public new void ReleaseStream() { base.ReleaseStream(); } + + public new void Init() + { + base.Init(); + for (UInt32 i = 0; i < _hashSizeSum; i++) + _hash[i] = kEmptyHashValue; + _cyclicBufferPos = 0; + ReduceOffsets(-1); + } + + public new void MovePos() + { + if (++_cyclicBufferPos >= _cyclicBufferSize) + _cyclicBufferPos = 0; + base.MovePos(); + if (_pos == kMaxValForNormalize) + Normalize(); + } + + public new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); } + + public new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) + { return base.GetMatchLen(index, distance, limit); } + + public new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); } + + public void Create(UInt32 historySize, UInt32 keepAddBufferBefore, + UInt32 matchMaxLen, UInt32 keepAddBufferAfter) + { + if (historySize > kMaxValForNormalize - 256) + throw new Exception(); + _cutValue = 16 + (matchMaxLen >> 1); + + UInt32 windowReservSize = (historySize + keepAddBufferBefore + + matchMaxLen + keepAddBufferAfter) / 2 + 256; + + base.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize); + + _matchMaxLen = matchMaxLen; + + UInt32 cyclicBufferSize = historySize + 1; + if (_cyclicBufferSize != cyclicBufferSize) + _son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2]; + + UInt32 hs = kBT2HashSize; + + if (HASH_ARRAY) + { + hs = historySize - 1; + hs |= (hs >> 1); + hs |= (hs >> 2); + hs |= (hs >> 4); + hs |= (hs >> 8); + hs >>= 1; + hs |= 0xFFFF; + if (hs > (1 << 24)) + hs >>= 1; + _hashMask = hs; + hs++; + hs += kFixHashSize; + } + if (hs != _hashSizeSum) + _hash = new UInt32[_hashSizeSum = hs]; + } + + public UInt32 GetMatches(UInt32[] distances) + { + UInt32 lenLimit; + if (_pos + _matchMaxLen <= _streamPos) + lenLimit = _matchMaxLen; + else + { + lenLimit = _streamPos - _pos; + if (lenLimit < kMinMatchCheck) + { + MovePos(); + return 0; + } + } + + UInt32 offset = 0; + UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; + UInt32 cur = _bufferOffset + _pos; + UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize; + UInt32 hashValue, hash2Value = 0, hash3Value = 0; + + if (HASH_ARRAY) + { + UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1]; + hash2Value = temp & (kHash2Size - 1); + temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8); + hash3Value = temp & (kHash3Size - 1); + hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask; + } + else + hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8); + + UInt32 curMatch = _hash[kFixHashSize + hashValue]; + if (HASH_ARRAY) + { + UInt32 curMatch2 = _hash[hash2Value]; + UInt32 curMatch3 = _hash[kHash3Offset + hash3Value]; + _hash[hash2Value] = _pos; + _hash[kHash3Offset + hash3Value] = _pos; + if (curMatch2 > matchMinPos) + if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur]) + { + distances[offset++] = maxLen = 2; + distances[offset++] = _pos - curMatch2 - 1; + } + if (curMatch3 > matchMinPos) + if (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur]) + { + if (curMatch3 == curMatch2) + offset -= 2; + distances[offset++] = maxLen = 3; + distances[offset++] = _pos - curMatch3 - 1; + curMatch2 = curMatch3; + } + if (offset != 0 && curMatch2 == curMatch) + { + offset -= 2; + maxLen = kStartMaxLen; + } + } + + _hash[kFixHashSize + hashValue] = _pos; + + UInt32 ptr0 = (_cyclicBufferPos << 1) + 1; + UInt32 ptr1 = (_cyclicBufferPos << 1); + + UInt32 len0, len1; + len0 = len1 = kNumHashDirectBytes; + + if (kNumHashDirectBytes != 0) + { + if (curMatch > matchMinPos) + { + if (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] != + _bufferBase[cur + kNumHashDirectBytes]) + { + distances[offset++] = maxLen = kNumHashDirectBytes; + distances[offset++] = _pos - curMatch - 1; + } + } + } + + UInt32 count = _cutValue; + + while(true) + { + if(curMatch <= matchMinPos || count-- == 0) + { + _son[ptr0] = _son[ptr1] = kEmptyHashValue; + break; + } + UInt32 delta = _pos - curMatch; + UInt32 cyclicPos = ((delta <= _cyclicBufferPos) ? + (_cyclicBufferPos - delta) : + (_cyclicBufferPos - delta + _cyclicBufferSize)) << 1; + + UInt32 pby1 = _bufferOffset + curMatch; + UInt32 len = Math.Min(len0, len1); + if (_bufferBase[pby1 + len] == _bufferBase[cur + len]) + { + while(++len != lenLimit) + if (_bufferBase[pby1 + len] != _bufferBase[cur + len]) + break; + if (maxLen < len) + { + distances[offset++] = maxLen = len; + distances[offset++] = delta - 1; + if (len == lenLimit) + { + _son[ptr1] = _son[cyclicPos]; + _son[ptr0] = _son[cyclicPos + 1]; + break; + } + } + } + if (_bufferBase[pby1 + len] < _bufferBase[cur + len]) + { + _son[ptr1] = curMatch; + ptr1 = cyclicPos + 1; + curMatch = _son[ptr1]; + len1 = len; + } + else + { + _son[ptr0] = curMatch; + ptr0 = cyclicPos; + curMatch = _son[ptr0]; + len0 = len; + } + } + MovePos(); + return offset; + } + + public void Skip(UInt32 num) + { + do + { + UInt32 lenLimit; + if (_pos + _matchMaxLen <= _streamPos) + lenLimit = _matchMaxLen; + else + { + lenLimit = _streamPos - _pos; + if (lenLimit < kMinMatchCheck) + { + MovePos(); + continue; + } + } + + UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; + UInt32 cur = _bufferOffset + _pos; + + UInt32 hashValue; + + if (HASH_ARRAY) + { + UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1]; + UInt32 hash2Value = temp & (kHash2Size - 1); + _hash[hash2Value] = _pos; + temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8); + UInt32 hash3Value = temp & (kHash3Size - 1); + _hash[kHash3Offset + hash3Value] = _pos; + hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask; + } + else + hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8); + + UInt32 curMatch = _hash[kFixHashSize + hashValue]; + _hash[kFixHashSize + hashValue] = _pos; + + UInt32 ptr0 = (_cyclicBufferPos << 1) + 1; + UInt32 ptr1 = (_cyclicBufferPos << 1); + + UInt32 len0, len1; + len0 = len1 = kNumHashDirectBytes; + + UInt32 count = _cutValue; + while (true) + { + if (curMatch <= matchMinPos || count-- == 0) + { + _son[ptr0] = _son[ptr1] = kEmptyHashValue; + break; + } + + UInt32 delta = _pos - curMatch; + UInt32 cyclicPos = ((delta <= _cyclicBufferPos) ? + (_cyclicBufferPos - delta) : + (_cyclicBufferPos - delta + _cyclicBufferSize)) << 1; + + UInt32 pby1 = _bufferOffset + curMatch; + UInt32 len = Math.Min(len0, len1); + if (_bufferBase[pby1 + len] == _bufferBase[cur + len]) + { + while (++len != lenLimit) + if (_bufferBase[pby1 + len] != _bufferBase[cur + len]) + break; + if (len == lenLimit) + { + _son[ptr1] = _son[cyclicPos]; + _son[ptr0] = _son[cyclicPos + 1]; + break; + } + } + if (_bufferBase[pby1 + len] < _bufferBase[cur + len]) + { + _son[ptr1] = curMatch; + ptr1 = cyclicPos + 1; + curMatch = _son[ptr1]; + len1 = len; + } + else + { + _son[ptr0] = curMatch; + ptr0 = cyclicPos; + curMatch = _son[ptr0]; + len0 = len; + } + } + MovePos(); + } + while (--num != 0); + } + + void NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue) + { + for (UInt32 i = 0; i < numItems; i++) + { + UInt32 value = items[i]; + if (value <= subValue) + value = kEmptyHashValue; + else + value -= subValue; + items[i] = value; + } + } + + void Normalize() + { + UInt32 subValue = _pos - _cyclicBufferSize; + NormalizeLinks(_son, _cyclicBufferSize * 2, subValue); + NormalizeLinks(_hash, _hashSizeSum, subValue); + ReduceOffsets((Int32)subValue); + } + + public void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs.meta new file mode 100644 index 0000000..d9f854a --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzBinTree.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1adea092391806b4ea76ac3e9b097d1a +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs new file mode 100644 index 0000000..52d23ce --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs @@ -0,0 +1,132 @@ +// LzInWindow.cs + +using System; + +namespace SevenZip.Compression.LZ +{ + public class InWindow + { + public Byte[] _bufferBase = null; // pointer to buffer with data + System.IO.Stream _stream; + UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done + bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream + + UInt32 _pointerToLastSafePosition; + + public UInt32 _bufferOffset; + + public UInt32 _blockSize; // Size of Allocated memory block + public UInt32 _pos; // offset (from _buffer) of curent byte + UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos + UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos + public UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream + + public void MoveBlock() + { + UInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore; + // we need one additional byte, since MovePos moves on 1 byte. + if (offset > 0) + offset--; + + UInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset; + + // check negative offset ???? + for (UInt32 i = 0; i < numBytes; i++) + _bufferBase[i] = _bufferBase[offset + i]; + _bufferOffset -= offset; + } + + public virtual void ReadBlock() + { + if (_streamEndWasReached) + return; + while (true) + { + int size = (int)((0 - _bufferOffset) + _blockSize - _streamPos); + if (size == 0) + return; + int numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size); + if (numReadBytes == 0) + { + _posLimit = _streamPos; + UInt32 pointerToPostion = _bufferOffset + _posLimit; + if (pointerToPostion > _pointerToLastSafePosition) + _posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset); + + _streamEndWasReached = true; + return; + } + _streamPos += (UInt32)numReadBytes; + if (_streamPos >= _pos + _keepSizeAfter) + _posLimit = _streamPos - _keepSizeAfter; + } + } + + void Free() { _bufferBase = null; } + + public void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv) + { + _keepSizeBefore = keepSizeBefore; + _keepSizeAfter = keepSizeAfter; + UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv; + if (_bufferBase == null || _blockSize != blockSize) + { + Free(); + _blockSize = blockSize; + _bufferBase = new Byte[_blockSize]; + } + _pointerToLastSafePosition = _blockSize - keepSizeAfter; + } + + public void SetStream(System.IO.Stream stream) { _stream = stream; } + public void ReleaseStream() { _stream = null; } + + public void Init() + { + _bufferOffset = 0; + _pos = 0; + _streamPos = 0; + _streamEndWasReached = false; + ReadBlock(); + } + + public void MovePos() + { + _pos++; + if (_pos > _posLimit) + { + UInt32 pointerToPostion = _bufferOffset + _pos; + if (pointerToPostion > _pointerToLastSafePosition) + MoveBlock(); + ReadBlock(); + } + } + + public Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; } + + // index + limit have not to exceed _keepSizeAfter; + public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) + { + if (_streamEndWasReached) + if ((_pos + index) + limit > _streamPos) + limit = _streamPos - (UInt32)(_pos + index); + distance++; + // Byte *pby = _buffer + (size_t)_pos + index; + UInt32 pby = _bufferOffset + _pos + (UInt32)index; + + UInt32 i; + for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++); + return i; + } + + public UInt32 GetNumAvailableBytes() { return _streamPos - _pos; } + + public void ReduceOffsets(Int32 subValue) + { + _bufferOffset += (UInt32)subValue; + _posLimit -= (UInt32)subValue; + _pos -= (UInt32)subValue; + _streamPos -= (UInt32)subValue; + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs.meta new file mode 100644 index 0000000..635f734 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzInWindow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6949cc430e3791941b28db4ce2a43f92 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs new file mode 100644 index 0000000..c998584 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs @@ -0,0 +1,110 @@ +// LzOutWindow.cs + +namespace SevenZip.Compression.LZ +{ + public class OutWindow + { + byte[] _buffer = null; + uint _pos; + uint _windowSize = 0; + uint _streamPos; + System.IO.Stream _stream; + + public uint TrainSize = 0; + + public void Create(uint windowSize) + { + if (_windowSize != windowSize) + { + // System.GC.Collect(); + _buffer = new byte[windowSize]; + } + _windowSize = windowSize; + _pos = 0; + _streamPos = 0; + } + + public void Init(System.IO.Stream stream, bool solid) + { + ReleaseStream(); + _stream = stream; + if (!solid) + { + _streamPos = 0; + _pos = 0; + TrainSize = 0; + } + } + + public bool Train(System.IO.Stream stream) + { + long len = stream.Length; + uint size = (len < _windowSize) ? (uint)len : _windowSize; + TrainSize = size; + stream.Position = len - size; + _streamPos = _pos = 0; + while (size > 0) + { + uint curSize = _windowSize - _pos; + if (size < curSize) + curSize = size; + int numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize); + if (numReadBytes == 0) + return false; + size -= (uint)numReadBytes; + _pos += (uint)numReadBytes; + _streamPos += (uint)numReadBytes; + if (_pos == _windowSize) + _streamPos = _pos = 0; + } + return true; + } + + public void ReleaseStream() + { + Flush(); + _stream = null; + } + + public void Flush() + { + uint size = _pos - _streamPos; + if (size == 0) + return; + _stream.Write(_buffer, (int)_streamPos, (int)size); + if (_pos >= _windowSize) + _pos = 0; + _streamPos = _pos; + } + + public void CopyBlock(uint distance, uint len) + { + uint pos = _pos - distance - 1; + if (pos >= _windowSize) + pos += _windowSize; + for (; len > 0; len--) + { + if (pos >= _windowSize) + pos = 0; + _buffer[_pos++] = _buffer[pos++]; + if (_pos >= _windowSize) + Flush(); + } + } + + public void PutByte(byte b) + { + _buffer[_pos++] = b; + if (_pos >= _windowSize) + Flush(); + } + + public byte GetByte(uint distance) + { + uint pos = _pos - distance - 1; + if (pos >= _windowSize) + pos += _windowSize; + return _buffer[pos]; + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs.meta new file mode 100644 index 0000000..b6f1f15 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZ/LzOutWindow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 050776325e14e274c96e6c64838698ae +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA.meta new file mode 100644 index 0000000..38dd753 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 129a5f22932e25343adaa6624e374d4b +folderAsset: yes +timeCreated: 1502467325 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs new file mode 100644 index 0000000..c7bca86 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs @@ -0,0 +1,76 @@ +// LzmaBase.cs + +namespace SevenZip.Compression.LZMA +{ + internal abstract class Base + { + public const uint kNumRepDistances = 4; + public const uint kNumStates = 12; + + // static byte []kLiteralNextStates = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; + // static byte []kMatchNextStates = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; + // static byte []kRepNextStates = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; + // static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; + + public struct State + { + public uint Index; + public void Init() { Index = 0; } + public void UpdateChar() + { + if (Index < 4) Index = 0; + else if (Index < 10) Index -= 3; + else Index -= 6; + } + public void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); } + public void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); } + public void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); } + public bool IsCharState() { return Index < 7; } + } + + public const int kNumPosSlotBits = 6; + public const int kDicLogSizeMin = 0; + // public const int kDicLogSizeMax = 30; + // public const uint kDistTableSizeMax = kDicLogSizeMax * 2; + + public const int kNumLenToPosStatesBits = 2; // it's for speed optimization + public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits; + + public const uint kMatchMinLen = 2; + + public static uint GetLenToPosState(uint len) + { + len -= kMatchMinLen; + if (len < kNumLenToPosStates) + return len; + return (uint)(kNumLenToPosStates - 1); + } + + public const int kNumAlignBits = 4; + public const uint kAlignTableSize = 1 << kNumAlignBits; + public const uint kAlignMask = (kAlignTableSize - 1); + + public const uint kStartPosModelIndex = 4; + public const uint kEndPosModelIndex = 14; + public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; + + public const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2); + + public const uint kNumLitPosStatesBitsEncodingMax = 4; + public const uint kNumLitContextBitsMax = 8; + + public const int kNumPosStatesBitsMax = 4; + public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax); + public const int kNumPosStatesBitsEncodingMax = 4; + public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); + + public const int kNumLowLenBits = 3; + public const int kNumMidLenBits = 3; + public const int kNumHighLenBits = 8; + public const uint kNumLowLenSymbols = 1 << kNumLowLenBits; + public const uint kNumMidLenSymbols = 1 << kNumMidLenBits; + public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + + (1 << kNumHighLenBits); + public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs.meta new file mode 100644 index 0000000..e13ec44 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaBase.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2494e83b2a12e4f44b5353018b98c0ed +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs new file mode 100644 index 0000000..a9be39f --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs @@ -0,0 +1,398 @@ +// LzmaDecoder.cs + +using System; + +namespace SevenZip.Compression.LZMA +{ + using RangeCoder; + + public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream + { + class LenDecoder + { + BitDecoder m_Choice = new BitDecoder(); + BitDecoder m_Choice2 = new BitDecoder(); + BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; + BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax]; + BitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits); + uint m_NumPosStates = 0; + + public void Create(uint numPosStates) + { + for (uint posState = m_NumPosStates; posState < numPosStates; posState++) + { + m_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits); + m_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits); + } + m_NumPosStates = numPosStates; + } + + public void Init() + { + m_Choice.Init(); + for (uint posState = 0; posState < m_NumPosStates; posState++) + { + m_LowCoder[posState].Init(); + m_MidCoder[posState].Init(); + } + m_Choice2.Init(); + m_HighCoder.Init(); + } + + public uint Decode(RangeCoder.Decoder rangeDecoder, uint posState) + { + if (m_Choice.Decode(rangeDecoder) == 0) + return m_LowCoder[posState].Decode(rangeDecoder); + else + { + uint symbol = Base.kNumLowLenSymbols; + if (m_Choice2.Decode(rangeDecoder) == 0) + symbol += m_MidCoder[posState].Decode(rangeDecoder); + else + { + symbol += Base.kNumMidLenSymbols; + symbol += m_HighCoder.Decode(rangeDecoder); + } + return symbol; + } + } + } + + class LiteralDecoder + { + struct Decoder2 + { + BitDecoder[] m_Decoders; + public void Create() { m_Decoders = new BitDecoder[0x300]; } + public void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); } + + public byte DecodeNormal(RangeCoder.Decoder rangeDecoder) + { + uint symbol = 1; + do + symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder); + while (symbol < 0x100); + return (byte)symbol; + } + + public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte) + { + uint symbol = 1; + do + { + uint matchBit = (uint)(matchByte >> 7) & 1; + matchByte <<= 1; + uint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder); + symbol = (symbol << 1) | bit; + if (matchBit != bit) + { + while (symbol < 0x100) + symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder); + break; + } + } + while (symbol < 0x100); + return (byte)symbol; + } + } + + Decoder2[] m_Coders; + int m_NumPrevBits; + int m_NumPosBits; + uint m_PosMask; + + public void Create(int numPosBits, int numPrevBits) + { + if (m_Coders != null && m_NumPrevBits == numPrevBits && + m_NumPosBits == numPosBits) + return; + m_NumPosBits = numPosBits; + m_PosMask = ((uint)1 << numPosBits) - 1; + m_NumPrevBits = numPrevBits; + uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + m_Coders = new Decoder2[numStates]; + for (uint i = 0; i < numStates; i++) + m_Coders[i].Create(); + } + + public void Init() + { + uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + for (uint i = 0; i < numStates; i++) + m_Coders[i].Init(); + } + + uint GetState(uint pos, byte prevByte) + { return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); } + + public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte) + { return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); } + + public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte) + { return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); } + }; + + LZ.OutWindow m_OutWindow = new LZ.OutWindow(); + RangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder(); + + BitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates]; + BitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates]; + BitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates]; + BitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates]; + BitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + + BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates]; + BitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex]; + + BitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits); + + LenDecoder m_LenDecoder = new LenDecoder(); + LenDecoder m_RepLenDecoder = new LenDecoder(); + + LiteralDecoder m_LiteralDecoder = new LiteralDecoder(); + + uint m_DictionarySize; + uint m_DictionarySizeCheck; + + uint m_PosStateMask; + + public Decoder() + { + m_DictionarySize = 0xFFFFFFFF; + for (int i = 0; i < Base.kNumLenToPosStates; i++) + m_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits); + } + + void SetDictionarySize(uint dictionarySize) + { + if (m_DictionarySize != dictionarySize) + { + m_DictionarySize = dictionarySize; + m_DictionarySizeCheck = Math.Max(m_DictionarySize, 1); + uint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12)); + m_OutWindow.Create(blockSize); + } + } + + void SetLiteralProperties(int lp, int lc) + { + if (lp > 8) + throw new InvalidParamException(); + if (lc > 8) + throw new InvalidParamException(); + m_LiteralDecoder.Create(lp, lc); + } + + void SetPosBitsProperties(int pb) + { + if (pb > Base.kNumPosStatesBitsMax) + throw new InvalidParamException(); + uint numPosStates = (uint)1 << pb; + m_LenDecoder.Create(numPosStates); + m_RepLenDecoder.Create(numPosStates); + m_PosStateMask = numPosStates - 1; + } + + bool _solid = false; + void Init(System.IO.Stream inStream, System.IO.Stream outStream) + { + m_RangeDecoder.Init(inStream); + m_OutWindow.Init(outStream, _solid); + + uint i; + for (i = 0; i < Base.kNumStates; i++) + { + for (uint j = 0; j <= m_PosStateMask; j++) + { + uint index = (i << Base.kNumPosStatesBitsMax) + j; + m_IsMatchDecoders[index].Init(); + m_IsRep0LongDecoders[index].Init(); + } + m_IsRepDecoders[i].Init(); + m_IsRepG0Decoders[i].Init(); + m_IsRepG1Decoders[i].Init(); + m_IsRepG2Decoders[i].Init(); + } + + m_LiteralDecoder.Init(); + for (i = 0; i < Base.kNumLenToPosStates; i++) + m_PosSlotDecoder[i].Init(); + // m_PosSpecDecoder.Init(); + for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++) + m_PosDecoders[i].Init(); + + m_LenDecoder.Init(); + m_RepLenDecoder.Init(); + m_PosAlignDecoder.Init(); + } + + public void Code(System.IO.Stream inStream, System.IO.Stream outStream, + Int64 inSize, Int64 outSize, ICodeProgress progress) + { + Init(inStream, outStream); + + Base.State state = new Base.State(); + state.Init(); + uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; + + UInt64 nowPos64 = 0; + UInt64 outSize64 = (UInt64)outSize; + if (nowPos64 < outSize64) + { + if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0) + throw new DataErrorException(); + state.UpdateChar(); + byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0); + m_OutWindow.PutByte(b); + nowPos64++; + } + while (nowPos64 < outSize64) + { + // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); + // while(nowPos64 < next) + { + uint posState = (uint)nowPos64 & m_PosStateMask; + if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) + { + byte b; + byte prevByte = m_OutWindow.GetByte(0); + if (!state.IsCharState()) + b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, + (uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0)); + else + b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte); + m_OutWindow.PutByte(b); + state.UpdateChar(); + nowPos64++; + } + else + { + uint len; + if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) + { + if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) + { + if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) + { + state.UpdateShortRep(); + m_OutWindow.PutByte(m_OutWindow.GetByte(rep0)); + nowPos64++; + continue; + } + } + else + { + UInt32 distance; + if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) + { + distance = rep1; + } + else + { + if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) + distance = rep2; + else + { + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen; + state.UpdateRep(); + } + else + { + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + len = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState); + state.UpdateMatch(); + uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder); + if (posSlot >= Base.kStartPosModelIndex) + { + int numDirectBits = (int)((posSlot >> 1) - 1); + rep0 = ((2 | (posSlot & 1)) << numDirectBits); + if (posSlot < Base.kEndPosModelIndex) + rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders, + rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); + else + { + rep0 += (m_RangeDecoder.DecodeDirectBits( + numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits); + rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); + } + } + else + rep0 = posSlot; + } + if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck) + { + if (rep0 == 0xFFFFFFFF) + break; + throw new DataErrorException(); + } + m_OutWindow.CopyBlock(rep0, len); + nowPos64 += len; + } + } + } + m_OutWindow.Flush(); + m_OutWindow.ReleaseStream(); + m_RangeDecoder.ReleaseStream(); + } + + public void SetDecoderProperties(byte[] properties) + { + if (properties.Length < 5) + throw new InvalidParamException(); + int lc = properties[0] % 9; + int remainder = properties[0] / 9; + int lp = remainder % 5; + int pb = remainder / 5; + if (pb > Base.kNumPosStatesBitsMax) + throw new InvalidParamException(); + UInt32 dictionarySize = 0; + for (int i = 0; i < 4; i++) + dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8); + SetDictionarySize(dictionarySize); + SetLiteralProperties(lp, lc); + SetPosBitsProperties(pb); + } + + public bool Train(System.IO.Stream stream) + { + _solid = true; + return m_OutWindow.Train(stream); + } + + /* + public override bool CanRead { get { return true; }} + public override bool CanWrite { get { return true; }} + public override bool CanSeek { get { return true; }} + public override long Length { get { return 0; }} + public override long Position + { + get { return 0; } + set { } + } + public override void Flush() { } + public override int Read(byte[] buffer, int offset, int count) + { + return 0; + } + public override void Write(byte[] buffer, int offset, int count) + { + } + public override long Seek(long offset, System.IO.SeekOrigin origin) + { + return 0; + } + public override void SetLength(long value) {} + */ + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs.meta new file mode 100644 index 0000000..bfca2bd --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaDecoder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 005072d71b7975544822012d673139ee +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs new file mode 100644 index 0000000..0237c51 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs @@ -0,0 +1,1480 @@ +// LzmaEncoder.cs + +using System; + +namespace SevenZip.Compression.LZMA +{ + using RangeCoder; + + public class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties + { + enum EMatchFinderType + { + BT2, + BT4, + }; + + const UInt32 kIfinityPrice = 0xFFFFFFF; + + static Byte[] g_FastPos = new Byte[1 << 11]; + + static Encoder() + { + const Byte kFastSlots = 22; + int c = 2; + g_FastPos[0] = 0; + g_FastPos[1] = 1; + for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++) + { + UInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1)); + for (UInt32 j = 0; j < k; j++, c++) + g_FastPos[c] = slotFast; + } + } + + static UInt32 GetPosSlot(UInt32 pos) + { + if (pos < (1 << 11)) + return g_FastPos[pos]; + if (pos < (1 << 21)) + return (UInt32)(g_FastPos[pos >> 10] + 20); + return (UInt32)(g_FastPos[pos >> 20] + 40); + } + + static UInt32 GetPosSlot2(UInt32 pos) + { + if (pos < (1 << 17)) + return (UInt32)(g_FastPos[pos >> 6] + 12); + if (pos < (1 << 27)) + return (UInt32)(g_FastPos[pos >> 16] + 32); + return (UInt32)(g_FastPos[pos >> 26] + 52); + } + + Base.State _state = new Base.State(); + Byte _previousByte; + UInt32[] _repDistances = new UInt32[Base.kNumRepDistances]; + + void BaseInit() + { + _state.Init(); + _previousByte = 0; + for (UInt32 i = 0; i < Base.kNumRepDistances; i++) + _repDistances[i] = 0; + } + + const int kDefaultDictionaryLogSize = 22; + const UInt32 kNumFastBytesDefault = 0x20; + + class LiteralEncoder + { + public struct Encoder2 + { + BitEncoder[] m_Encoders; + + public void Create() { m_Encoders = new BitEncoder[0x300]; } + + public void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); } + + public void Encode(RangeCoder.Encoder rangeEncoder, byte symbol) + { + uint context = 1; + for (int i = 7; i >= 0; i--) + { + uint bit = (uint)((symbol >> i) & 1); + m_Encoders[context].Encode(rangeEncoder, bit); + context = (context << 1) | bit; + } + } + + public void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) + { + uint context = 1; + bool same = true; + for (int i = 7; i >= 0; i--) + { + uint bit = (uint)((symbol >> i) & 1); + uint state = context; + if (same) + { + uint matchBit = (uint)((matchByte >> i) & 1); + state += ((1 + matchBit) << 8); + same = (matchBit == bit); + } + m_Encoders[state].Encode(rangeEncoder, bit); + context = (context << 1) | bit; + } + } + + public uint GetPrice(bool matchMode, byte matchByte, byte symbol) + { + uint price = 0; + uint context = 1; + int i = 7; + if (matchMode) + { + for (; i >= 0; i--) + { + uint matchBit = (uint)(matchByte >> i) & 1; + uint bit = (uint)(symbol >> i) & 1; + price += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit); + context = (context << 1) | bit; + if (matchBit != bit) + { + i--; + break; + } + } + } + for (; i >= 0; i--) + { + uint bit = (uint)(symbol >> i) & 1; + price += m_Encoders[context].GetPrice(bit); + context = (context << 1) | bit; + } + return price; + } + } + + Encoder2[] m_Coders; + int m_NumPrevBits; + int m_NumPosBits; + uint m_PosMask; + + public void Create(int numPosBits, int numPrevBits) + { + if (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits) + return; + m_NumPosBits = numPosBits; + m_PosMask = ((uint)1 << numPosBits) - 1; + m_NumPrevBits = numPrevBits; + uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + m_Coders = new Encoder2[numStates]; + for (uint i = 0; i < numStates; i++) + m_Coders[i].Create(); + } + + public void Init() + { + uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits); + for (uint i = 0; i < numStates; i++) + m_Coders[i].Init(); + } + + public Encoder2 GetSubCoder(UInt32 pos, Byte prevByte) + { return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; } + } + + class LenEncoder + { + RangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder(); + RangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder(); + RangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; + RangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; + RangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits); + + public LenEncoder() + { + for (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++) + { + _lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits); + _midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits); + } + } + + public void Init(UInt32 numPosStates) + { + _choice.Init(); + _choice2.Init(); + for (UInt32 posState = 0; posState < numPosStates; posState++) + { + _lowCoder[posState].Init(); + _midCoder[posState].Init(); + } + _highCoder.Init(); + } + + public void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState) + { + if (symbol < Base.kNumLowLenSymbols) + { + _choice.Encode(rangeEncoder, 0); + _lowCoder[posState].Encode(rangeEncoder, symbol); + } + else + { + symbol -= Base.kNumLowLenSymbols; + _choice.Encode(rangeEncoder, 1); + if (symbol < Base.kNumMidLenSymbols) + { + _choice2.Encode(rangeEncoder, 0); + _midCoder[posState].Encode(rangeEncoder, symbol); + } + else + { + _choice2.Encode(rangeEncoder, 1); + _highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols); + } + } + } + + public void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st) + { + UInt32 a0 = _choice.GetPrice0(); + UInt32 a1 = _choice.GetPrice1(); + UInt32 b0 = a1 + _choice2.GetPrice0(); + UInt32 b1 = a1 + _choice2.GetPrice1(); + UInt32 i = 0; + for (i = 0; i < Base.kNumLowLenSymbols; i++) + { + if (i >= numSymbols) + return; + prices[st + i] = a0 + _lowCoder[posState].GetPrice(i); + } + for (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++) + { + if (i >= numSymbols) + return; + prices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols); + } + for (; i < numSymbols; i++) + prices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols); + } + }; + + const UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; + + class LenPriceTableEncoder : LenEncoder + { + UInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax]; + UInt32 _tableSize; + UInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax]; + + public void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; } + + public UInt32 GetPrice(UInt32 symbol, UInt32 posState) + { + return _prices[posState * Base.kNumLenSymbols + symbol]; + } + + void UpdateTable(UInt32 posState) + { + SetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols); + _counters[posState] = _tableSize; + } + + public void UpdateTables(UInt32 numPosStates) + { + for (UInt32 posState = 0; posState < numPosStates; posState++) + UpdateTable(posState); + } + + public new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState) + { + base.Encode(rangeEncoder, symbol, posState); + if (--_counters[posState] == 0) + UpdateTable(posState); + } + } + + const UInt32 kNumOpts = 1 << 12; + class Optimal + { + public Base.State State; + + public bool Prev1IsChar; + public bool Prev2; + + public UInt32 PosPrev2; + public UInt32 BackPrev2; + + public UInt32 Price; + public UInt32 PosPrev; + public UInt32 BackPrev; + + public UInt32 Backs0; + public UInt32 Backs1; + public UInt32 Backs2; + public UInt32 Backs3; + + public void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; } + public void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; } + public bool IsShortRep() { return (BackPrev == 0); } + }; + Optimal[] _optimum = new Optimal[kNumOpts]; + LZ.IMatchFinder _matchFinder = null; + RangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder(); + + RangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + RangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates]; + RangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates]; + RangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates]; + RangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates]; + RangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax]; + + RangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates]; + + RangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex]; + RangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits); + + LenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder(); + LenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder(); + + LiteralEncoder _literalEncoder = new LiteralEncoder(); + + UInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2]; + + UInt32 _numFastBytes = kNumFastBytesDefault; + UInt32 _longestMatchLength; + UInt32 _numDistancePairs; + + UInt32 _additionalOffset; + + UInt32 _optimumEndIndex; + UInt32 _optimumCurrentIndex; + + bool _longestMatchWasFound; + + UInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)]; + UInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits]; + UInt32[] _alignPrices = new UInt32[Base.kAlignTableSize]; + UInt32 _alignPriceCount; + + UInt32 _distTableSize = (kDefaultDictionaryLogSize * 2); + + int _posStateBits = 2; + UInt32 _posStateMask = (4 - 1); + int _numLiteralPosStateBits = 0; + int _numLiteralContextBits = 3; + + UInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize); + UInt32 _dictionarySizePrev = 0xFFFFFFFF; + UInt32 _numFastBytesPrev = 0xFFFFFFFF; + + Int64 nowPos64; + bool _finished; + System.IO.Stream _inStream; + + EMatchFinderType _matchFinderType = EMatchFinderType.BT4; + bool _writeEndMark = false; + + bool _needReleaseMFStream; + + void Create() + { + if (_matchFinder == null) + { + LZ.BinTree bt = new LZ.BinTree(); + int numHashBytes = 4; + if (_matchFinderType == EMatchFinderType.BT2) + numHashBytes = 2; + bt.SetType(numHashBytes); + _matchFinder = bt; + } + _literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits); + + if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes) + return; + _matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1); + _dictionarySizePrev = _dictionarySize; + _numFastBytesPrev = _numFastBytes; + } + + public Encoder() + { + for (int i = 0; i < kNumOpts; i++) + _optimum[i] = new Optimal(); + for (int i = 0; i < Base.kNumLenToPosStates; i++) + _posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits); + } + + void SetWriteEndMarkerMode(bool writeEndMarker) + { + _writeEndMark = writeEndMarker; + } + + void Init() + { + BaseInit(); + _rangeEncoder.Init(); + + uint i; + for (i = 0; i < Base.kNumStates; i++) + { + for (uint j = 0; j <= _posStateMask; j++) + { + uint complexState = (i << Base.kNumPosStatesBitsMax) + j; + _isMatch[complexState].Init(); + _isRep0Long[complexState].Init(); + } + _isRep[i].Init(); + _isRepG0[i].Init(); + _isRepG1[i].Init(); + _isRepG2[i].Init(); + } + _literalEncoder.Init(); + for (i = 0; i < Base.kNumLenToPosStates; i++) + _posSlotEncoder[i].Init(); + for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++) + _posEncoders[i].Init(); + + _lenEncoder.Init((UInt32)1 << _posStateBits); + _repMatchLenEncoder.Init((UInt32)1 << _posStateBits); + + _posAlignEncoder.Init(); + + _longestMatchWasFound = false; + _optimumEndIndex = 0; + _optimumCurrentIndex = 0; + _additionalOffset = 0; + } + + void ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs) + { + lenRes = 0; + numDistancePairs = _matchFinder.GetMatches(_matchDistances); + if (numDistancePairs > 0) + { + lenRes = _matchDistances[numDistancePairs - 2]; + if (lenRes == _numFastBytes) + lenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1], + Base.kMatchMaxLen - lenRes); + } + _additionalOffset++; + } + + + void MovePos(UInt32 num) + { + if (num > 0) + { + _matchFinder.Skip(num); + _additionalOffset += num; + } + } + + UInt32 GetRepLen1Price(Base.State state, UInt32 posState) + { + return _isRepG0[state.Index].GetPrice0() + + _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0(); + } + + UInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState) + { + UInt32 price; + if (repIndex == 0) + { + price = _isRepG0[state.Index].GetPrice0(); + price += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1(); + } + else + { + price = _isRepG0[state.Index].GetPrice1(); + if (repIndex == 1) + price += _isRepG1[state.Index].GetPrice0(); + else + { + price += _isRepG1[state.Index].GetPrice1(); + price += _isRepG2[state.Index].GetPrice(repIndex - 2); + } + } + return price; + } + + UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState) + { + UInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState); + return price + GetPureRepPrice(repIndex, state, posState); + } + + UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) + { + UInt32 price; + UInt32 lenToPosState = Base.GetLenToPosState(len); + if (pos < Base.kNumFullDistances) + price = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos]; + else + price = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] + + _alignPrices[pos & Base.kAlignMask]; + return price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState); + } + + UInt32 Backward(out UInt32 backRes, UInt32 cur) + { + _optimumEndIndex = cur; + UInt32 posMem = _optimum[cur].PosPrev; + UInt32 backMem = _optimum[cur].BackPrev; + do + { + if (_optimum[cur].Prev1IsChar) + { + _optimum[posMem].MakeAsChar(); + _optimum[posMem].PosPrev = posMem - 1; + if (_optimum[cur].Prev2) + { + _optimum[posMem - 1].Prev1IsChar = false; + _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2; + _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2; + } + } + UInt32 posPrev = posMem; + UInt32 backCur = backMem; + + backMem = _optimum[posPrev].BackPrev; + posMem = _optimum[posPrev].PosPrev; + + _optimum[posPrev].BackPrev = backCur; + _optimum[posPrev].PosPrev = cur; + cur = posPrev; + } + while (cur > 0); + backRes = _optimum[0].BackPrev; + _optimumCurrentIndex = _optimum[0].PosPrev; + return _optimumCurrentIndex; + } + + UInt32[] reps = new UInt32[Base.kNumRepDistances]; + UInt32[] repLens = new UInt32[Base.kNumRepDistances]; + + + UInt32 GetOptimum(UInt32 position, out UInt32 backRes) + { + if (_optimumEndIndex != _optimumCurrentIndex) + { + UInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex; + backRes = _optimum[_optimumCurrentIndex].BackPrev; + _optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev; + return lenRes; + } + _optimumCurrentIndex = _optimumEndIndex = 0; + + UInt32 lenMain, numDistancePairs; + if (!_longestMatchWasFound) + { + ReadMatchDistances(out lenMain, out numDistancePairs); + } + else + { + lenMain = _longestMatchLength; + numDistancePairs = _numDistancePairs; + _longestMatchWasFound = false; + } + + UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1; + if (numAvailableBytes < 2) + { + backRes = 0xFFFFFFFF; + return 1; + } + if (numAvailableBytes > Base.kMatchMaxLen) + numAvailableBytes = Base.kMatchMaxLen; + + UInt32 repMaxIndex = 0; + UInt32 i; + for (i = 0; i < Base.kNumRepDistances; i++) + { + reps[i] = _repDistances[i]; + repLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen); + if (repLens[i] > repLens[repMaxIndex]) + repMaxIndex = i; + } + if (repLens[repMaxIndex] >= _numFastBytes) + { + backRes = repMaxIndex; + UInt32 lenRes = repLens[repMaxIndex]; + MovePos(lenRes - 1); + return lenRes; + } + + if (lenMain >= _numFastBytes) + { + backRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances; + MovePos(lenMain - 1); + return lenMain; + } + + Byte currentByte = _matchFinder.GetIndexByte(0 - 1); + Byte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1)); + + if (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2) + { + backRes = (UInt32)0xFFFFFFFF; + return 1; + } + + _optimum[0].State = _state; + + UInt32 posState = (position & _posStateMask); + + _optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() + + _literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte); + _optimum[1].MakeAsChar(); + + UInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1(); + UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1(); + + if (matchByte == currentByte) + { + UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState); + if (shortRepPrice < _optimum[1].Price) + { + _optimum[1].Price = shortRepPrice; + _optimum[1].MakeAsShortRep(); + } + } + + UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]); + + if(lenEnd < 2) + { + backRes = _optimum[1].BackPrev; + return 1; + } + + _optimum[1].PosPrev = 0; + + _optimum[0].Backs0 = reps[0]; + _optimum[0].Backs1 = reps[1]; + _optimum[0].Backs2 = reps[2]; + _optimum[0].Backs3 = reps[3]; + + UInt32 len = lenEnd; + do + _optimum[len--].Price = kIfinityPrice; + while (len >= 2); + + for (i = 0; i < Base.kNumRepDistances; i++) + { + UInt32 repLen = repLens[i]; + if (repLen < 2) + continue; + UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState); + do + { + UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); + Optimal optimum = _optimum[repLen]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = 0; + optimum.BackPrev = i; + optimum.Prev1IsChar = false; + } + } + while (--repLen >= 2); + } + + UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0(); + + len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2); + if (len <= lenMain) + { + UInt32 offs = 0; + while (len > _matchDistances[offs]) + offs += 2; + for (; ; len++) + { + UInt32 distance = _matchDistances[offs + 1]; + UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState); + Optimal optimum = _optimum[len]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = 0; + optimum.BackPrev = distance + Base.kNumRepDistances; + optimum.Prev1IsChar = false; + } + if (len == _matchDistances[offs]) + { + offs += 2; + if (offs == numDistancePairs) + break; + } + } + } + + UInt32 cur = 0; + + while (true) + { + cur++; + if (cur == lenEnd) + return Backward(out backRes, cur); + UInt32 newLen; + ReadMatchDistances(out newLen, out numDistancePairs); + if (newLen >= _numFastBytes) + { + _numDistancePairs = numDistancePairs; + _longestMatchLength = newLen; + _longestMatchWasFound = true; + return Backward(out backRes, cur); + } + position++; + UInt32 posPrev = _optimum[cur].PosPrev; + Base.State state; + if (_optimum[cur].Prev1IsChar) + { + posPrev--; + if (_optimum[cur].Prev2) + { + state = _optimum[_optimum[cur].PosPrev2].State; + if (_optimum[cur].BackPrev2 < Base.kNumRepDistances) + state.UpdateRep(); + else + state.UpdateMatch(); + } + else + state = _optimum[posPrev].State; + state.UpdateChar(); + } + else + state = _optimum[posPrev].State; + if (posPrev == cur - 1) + { + if (_optimum[cur].IsShortRep()) + state.UpdateShortRep(); + else + state.UpdateChar(); + } + else + { + UInt32 pos; + if (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2) + { + posPrev = _optimum[cur].PosPrev2; + pos = _optimum[cur].BackPrev2; + state.UpdateRep(); + } + else + { + pos = _optimum[cur].BackPrev; + if (pos < Base.kNumRepDistances) + state.UpdateRep(); + else + state.UpdateMatch(); + } + Optimal opt = _optimum[posPrev]; + if (pos < Base.kNumRepDistances) + { + if (pos == 0) + { + reps[0] = opt.Backs0; + reps[1] = opt.Backs1; + reps[2] = opt.Backs2; + reps[3] = opt.Backs3; + } + else if (pos == 1) + { + reps[0] = opt.Backs1; + reps[1] = opt.Backs0; + reps[2] = opt.Backs2; + reps[3] = opt.Backs3; + } + else if (pos == 2) + { + reps[0] = opt.Backs2; + reps[1] = opt.Backs0; + reps[2] = opt.Backs1; + reps[3] = opt.Backs3; + } + else + { + reps[0] = opt.Backs3; + reps[1] = opt.Backs0; + reps[2] = opt.Backs1; + reps[3] = opt.Backs2; + } + } + else + { + reps[0] = (pos - Base.kNumRepDistances); + reps[1] = opt.Backs0; + reps[2] = opt.Backs1; + reps[3] = opt.Backs2; + } + } + _optimum[cur].State = state; + _optimum[cur].Backs0 = reps[0]; + _optimum[cur].Backs1 = reps[1]; + _optimum[cur].Backs2 = reps[2]; + _optimum[cur].Backs3 = reps[3]; + UInt32 curPrice = _optimum[cur].Price; + + currentByte = _matchFinder.GetIndexByte(0 - 1); + matchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1)); + + posState = (position & _posStateMask); + + UInt32 curAnd1Price = curPrice + + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() + + _literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)). + GetPrice(!state.IsCharState(), matchByte, currentByte); + + Optimal nextOptimum = _optimum[cur + 1]; + + bool nextIsChar = false; + if (curAnd1Price < nextOptimum.Price) + { + nextOptimum.Price = curAnd1Price; + nextOptimum.PosPrev = cur; + nextOptimum.MakeAsChar(); + nextIsChar = true; + } + + matchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1(); + repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1(); + + if (matchByte == currentByte && + !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0)) + { + UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState); + if (shortRepPrice <= nextOptimum.Price) + { + nextOptimum.Price = shortRepPrice; + nextOptimum.PosPrev = cur; + nextOptimum.MakeAsShortRep(); + nextIsChar = true; + } + } + + UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1; + numAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull); + numAvailableBytes = numAvailableBytesFull; + + if (numAvailableBytes < 2) + continue; + if (numAvailableBytes > _numFastBytes) + numAvailableBytes = _numFastBytes; + if (!nextIsChar && matchByte != currentByte) + { + // try Literal + rep0 + UInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes); + UInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t); + if (lenTest2 >= 2) + { + Base.State state2 = state; + state2.UpdateChar(); + UInt32 posStateNext = (position + 1) & _posStateMask; + UInt32 nextRepMatchPrice = curAnd1Price + + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() + + _isRep[state2.Index].GetPrice1(); + { + UInt32 offset = cur + 1 + lenTest2; + while (lenEnd < offset) + _optimum[++lenEnd].Price = kIfinityPrice; + UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice( + 0, lenTest2, state2, posStateNext); + Optimal optimum = _optimum[offset]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = cur + 1; + optimum.BackPrev = 0; + optimum.Prev1IsChar = true; + optimum.Prev2 = false; + } + } + } + } + + UInt32 startLen = 2; // speed optimization + + for (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++) + { + UInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes); + if (lenTest < 2) + continue; + UInt32 lenTestTemp = lenTest; + do + { + while (lenEnd < cur + lenTest) + _optimum[++lenEnd].Price = kIfinityPrice; + UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState); + Optimal optimum = _optimum[cur + lenTest]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = cur; + optimum.BackPrev = repIndex; + optimum.Prev1IsChar = false; + } + } + while(--lenTest >= 2); + lenTest = lenTestTemp; + + if (repIndex == 0) + startLen = lenTest + 1; + + // if (_maxMode) + if (lenTest < numAvailableBytesFull) + { + UInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); + UInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t); + if (lenTest2 >= 2) + { + Base.State state2 = state; + state2.UpdateRep(); + UInt32 posStateNext = (position + lenTest) & _posStateMask; + UInt32 curAndLenCharPrice = + repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() + + _literalEncoder.GetSubCoder(position + lenTest, + _matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true, + _matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), + _matchFinder.GetIndexByte((Int32)lenTest - 1)); + state2.UpdateChar(); + posStateNext = (position + lenTest + 1) & _posStateMask; + UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1(); + UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1(); + + // for(; lenTest2 >= 2; lenTest2--) + { + UInt32 offset = lenTest + 1 + lenTest2; + while(lenEnd < cur + offset) + _optimum[++lenEnd].Price = kIfinityPrice; + UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); + Optimal optimum = _optimum[cur + offset]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = cur + lenTest + 1; + optimum.BackPrev = 0; + optimum.Prev1IsChar = true; + optimum.Prev2 = true; + optimum.PosPrev2 = cur; + optimum.BackPrev2 = repIndex; + } + } + } + } + } + + if (newLen > numAvailableBytes) + { + newLen = numAvailableBytes; + for (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ; + _matchDistances[numDistancePairs] = newLen; + numDistancePairs += 2; + } + if (newLen >= startLen) + { + normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0(); + while (lenEnd < cur + newLen) + _optimum[++lenEnd].Price = kIfinityPrice; + + UInt32 offs = 0; + while (startLen > _matchDistances[offs]) + offs += 2; + + for (UInt32 lenTest = startLen; ; lenTest++) + { + UInt32 curBack = _matchDistances[offs + 1]; + UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState); + Optimal optimum = _optimum[cur + lenTest]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = cur; + optimum.BackPrev = curBack + Base.kNumRepDistances; + optimum.Prev1IsChar = false; + } + + if (lenTest == _matchDistances[offs]) + { + if (lenTest < numAvailableBytesFull) + { + UInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); + UInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t); + if (lenTest2 >= 2) + { + Base.State state2 = state; + state2.UpdateMatch(); + UInt32 posStateNext = (position + lenTest) & _posStateMask; + UInt32 curAndLenCharPrice = curAndLenPrice + + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() + + _literalEncoder.GetSubCoder(position + lenTest, + _matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)). + GetPrice(true, + _matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1), + _matchFinder.GetIndexByte((Int32)lenTest - 1)); + state2.UpdateChar(); + posStateNext = (position + lenTest + 1) & _posStateMask; + UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1(); + UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1(); + + UInt32 offset = lenTest + 1 + lenTest2; + while (lenEnd < cur + offset) + _optimum[++lenEnd].Price = kIfinityPrice; + curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); + optimum = _optimum[cur + offset]; + if (curAndLenPrice < optimum.Price) + { + optimum.Price = curAndLenPrice; + optimum.PosPrev = cur + lenTest + 1; + optimum.BackPrev = 0; + optimum.Prev1IsChar = true; + optimum.Prev2 = true; + optimum.PosPrev2 = cur; + optimum.BackPrev2 = curBack + Base.kNumRepDistances; + } + } + } + offs += 2; + if (offs == numDistancePairs) + break; + } + } + } + } + } + + bool ChangePair(UInt32 smallDist, UInt32 bigDist) + { + const int kDif = 7; + return (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif)); + } + + void WriteEndMarker(UInt32 posState) + { + if (!_writeEndMark) + return; + + _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1); + _isRep[_state.Index].Encode(_rangeEncoder, 0); + _state.UpdateMatch(); + UInt32 len = Base.kMatchMinLen; + _lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState); + UInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1; + UInt32 lenToPosState = Base.GetLenToPosState(len); + _posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot); + int footerBits = 30; + UInt32 posReduced = (((UInt32)1) << footerBits) - 1; + _rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits); + _posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask); + } + + void Flush(UInt32 nowPos) + { + ReleaseMFStream(); + WriteEndMarker(nowPos & _posStateMask); + _rangeEncoder.FlushData(); + _rangeEncoder.FlushStream(); + } + + public void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished) + { + inSize = 0; + outSize = 0; + finished = true; + + if (_inStream != null) + { + _matchFinder.SetStream(_inStream); + _matchFinder.Init(); + _needReleaseMFStream = true; + _inStream = null; + if (_trainSize > 0) + _matchFinder.Skip(_trainSize); + } + + if (_finished) + return; + _finished = true; + + + Int64 progressPosValuePrev = nowPos64; + if (nowPos64 == 0) + { + if (_matchFinder.GetNumAvailableBytes() == 0) + { + Flush((UInt32)nowPos64); + return; + } + UInt32 len, numDistancePairs; // it's not used + ReadMatchDistances(out len, out numDistancePairs); + UInt32 posState = (UInt32)(nowPos64) & _posStateMask; + _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0); + _state.UpdateChar(); + Byte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset)); + _literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte); + _previousByte = curByte; + _additionalOffset--; + nowPos64++; + } + if (_matchFinder.GetNumAvailableBytes() == 0) + { + Flush((UInt32)nowPos64); + return; + } + while (true) + { + UInt32 pos; + UInt32 len = GetOptimum((UInt32)nowPos64, out pos); + + UInt32 posState = ((UInt32)nowPos64) & _posStateMask; + UInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState; + if (len == 1 && pos == 0xFFFFFFFF) + { + _isMatch[complexState].Encode(_rangeEncoder, 0); + Byte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset)); + LiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte); + if (!_state.IsCharState()) + { + Byte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset)); + subCoder.EncodeMatched(_rangeEncoder, matchByte, curByte); + } + else + subCoder.Encode(_rangeEncoder, curByte); + _previousByte = curByte; + _state.UpdateChar(); + } + else + { + _isMatch[complexState].Encode(_rangeEncoder, 1); + if (pos < Base.kNumRepDistances) + { + _isRep[_state.Index].Encode(_rangeEncoder, 1); + if (pos == 0) + { + _isRepG0[_state.Index].Encode(_rangeEncoder, 0); + if (len == 1) + _isRep0Long[complexState].Encode(_rangeEncoder, 0); + else + _isRep0Long[complexState].Encode(_rangeEncoder, 1); + } + else + { + _isRepG0[_state.Index].Encode(_rangeEncoder, 1); + if (pos == 1) + _isRepG1[_state.Index].Encode(_rangeEncoder, 0); + else + { + _isRepG1[_state.Index].Encode(_rangeEncoder, 1); + _isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2); + } + } + if (len == 1) + _state.UpdateShortRep(); + else + { + _repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState); + _state.UpdateRep(); + } + UInt32 distance = _repDistances[pos]; + if (pos != 0) + { + for (UInt32 i = pos; i >= 1; i--) + _repDistances[i] = _repDistances[i - 1]; + _repDistances[0] = distance; + } + } + else + { + _isRep[_state.Index].Encode(_rangeEncoder, 0); + _state.UpdateMatch(); + _lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState); + pos -= Base.kNumRepDistances; + UInt32 posSlot = GetPosSlot(pos); + UInt32 lenToPosState = Base.GetLenToPosState(len); + _posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot); + + if (posSlot >= Base.kStartPosModelIndex) + { + int footerBits = (int)((posSlot >> 1) - 1); + UInt32 baseVal = ((2 | (posSlot & 1)) << footerBits); + UInt32 posReduced = pos - baseVal; + + if (posSlot < Base.kEndPosModelIndex) + RangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders, + baseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced); + else + { + _rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits); + _posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask); + _alignPriceCount++; + } + } + UInt32 distance = pos; + for (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--) + _repDistances[i] = _repDistances[i - 1]; + _repDistances[0] = distance; + _matchPriceCount++; + } + _previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset)); + } + _additionalOffset -= len; + nowPos64 += len; + if (_additionalOffset == 0) + { + // if (!_fastMode) + if (_matchPriceCount >= (1 << 7)) + FillDistancesPrices(); + if (_alignPriceCount >= Base.kAlignTableSize) + FillAlignPrices(); + inSize = nowPos64; + outSize = _rangeEncoder.GetProcessedSizeAdd(); + if (_matchFinder.GetNumAvailableBytes() == 0) + { + Flush((UInt32)nowPos64); + return; + } + + if (nowPos64 - progressPosValuePrev >= (1 << 12)) + { + _finished = false; + finished = false; + return; + } + } + } + } + + void ReleaseMFStream() + { + if (_matchFinder != null && _needReleaseMFStream) + { + _matchFinder.ReleaseStream(); + _needReleaseMFStream = false; + } + } + + void SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); } + void ReleaseOutStream() { _rangeEncoder.ReleaseStream(); } + + void ReleaseStreams() + { + ReleaseMFStream(); + ReleaseOutStream(); + } + + void SetStreams(System.IO.Stream inStream, System.IO.Stream outStream, + Int64 inSize, Int64 outSize) + { + _inStream = inStream; + _finished = false; + Create(); + SetOutStream(outStream); + Init(); + + // if (!_fastMode) + { + FillDistancesPrices(); + FillAlignPrices(); + } + + _lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen); + _lenEncoder.UpdateTables((UInt32)1 << _posStateBits); + _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen); + _repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits); + + nowPos64 = 0; + } + + + public void Code(System.IO.Stream inStream, System.IO.Stream outStream, + Int64 inSize, Int64 outSize, ICodeProgress progress) + { + _needReleaseMFStream = false; + try + { + SetStreams(inStream, outStream, inSize, outSize); + while (true) + { + Int64 processedInSize; + Int64 processedOutSize; + bool finished; + CodeOneBlock(out processedInSize, out processedOutSize, out finished); + if (finished) + return; + if (progress != null) + { + progress.SetProgress(processedInSize, processedOutSize); + } + } + } + finally + { + ReleaseStreams(); + } + } + + const int kPropSize = 5; + Byte[] properties = new Byte[kPropSize]; + + public void WriteCoderProperties(System.IO.Stream outStream) + { + properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits); + for (int i = 0; i < 4; i++) + properties[1 + i] = (Byte)((_dictionarySize >> (8 * i)) & 0xFF); + outStream.Write(properties, 0, kPropSize); + } + + UInt32[] tempPrices = new UInt32[Base.kNumFullDistances]; + UInt32 _matchPriceCount; + + void FillDistancesPrices() + { + for (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++) + { + UInt32 posSlot = GetPosSlot(i); + int footerBits = (int)((posSlot >> 1) - 1); + UInt32 baseVal = ((2 | (posSlot & 1)) << footerBits); + tempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, + baseVal - posSlot - 1, footerBits, i - baseVal); + } + + for (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++) + { + UInt32 posSlot; + RangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState]; + + UInt32 st = (lenToPosState << Base.kNumPosSlotBits); + for (posSlot = 0; posSlot < _distTableSize; posSlot++) + _posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot); + for (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++) + _posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits); + + UInt32 st2 = lenToPosState * Base.kNumFullDistances; + UInt32 i; + for (i = 0; i < Base.kStartPosModelIndex; i++) + _distancesPrices[st2 + i] = _posSlotPrices[st + i]; + for (; i < Base.kNumFullDistances; i++) + _distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i]; + } + _matchPriceCount = 0; + } + + void FillAlignPrices() + { + for (UInt32 i = 0; i < Base.kAlignTableSize; i++) + _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i); + _alignPriceCount = 0; + } + + + static string[] kMatchFinderIDs = + { + "BT2", + "BT4", + }; + + static int FindMatchFinder(string s) + { + for (int m = 0; m < kMatchFinderIDs.Length; m++) + if (s == kMatchFinderIDs[m]) + return m; + return -1; + } + + public void SetCoderProperties(CoderPropID[] propIDs, object[] properties) + { + for (UInt32 i = 0; i < properties.Length; i++) + { + object prop = properties[i]; + switch (propIDs[i]) + { + case CoderPropID.NumFastBytes: + { + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 numFastBytes = (Int32)prop; + if (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen) + throw new InvalidParamException(); + _numFastBytes = (UInt32)numFastBytes; + break; + } + case CoderPropID.Algorithm: + { + /* + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 maximize = (Int32)prop; + _fastMode = (maximize == 0); + _maxMode = (maximize >= 2); + */ + break; + } + case CoderPropID.MatchFinder: + { + if (!(prop is String)) + throw new InvalidParamException(); + EMatchFinderType matchFinderIndexPrev = _matchFinderType; + int m = FindMatchFinder(((string)prop).ToUpper()); + if (m < 0) + throw new InvalidParamException(); + _matchFinderType = (EMatchFinderType)m; + if (_matchFinder != null && matchFinderIndexPrev != _matchFinderType) + { + _dictionarySizePrev = 0xFFFFFFFF; + _matchFinder = null; + } + break; + } + case CoderPropID.DictionarySize: + { + const int kDicLogSizeMaxCompress = 30; + if (!(prop is Int32)) + throw new InvalidParamException(); ; + Int32 dictionarySize = (Int32)prop; + if (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) || + dictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress)) + throw new InvalidParamException(); + _dictionarySize = (UInt32)dictionarySize; + int dicLogSize; + for (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++) + if (dictionarySize <= ((UInt32)(1) << dicLogSize)) + break; + _distTableSize = (UInt32)dicLogSize * 2; + break; + } + case CoderPropID.PosStateBits: + { + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 v = (Int32)prop; + if (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax) + throw new InvalidParamException(); + _posStateBits = (int)v; + _posStateMask = (((UInt32)1) << (int)_posStateBits) - 1; + break; + } + case CoderPropID.LitPosBits: + { + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 v = (Int32)prop; + if (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax) + throw new InvalidParamException(); + _numLiteralPosStateBits = (int)v; + break; + } + case CoderPropID.LitContextBits: + { + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 v = (Int32)prop; + if (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax) + throw new InvalidParamException(); ; + _numLiteralContextBits = (int)v; + break; + } + case CoderPropID.EndMarker: + { + if (!(prop is Boolean)) + throw new InvalidParamException(); + SetWriteEndMarkerMode((Boolean)prop); + break; + } + default: + throw new InvalidParamException(); + } + } + } + + uint _trainSize = 0; + public void SetTrainSize(uint trainSize) + { + _trainSize = trainSize; + } + + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs.meta new file mode 100644 index 0000000..caab255 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/LZMA/LzmaEncoder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1e05222ef457fcd4b9b39cd998bf22a3 +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder.meta new file mode 100644 index 0000000..1d62139 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2c80d8fbc67455b4881c9557bce901a9 +folderAsset: yes +timeCreated: 1502467325 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs new file mode 100644 index 0000000..949c6bb --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs @@ -0,0 +1,234 @@ +using System; + +namespace SevenZip.Compression.RangeCoder +{ + class Encoder + { + public const uint kTopValue = (1 << 24); + + System.IO.Stream Stream; + + public UInt64 Low; + public uint Range; + uint _cacheSize; + byte _cache; + + long StartPosition; + + public void SetStream(System.IO.Stream stream) + { + Stream = stream; + } + + public void ReleaseStream() + { + Stream = null; + } + + public void Init() + { + StartPosition = Stream.Position; + + Low = 0; + Range = 0xFFFFFFFF; + _cacheSize = 1; + _cache = 0; + } + + public void FlushData() + { + for (int i = 0; i < 5; i++) + ShiftLow(); + } + + public void FlushStream() + { + Stream.Flush(); + } + + public void CloseStream() + { + Stream.Close(); + } + + public void Encode(uint start, uint size, uint total) + { + Low += start * (Range /= total); + Range *= size; + while (Range < kTopValue) + { + Range <<= 8; + ShiftLow(); + } + } + + public void ShiftLow() + { + if ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1) + { + byte temp = _cache; + do + { + Stream.WriteByte((byte)(temp + (Low >> 32))); + temp = 0xFF; + } + while (--_cacheSize != 0); + _cache = (byte)(((uint)Low) >> 24); + } + _cacheSize++; + Low = ((uint)Low) << 8; + } + + public void EncodeDirectBits(uint v, int numTotalBits) + { + for (int i = numTotalBits - 1; i >= 0; i--) + { + Range >>= 1; + if (((v >> i) & 1) == 1) + Low += Range; + if (Range < kTopValue) + { + Range <<= 8; + ShiftLow(); + } + } + } + + public void EncodeBit(uint size0, int numTotalBits, uint symbol) + { + uint newBound = (Range >> numTotalBits) * size0; + if (symbol == 0) + Range = newBound; + else + { + Low += newBound; + Range -= newBound; + } + while (Range < kTopValue) + { + Range <<= 8; + ShiftLow(); + } + } + + public long GetProcessedSizeAdd() + { + return _cacheSize + + Stream.Position - StartPosition + 4; + // (long)Stream.GetProcessedSize(); + } + } + + class Decoder + { + public const uint kTopValue = (1 << 24); + public uint Range; + public uint Code; + // public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16); + public System.IO.Stream Stream; + + public void Init(System.IO.Stream stream) + { + // Stream.Init(stream); + Stream = stream; + + Code = 0; + Range = 0xFFFFFFFF; + for (int i = 0; i < 5; i++) + Code = (Code << 8) | (byte)Stream.ReadByte(); + } + + public void ReleaseStream() + { + // Stream.ReleaseStream(); + Stream = null; + } + + public void CloseStream() + { + Stream.Close(); + } + + public void Normalize() + { + while (Range < kTopValue) + { + Code = (Code << 8) | (byte)Stream.ReadByte(); + Range <<= 8; + } + } + + public void Normalize2() + { + if (Range < kTopValue) + { + Code = (Code << 8) | (byte)Stream.ReadByte(); + Range <<= 8; + } + } + + public uint GetThreshold(uint total) + { + return Code / (Range /= total); + } + + public void Decode(uint start, uint size, uint total) + { + Code -= start * Range; + Range *= size; + Normalize(); + } + + public uint DecodeDirectBits(int numTotalBits) + { + uint range = Range; + uint code = Code; + uint result = 0; + for (int i = numTotalBits; i > 0; i--) + { + range >>= 1; + /* + result <<= 1; + if (code >= range) + { + code -= range; + result |= 1; + } + */ + uint t = (code - range) >> 31; + code -= range & (t - 1); + result = (result << 1) | (1 - t); + + if (range < kTopValue) + { + code = (code << 8) | (byte)Stream.ReadByte(); + range <<= 8; + } + } + Range = range; + Code = code; + return result; + } + + public uint DecodeBit(uint size0, int numTotalBits) + { + uint newBound = (Range >> numTotalBits) * size0; + uint symbol; + if (Code < newBound) + { + symbol = 0; + Range = newBound; + } + else + { + symbol = 1; + Code -= newBound; + Range -= newBound; + } + Normalize(); + return symbol; + } + + // ulong GetProcessedSize() {return Stream.GetProcessedSize(); } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs.meta new file mode 100644 index 0000000..76b69de --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7628341606acb864cb6b13e2dd60e638 +timeCreated: 1427784258 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs new file mode 100644 index 0000000..4f0346d --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs @@ -0,0 +1,117 @@ +using System; + +namespace SevenZip.Compression.RangeCoder +{ + struct BitEncoder + { + public const int kNumBitModelTotalBits = 11; + public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); + const int kNumMoveBits = 5; + const int kNumMoveReducingBits = 2; + public const int kNumBitPriceShiftBits = 6; + + uint Prob; + + public void Init() { Prob = kBitModelTotal >> 1; } + + public void UpdateModel(uint symbol) + { + if (symbol == 0) + Prob += (kBitModelTotal - Prob) >> kNumMoveBits; + else + Prob -= (Prob) >> kNumMoveBits; + } + + public void Encode(Encoder encoder, uint symbol) + { + // encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol); + // UpdateModel(symbol); + uint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob; + if (symbol == 0) + { + encoder.Range = newBound; + Prob += (kBitModelTotal - Prob) >> kNumMoveBits; + } + else + { + encoder.Low += newBound; + encoder.Range -= newBound; + Prob -= (Prob) >> kNumMoveBits; + } + if (encoder.Range < Encoder.kTopValue) + { + encoder.Range <<= 8; + encoder.ShiftLow(); + } + } + + private static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits]; + + static BitEncoder() + { + const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); + for (int i = kNumBits - 1; i >= 0; i--) + { + UInt32 start = (UInt32)1 << (kNumBits - i - 1); + UInt32 end = (UInt32)1 << (kNumBits - i); + for (UInt32 j = start; j < end; j++) + ProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) + + (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); + } + } + + public uint GetPrice(uint symbol) + { + return ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; + } + public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; } + public uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; } + } + + struct BitDecoder + { + public const int kNumBitModelTotalBits = 11; + public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); + const int kNumMoveBits = 5; + + uint Prob; + + public void UpdateModel(int numMoveBits, uint symbol) + { + if (symbol == 0) + Prob += (kBitModelTotal - Prob) >> numMoveBits; + else + Prob -= (Prob) >> numMoveBits; + } + + public void Init() { Prob = kBitModelTotal >> 1; } + + public uint Decode(RangeCoder.Decoder rangeDecoder) + { + uint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob; + if (rangeDecoder.Code < newBound) + { + rangeDecoder.Range = newBound; + Prob += (kBitModelTotal - Prob) >> kNumMoveBits; + if (rangeDecoder.Range < Decoder.kTopValue) + { + rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); + rangeDecoder.Range <<= 8; + } + return 0; + } + else + { + rangeDecoder.Range -= newBound; + rangeDecoder.Code -= newBound; + Prob -= (Prob) >> kNumMoveBits; + if (rangeDecoder.Range < Decoder.kTopValue) + { + rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); + rangeDecoder.Range <<= 8; + } + return 1; + } + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs.meta new file mode 100644 index 0000000..24f6155 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBit.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fdedea75b3cb5a54fbff3ed9b9517923 +timeCreated: 1427784258 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs new file mode 100644 index 0000000..4b4506f --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs @@ -0,0 +1,157 @@ +using System; + +namespace SevenZip.Compression.RangeCoder +{ + struct BitTreeEncoder + { + BitEncoder[] Models; + int NumBitLevels; + + public BitTreeEncoder(int numBitLevels) + { + NumBitLevels = numBitLevels; + Models = new BitEncoder[1 << numBitLevels]; + } + + public void Init() + { + for (uint i = 1; i < (1 << NumBitLevels); i++) + Models[i].Init(); + } + + public void Encode(Encoder rangeEncoder, UInt32 symbol) + { + UInt32 m = 1; + for (int bitIndex = NumBitLevels; bitIndex > 0; ) + { + bitIndex--; + UInt32 bit = (symbol >> bitIndex) & 1; + Models[m].Encode(rangeEncoder, bit); + m = (m << 1) | bit; + } + } + + public void ReverseEncode(Encoder rangeEncoder, UInt32 symbol) + { + UInt32 m = 1; + for (UInt32 i = 0; i < NumBitLevels; i++) + { + UInt32 bit = symbol & 1; + Models[m].Encode(rangeEncoder, bit); + m = (m << 1) | bit; + symbol >>= 1; + } + } + + public UInt32 GetPrice(UInt32 symbol) + { + UInt32 price = 0; + UInt32 m = 1; + for (int bitIndex = NumBitLevels; bitIndex > 0; ) + { + bitIndex--; + UInt32 bit = (symbol >> bitIndex) & 1; + price += Models[m].GetPrice(bit); + m = (m << 1) + bit; + } + return price; + } + + public UInt32 ReverseGetPrice(UInt32 symbol) + { + UInt32 price = 0; + UInt32 m = 1; + for (int i = NumBitLevels; i > 0; i--) + { + UInt32 bit = symbol & 1; + symbol >>= 1; + price += Models[m].GetPrice(bit); + m = (m << 1) | bit; + } + return price; + } + + public static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex, + int NumBitLevels, UInt32 symbol) + { + UInt32 price = 0; + UInt32 m = 1; + for (int i = NumBitLevels; i > 0; i--) + { + UInt32 bit = symbol & 1; + symbol >>= 1; + price += Models[startIndex + m].GetPrice(bit); + m = (m << 1) | bit; + } + return price; + } + + public static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex, + Encoder rangeEncoder, int NumBitLevels, UInt32 symbol) + { + UInt32 m = 1; + for (int i = 0; i < NumBitLevels; i++) + { + UInt32 bit = symbol & 1; + Models[startIndex + m].Encode(rangeEncoder, bit); + m = (m << 1) | bit; + symbol >>= 1; + } + } + } + + struct BitTreeDecoder + { + BitDecoder[] Models; + int NumBitLevels; + + public BitTreeDecoder(int numBitLevels) + { + NumBitLevels = numBitLevels; + Models = new BitDecoder[1 << numBitLevels]; + } + + public void Init() + { + for (uint i = 1; i < (1 << NumBitLevels); i++) + Models[i].Init(); + } + + public uint Decode(RangeCoder.Decoder rangeDecoder) + { + uint m = 1; + for (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--) + m = (m << 1) + Models[m].Decode(rangeDecoder); + return m - ((uint)1 << NumBitLevels); + } + + public uint ReverseDecode(RangeCoder.Decoder rangeDecoder) + { + uint m = 1; + uint symbol = 0; + for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) + { + uint bit = Models[m].Decode(rangeDecoder); + m <<= 1; + m += bit; + symbol |= (bit << bitIndex); + } + return symbol; + } + + public static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex, + RangeCoder.Decoder rangeDecoder, int NumBitLevels) + { + uint m = 1; + uint symbol = 0; + for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) + { + uint bit = Models[startIndex + m].Decode(rangeDecoder); + m <<= 1; + m += bit; + symbol |= (bit << bitIndex); + } + return symbol; + } + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs.meta new file mode 100644 index 0000000..24c67ed --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/Compress/RangeCoder/RangeCoderBitTree.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4d5a935938d52334fa68ededbbe1dbbd +timeCreated: 1427784258 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs new file mode 100644 index 0000000..c8b95c8 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs @@ -0,0 +1,157 @@ +// ICoder.h + +using System; + +namespace SevenZip +{ + /// + /// The exception that is thrown when an error in input stream occurs during decoding. + /// + class DataErrorException : ApplicationException + { + public DataErrorException(): base("Data Error") { } + } + + /// + /// The exception that is thrown when the value of an argument is outside the allowable range. + /// + class InvalidParamException : ApplicationException + { + public InvalidParamException(): base("Invalid Parameter") { } + } + + public interface ICodeProgress + { + /// + /// Callback progress. + /// + /// + /// input size. -1 if unknown. + /// + /// + /// output size. -1 if unknown. + /// + void SetProgress(Int64 inSize, Int64 outSize); + }; + + public interface ICoder + { + /// + /// Codes streams. + /// + /// + /// input Stream. + /// + /// + /// output Stream. + /// + /// + /// input Size. -1 if unknown. + /// + /// + /// output Size. -1 if unknown. + /// + /// + /// callback progress reference. + /// + /// + /// if input stream is not valid + /// + void Code(System.IO.Stream inStream, System.IO.Stream outStream, + Int64 inSize, Int64 outSize, ICodeProgress progress); + }; + + /* + public interface ICoder2 + { + void Code(ISequentialInStream []inStreams, + const UInt64 []inSizes, + ISequentialOutStream []outStreams, + UInt64 []outSizes, + ICodeProgress progress); + }; + */ + + /// + /// Provides the fields that represent properties idenitifiers for compressing. + /// + public enum CoderPropID + { + /// + /// Specifies default property. + /// + DefaultProp = 0, + /// + /// Specifies size of dictionary. + /// + DictionarySize, + /// + /// Specifies size of memory for PPM*. + /// + UsedMemorySize, + /// + /// Specifies order for PPM methods. + /// + Order, + /// + /// Specifies Block Size. + /// + BlockSize, + /// + /// Specifies number of postion state bits for LZMA (0 <= x <= 4). + /// + PosStateBits, + /// + /// Specifies number of literal context bits for LZMA (0 <= x <= 8). + /// + LitContextBits, + /// + /// Specifies number of literal position bits for LZMA (0 <= x <= 4). + /// + LitPosBits, + /// + /// Specifies number of fast bytes for LZ*. + /// + NumFastBytes, + /// + /// Specifies match finder. LZMA: "BT2", "BT4" or "BT4B". + /// + MatchFinder, + /// + /// Specifies the number of match finder cyckes. + /// + MatchFinderCycles, + /// + /// Specifies number of passes. + /// + NumPasses, + /// + /// Specifies number of algorithm. + /// + Algorithm, + /// + /// Specifies the number of threads. + /// + NumThreads, + /// + /// Specifies mode with end marker. + /// + EndMarker + }; + + + public interface ISetCoderProperties + { + void SetCoderProperties(CoderPropID[] propIDs, object[] properties); + }; + + public interface IWriteCoderProperties + { + void WriteCoderProperties(System.IO.Stream outStream); + } + + public interface ISetDecoderProperties + { + void SetDecoderProperties(byte[] properties); + } +} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs.meta new file mode 100644 index 0000000..c99a019 --- /dev/null +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/7zip/ICoder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 54d3c6cf65df0ac4f893f91153f1629d +timeCreated: 1427784069 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutoFaceBase.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutoFaceBase.cs deleted file mode 100644 index 64a5f93..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutoFaceBase.cs +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************************************* -**文 件 名:AutoFaceBase -**创建时间:2017/8/10 星期四 下午 3:13:24 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -using XLua; -using System.IO; -public class AutoFaceBase : IAutoFace -{ - Action _luaFunc; - public Action LuaFunc - { - get { return _luaFunc; } - - set { _luaFunc = value; } - } - Action _luaOnDestroy; - public Action LuaOnDestroy - { - get { return _luaOnDestroy; } - - set { _luaOnDestroy = value; } - } - Action _luaStart; - public Action LuaStart - { - get { return _luaStart; } - - set { _luaStart = value; } - } - Action _luaUpdate; - public Action LuaUpdate - { - get { return _luaUpdate; } - - set { _luaUpdate = value; } - } - private LuaTable scriptEnv; - internal static LuaEnv luaEnv = new LuaEnv(); //all lua behaviour shared one luaenv only! - - public void RegisterLua() - { - - luaEnv.DoString("require 'Main'"); - - scriptEnv = luaEnv.NewTable(); - LuaTable meta = luaEnv.NewTable(); - meta.Set("__index", luaEnv.Global); - scriptEnv.SetMetaTable(meta); - meta.Dispose(); - scriptEnv.Set("self", this); - - - scriptEnv.Get("start", out _luaStart); - scriptEnv.Get("update", out _luaUpdate); - scriptEnv.Get("ondestroy", out _luaOnDestroy); - scriptEnv.Get("Testfunc", out _luaFunc); - } - - public string ReadLua(string filePath) - { - string str=""; - str = File.ReadAllText(Application.streamingAssetsPath + "/" + filePath); - return str; - } -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceMgr.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceMgr.cs deleted file mode 100644 index bb585d5..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceMgr.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************************* -**文 件 名:AutofaceMgr -**创建时间:2017/8/10 星期四 下午 3:31:28 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -public class AutofaceMgr -{ - IAutoFace _iAutoFace; - - public AutofaceMgr(IAutoFace iAutoFace) - { - _iAutoFace = iAutoFace; - } - - public void Init() - { - _iAutoFace.RegisterLua(); - Debug.LogWarning(" sucess register lua!"); - } - - public void OnStart() - { - if (_iAutoFace.LuaStart != null) - { - _iAutoFace.LuaStart(); - } - } - public void OnUpdate() - { - if (_iAutoFace.LuaUpdate != null) - { - _iAutoFace.LuaUpdate(); - } - } - public void OnDestroy() - { - if (_iAutoFace.LuaOnDestroy != null) - { - _iAutoFace.LuaOnDestroy(); - } - } - public void OnLuaFunc() - { - if (_iAutoFace.LuaFunc != null) - { - _iAutoFace.LuaFunc(); - } - } - -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs deleted file mode 100644 index 6a0e1f5..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************************* -**文 件 名:AutofaceTest -**创建时间:2017/8/10 星期四 下午 3:01:06 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -using Autofac; -using UnityEngine.UI; -public class AutofaceTest:MonoBehaviour -{ - public AutofaceMgr manager; - public Button button; - void Awake() - { - var builder = new ContainerBuilder(); - builder.RegisterType(); - builder.RegisterType().As(); - using (var container = builder.Build()) - { - manager = container.Resolve(); - manager.Init(); - } - button.onClick.AddListener(ToLuaFunc); - } - - void Start() - { - manager.OnStart(); - } - void Update() - { - // manager.OnUpdate(); - } - void OnDestroy() - { - manager.OnDestroy(); - } - - private void ToLuaFunc() - { - manager.OnLuaFunc(); - } -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.unity b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.unity deleted file mode 100644 index 50b84b5..0000000 Binary files a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.unity and /dev/null differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad.meta similarity index 67% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad.meta index 26f9b97..e11c3c4 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 3ff45b43331f6f74a83e907706c49cc6 +guid: 150e744d398d8734f81ecee312392253 folderAsset: yes -timeCreated: 1502864101 +timeCreated: 1503972589 licenseType: Pro DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs similarity index 78% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs index 1de24d0..5de1942 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs @@ -1,6 +1,6 @@ /************************************************************************************* -**文 件 名:TestApi -**创建时间:2017/8/11 星期五 下午 3:21:24 +**文 件 名:LuaLoadTest +**创建时间:2017/8/29 星期二 上午 10:10:08 **作 者:罗弘(email: 243515320@qq.com) **工 号:102193 **说 明: @@ -11,7 +11,7 @@ using System; using System.Collections.Generic; using UnityEngine; -public class TestApi: IAndroidApi +public class LuaLoadTest { } diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs.meta similarity index 75% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs.meta index 6237404..a358594 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/AutofaceTest.cs.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/LuaLoadTest.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: cfbd0c3546969104fbdcb90296b03056 -timeCreated: 1502348499 +guid: ea0539fcd3aaf15498d3661125f37004 +timeCreated: 1503973570 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity new file mode 100644 index 0000000..ade4bea Binary files /dev/null and b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity.meta similarity index 63% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity.meta index 842192a..d57e0df 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_LuaLoad/demo.unity.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 148eddc01bec97c4aa87ec9d91acd828 -timeCreated: 1502354395 +guid: 9ce2382e5c60e064f80e88e32dc2b135 +timeCreated: 1503972539 licenseType: Pro DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutoFaceBase.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutoFaceBase.cs deleted file mode 100644 index 64a5f93..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutoFaceBase.cs +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************************************* -**文 件 名:AutoFaceBase -**创建时间:2017/8/10 星期四 下午 3:13:24 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -using XLua; -using System.IO; -public class AutoFaceBase : IAutoFace -{ - Action _luaFunc; - public Action LuaFunc - { - get { return _luaFunc; } - - set { _luaFunc = value; } - } - Action _luaOnDestroy; - public Action LuaOnDestroy - { - get { return _luaOnDestroy; } - - set { _luaOnDestroy = value; } - } - Action _luaStart; - public Action LuaStart - { - get { return _luaStart; } - - set { _luaStart = value; } - } - Action _luaUpdate; - public Action LuaUpdate - { - get { return _luaUpdate; } - - set { _luaUpdate = value; } - } - private LuaTable scriptEnv; - internal static LuaEnv luaEnv = new LuaEnv(); //all lua behaviour shared one luaenv only! - - public void RegisterLua() - { - - luaEnv.DoString("require 'Main'"); - - scriptEnv = luaEnv.NewTable(); - LuaTable meta = luaEnv.NewTable(); - meta.Set("__index", luaEnv.Global); - scriptEnv.SetMetaTable(meta); - meta.Dispose(); - scriptEnv.Set("self", this); - - - scriptEnv.Get("start", out _luaStart); - scriptEnv.Get("update", out _luaUpdate); - scriptEnv.Get("ondestroy", out _luaOnDestroy); - scriptEnv.Get("Testfunc", out _luaFunc); - } - - public string ReadLua(string filePath) - { - string str=""; - str = File.ReadAllText(Application.streamingAssetsPath + "/" + filePath); - return str; - } -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs deleted file mode 100644 index bb585d5..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************************* -**文 件 名:AutofaceMgr -**创建时间:2017/8/10 星期四 下午 3:31:28 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -public class AutofaceMgr -{ - IAutoFace _iAutoFace; - - public AutofaceMgr(IAutoFace iAutoFace) - { - _iAutoFace = iAutoFace; - } - - public void Init() - { - _iAutoFace.RegisterLua(); - Debug.LogWarning(" sucess register lua!"); - } - - public void OnStart() - { - if (_iAutoFace.LuaStart != null) - { - _iAutoFace.LuaStart(); - } - } - public void OnUpdate() - { - if (_iAutoFace.LuaUpdate != null) - { - _iAutoFace.LuaUpdate(); - } - } - public void OnDestroy() - { - if (_iAutoFace.LuaOnDestroy != null) - { - _iAutoFace.LuaOnDestroy(); - } - } - public void OnLuaFunc() - { - if (_iAutoFace.LuaFunc != null) - { - _iAutoFace.LuaFunc(); - } - } - -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs.meta deleted file mode 100644 index 0b60a23..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceMgr.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 0308eda7e36e1b446800c26f0ab95e15 -timeCreated: 1502351103 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs deleted file mode 100644 index 6a0e1f5..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************************* -**文 件 名:AutofaceTest -**创建时间:2017/8/10 星期四 下午 3:01:06 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -using Autofac; -using UnityEngine.UI; -public class AutofaceTest:MonoBehaviour -{ - public AutofaceMgr manager; - public Button button; - void Awake() - { - var builder = new ContainerBuilder(); - builder.RegisterType(); - builder.RegisterType().As(); - using (var container = builder.Build()) - { - manager = container.Resolve(); - manager.Init(); - } - button.onClick.AddListener(ToLuaFunc); - } - - void Start() - { - manager.OnStart(); - } - void Update() - { - // manager.OnUpdate(); - } - void OnDestroy() - { - manager.OnDestroy(); - } - - private void ToLuaFunc() - { - manager.OnLuaFunc(); - } -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs.meta deleted file mode 100644 index 6237404..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: cfbd0c3546969104fbdcb90296b03056 -timeCreated: 1502348499 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.unity b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.unity deleted file mode 100644 index 50b84b5..0000000 Binary files a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/AutofaceTest.unity and /dev/null differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/IAutoFace.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/IAutoFace.cs.meta deleted file mode 100644 index c531e25..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/IAutoFace.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 2ab1d22f20cec694391af4bf421b08fd -timeCreated: 1502349477 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt deleted file mode 100644 index 2e709ee..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt +++ /dev/null @@ -1 +0,0 @@ -require "Test" function start() print("lua start...") end function update() print("lua update...") end function ondestroy() print("lua destroy") end function Testfunc() print("lua do something...") DoSomething(); end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt.meta deleted file mode 100644 index 9f94a6c..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Main.lua.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5aeca407ea9cc3e4f9114f1388d70c07 -timeCreated: 1502356708 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt deleted file mode 100644 index 5f1dcf6..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt +++ /dev/null @@ -1 +0,0 @@ -function DoSomething() print("you jump i jump...") end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt.meta deleted file mode 100644 index 6eb4963..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/Resources/Test.lua.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 42bda03cbda6cdb46a1c664c9bc9eb78 -timeCreated: 1502356708 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs deleted file mode 100644 index f0188bc..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs +++ /dev/null @@ -1,66 +0,0 @@ -/************************************************************************************* -**文 件 名:Bootstrap -**创建时间:2017/8/11 星期五 下午 5:27:36 -**作 者:罗弘(email: 243515320@qq.com) -**工 号:102193 -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using Autofac; -using Code.AdroidApi; - -public class Bootstrap:MonoBehaviour -{ - public Button Btn_1; - public Button Btn_2; - public Button Btn_3; - public Text ShowText; - public AutofaceMgr manager; - void Awake() - { - var builder = new ContainerBuilder(); - builder.RegisterType(); - builder.RegisterType().As(); - using (var container = builder.Build()) - { - manager = container.Resolve(); - manager.Init(); - } - Btn_1.onClick.AddListener(UnityCallAndroid); - Btn_2.onClick.AddListener(UnityCallAndroidToastMsg); - Btn_3.onClick.AddListener(AndroidCallUnity); - } - - private void UnityCallAndroid() - { - int a = UnityEngine.Random.Range(1, 100); - int b = UnityEngine.Random.Range(1, 100); - int c = AndroidApi.getInstance().SDKCall("add", a, b); - ShowText.text = a+"+"+b+" 呼叫Adroid返回的结果:" + c; - } - - private void UnityCallAndroidToastMsg() - { - AndroidApi.getInstance().SDKCall("ShowToast", "安卓需要显示一下哟!!!"); - } - - private void AndroidCallUnity() - { - /// android 方法, 挂有呼叫方法的对象名字,方法名字 - AndroidApi.getInstance().SDKCall("CallUnity", "Canvas", "ToLuaFunc"); - } - - private int callnum = 0; - public void ToLuaFunc() - { - manager.OnLuaFunc(); - callnum++; - ShowText.text = "android通知unity方法, 呼叫 "+ callnum +"次"; - } -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs.meta deleted file mode 100644 index 4687fed..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/Bootstrap.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 4d116796f683f3f4a9d3eac22c6036e8 -timeCreated: 1502444559 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/IAndroidApi.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/IAndroidApi.cs.meta deleted file mode 100644 index 43be1cd..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/IAndroidApi.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 24828e735f5abdb45a59ccfe240b21be -timeCreated: 1502864101 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs.meta deleted file mode 100644 index 2a86e71..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/TestApi/TestApi.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 6bde246ea56d77346858268c985594f5 -timeCreated: 1502864101 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua deleted file mode 100644 index b28496b..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Main.lua +++ /dev/null @@ -1 +0,0 @@ -require "test.lua" function start() print("lua start...") end function update() print("lua update...") end function ondestroy() print("lua destroy") end function Testfunc() print("lua do something...") DoSomething(); end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Test.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Test.lua deleted file mode 100644 index 5f1dcf6..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua/Test.lua +++ /dev/null @@ -1 +0,0 @@ -function DoSomething() print("you jump i jump...") end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11.meta similarity index 67% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11.meta index 01c8d5f..1e58b36 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/1.0_ToXlua/lua.meta +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 21a87314180a24a4baddab64a287bdd7 +guid: e9e804decb7d99f40bbae62f4991f152 folderAsset: yes -timeCreated: 1502354813 +timeCreated: 1503974289 licenseType: Pro DefaultImporter: userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua2.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11/TestLua2.lua similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua2.lua rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11/TestLua2.lua diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua2.lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11/TestLua2.lua.meta similarity index 100% rename from AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua2.lua.meta rename to AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/11/TestLua2.lua.meta diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua1.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua1.lua index 6c1572a..ff874c7 100644 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua1.lua +++ b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Examples/3.0_XluaLoading/lua/TestLua1.lua @@ -1,5 +1,6 @@ -require "TestLua2" +require "11/TestLua2" function dofunc1() print("dodododoodododod11111111111") dofunc2() -end \ No newline at end of file +end + diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs deleted file mode 100644 index 941494f..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs +++ /dev/null @@ -1,23 +0,0 @@ -/************************************************************************************* -**文 件 名:IAutoFace -**创建时间:2017/8/10 星期四 下午 3:04:00 -**作 者: -**工 号: -**说 明: -**版 本:V1.0.0 -**修改时间: -**修 改 人: - *************************************************************************************/ -using System; -using System.Collections.Generic; - -public interface IAutoFace -{ - Action LuaStart { get; set; } - - Action LuaUpdate { get; set; } - Action LuaOnDestroy { get; set; } - - Action LuaFunc { get; set; } - void RegisterLua(); -} diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs.meta deleted file mode 100644 index c531e25..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/IAutoFace.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 2ab1d22f20cec694391af4bf421b08fd -timeCreated: 1502349477 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources.meta deleted file mode 100644 index 3b793bc..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: eef2cf50a096d44448102879c78c6485 -folderAsset: yes -timeCreated: 1502356369 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt deleted file mode 100644 index 2e709ee..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt +++ /dev/null @@ -1 +0,0 @@ -require "Test" function start() print("lua start...") end function update() print("lua update...") end function ondestroy() print("lua destroy") end function Testfunc() print("lua do something...") DoSomething(); end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt.meta deleted file mode 100644 index 9f94a6c..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Main.lua.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5aeca407ea9cc3e4f9114f1388d70c07 -timeCreated: 1502356708 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt deleted file mode 100644 index 5f1dcf6..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt +++ /dev/null @@ -1 +0,0 @@ -function DoSomething() print("you jump i jump...") end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt.meta deleted file mode 100644 index 6eb4963..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/Resources/Test.lua.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 42bda03cbda6cdb46a1c664c9bc9eb78 -timeCreated: 1502356708 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua.meta deleted file mode 100644 index 01c8d5f..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 21a87314180a24a4baddab64a287bdd7 -folderAsset: yes -timeCreated: 1502354813 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua deleted file mode 100644 index b28496b..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua +++ /dev/null @@ -1 +0,0 @@ -require "test.lua" function start() print("lua start...") end function update() print("lua update...") end function ondestroy() print("lua destroy") end function Testfunc() print("lua do something...") DoSomething(); end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua.meta deleted file mode 100644 index 842192a..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Main.lua.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 148eddc01bec97c4aa87ec9d91acd828 -timeCreated: 1502354395 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua deleted file mode 100644 index 5f1dcf6..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua +++ /dev/null @@ -1 +0,0 @@ -function DoSomething() print("you jump i jump...") end \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua.meta deleted file mode 100644 index 78bb893..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/AutofaceTest/lua/Test.lua.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 2b46b2cde372c8f4bbd851b71a4259a3 -timeCreated: 1502354395 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt deleted file mode 100644 index c6f8509..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt +++ /dev/null @@ -1,325 +0,0 @@ -v2.1.9 [待发布] -新增特性 -1、新增最小生成模式,可以节省50%的text段空间; -2、新增xlua.util.createdelegate,支持在lua直接用C#函数创建delegate而不需要通过lua适配; -3、xlua.private_accessible支持public int Prop { get; private set; } -4、新增 xlua.getmetatable、 xlua.setmetatable、xlua.setclass、xlua.genaccessor,用以支持lua使用C#类型直接在lua侧完成; -5、反射下扩展方法的支持; - -优化 -1、加入travis持续集成; - -变更 -1、LuaCallCSharp自动去除匿名类型; -2、THREAD_SAFT改为THREAD_SAFE; -3、GenFlag.GCOptimize标记为过时; -4、删除过时的GenConfig配置方式; - -bug修复 -1、window phone下一些系统api是禁用的,源码中去掉; -2、泛型约束是struct的时候,生成代码失败; -3、unity2017 .net 4.6,枚举生成代码报错; - -v2.1.8 2017年6月27日 -新增特性 -1、Hotfix标签添加几个订制参数:ValueTypeBoxing、IgnoreProperty、IgnoreNotPublic、Inline、IntKey -2、Hotfix代码注入优化,减少text段占用; -3、Hotfix配置支持放Editor目录,可以减少text段占用; -4、支持以指定类型传递object参数; -5、反射调用Obsolete方法在Editor下打印warning; - -变更 - -bug修复 -1、pinvoke独立设置的In,Out属性可能导致生成代码失败; -2、如果业务在全局名字空间有和xLua名字空间的同名类,生成代码编译失败; - -v2.1.7 2017年5月17日 -新增特性 -1、支持发布UWP(含HoloLens,Xbox one,Win10 Mobile、Win10 PC)应用; -2、支持对lua源代码ras+sha1签名; -3、如果没安装Tools提示“please install the Tools”; -4、linxu版本的支持; -5、支持bitcode打包; -6、对所有struct新增无参数构造函数; -7、delegate的参数名改为p0到pn,防止hotfix时业务代码变量和生成代码冲突; -8、支持对成员名为C#关键字的情况; -9、新增util.loadpackage,和require类似,通过searcher加载文件,不同的是,它不执行,而且也不会cache到package.loaded; -10、优化模版引擎大文件的生成性能; -11、新增不需要生成代码的注入方式; -12、支持构造函数参数带ref和out修饰符; -13、构造函数也支持黑名单排除; - -变更 -1、this[object field]操作符重载; -2、反射的数据转换规则改成和生成代码一致; -3、忽略掉匿名类及匿名函数的注入; - -bug修复 -1、规避Unity的bug:List,CustomType是当前执行程序集的类型,这在.Net是不需要指明程序集就可以通过Type.GetType得到,但Unity下不行。 -2、解决反射下,可变参数不提供时,传null的问题; -3、继承了另外一个程序集的类型,使用了protected类型会导致注入失败; -4、luajit去掉dlopen和dlsym的调用; -5、解决通用版本的生成代码工具找不到模版的问题; -6、修复通用版本反射导入泛化类型的问题; -7、反射调用含delegate参数的的api,会因为缓存而导致调用LuaEnv.Dispose失败; -8、兼容老版本的C编译器,声明要放开头; -9、生成代码对hotfix的检测算法和注入工具不一致导致的注入失败; -10、注入的nested类型是public,但其的外层类型非public,生成代码报错; -11、析构函数只判断名字可能出现误判; -12、构造函数是非public的,可能会导致找不到适配delegate而注入失败; -13、修正Extension method会在所有子类都生成代码的bug(2.1.6泛化特性引入); -14、构造函数重载,只有一个能hotfix成功; -15、规避一个可能是il2cpp的bug(unity5.4):字符串参数默认值是"",ios下在反射的default value也是Reflection.Missing; -16、将一个table传到List<>,取了最后一个参数,而不是那个table的长度; -17、ldarg指令在这种场景下il2cpp转换时会出现异常:1、采用模版注入;2、从4到255间有一个输出参数;改为兼容性更好的ldarg.s; -18、解决配置了System.Delegate到CSCallLua,执行生成代码会编辑器会crash的问题; -19、扩展函数可能和原来的函数同名,反射实现并未考虑到这种情况; -20、通用版本的可变参数delegate调用异常; -21、unity4规避lua53冲突的方式改为返回null更合适,异常方式会导致IsNull无法正常工作; -22、lua_tostring解码失败改为UTF8解码; - -v2.1.6 2017年3月1日 -新增特性 -1、带约束的泛型支持(by forsakenyang); -2、非Unity的.net环境支持; -3、代码注入支持小工具方式,该方式不用拷贝cecil库,可以解决拷错cecil库版本或者和Unity,VS插件冲突的问题; -4、Hotfix配置支持字段和属性 -5、更方便的Unity协程hotfix -6、在hotfix触发事件; -7、LuaTable添加ForEach方法以及Length属性; -8、cmake生成项目优化:保留源文件目录结构; -9、对已经Dispose的LuaEnv的访问做保护;Dispose时检查callback是否已经都释放,没释放的话报错; -10、支持释放Hotfix回调; - -变更 -1、构造函数改为执行原有逻辑后调用lua; -2、this[string field]操作符重载会影响到继承调用,去掉该特性的支持; -3、编辑器下的代码注入改为手动方式; - -bug修复 -1、防止定义了同时定义get_xx方法以及xx属性的生成代码的重名。 -2、struct注入代码无效; -3、Utils加名字空间,防止和业务冲突; -4、返回定长多维数组的delegate,生成代码可能会冲突; -5、interface,以及编辑器下不生成代码情况下,对可变参数的展开; -6、il2cpp下,如果不生成代码,会报ManifestModule不支持; -7、规避Unity4的bug:访问一个已经被Distroy的UnityEngine.Object,编辑器下会崩溃,这个问题在Unity5,或者luajit版本都不会出现; -8、修改上个版本引入的问题:xlua_setglobal会漏一个值在栈上,这会导致一些32位应用不稳定; -9、当delegate参数只有ref和out的区别的话,报重载冲突; - -v2.1.5 2017年1月13日 - -新增特性 -1、全平台热补丁; -2、新增线程安全模式,可通过THREAD_SAFT宏打开; -3、新增更简便的配置方式,具体参见XLua\Doc下《XLua的配置.doc》; -4、多虚拟机实例时的自动Dispose; -5、内存优化:减少匿名闭包到delegate映射的内存占用;减少LuaFunction以及LuaTable内存占用;减少lua table映射C#interface的gc; -6、生成代码速度优化; -7、支持直接在lua侧clone C#结构体; -8、LuaFunction新增无gc调用api; - -变更 -1、delegate必须都加[CSharpCallLua]才支持C#到lua的回调(以前参数和返回值都相同的delegate只要其中一个加了就可以); -2、加回string/number到枚举的自动转换; - -bug修复 -1、枚举不生成代码时,第一次使用会产生两个不同的userdata; -2、数组和System.Type的相互引用导致System.Type生成代码无法加载; -3、更安全的异常处理,封装lua_setglobal,lua_getglobal的异常,C#回调保证所有C#异常都catch并转换到成lua error。 - - -v2.1.4 2016年11月29日 -新增特性 -1、加了ReflectionUse会自动生成到link.xml,可以防止il2cpp下因stripping导致的反射不可用; -2、开放生成引擎,可二次开发自己生成插件,生成所需的代码或配置; -3、GetInPath和SetInPath无C# gc优化; -4、一个lua table自动转换为带GCOptimize标签的复杂类型以及该复杂类型的一维数组不使用反射,如果这复杂类型是纯值类型,无c# gc; - -变更 -1、基于一致性以及性能的考虑,不支持数字和字符串到枚举的静默转换,须主动调用起类下的__CastFrom; -2、名字空间从LuaInterface改为XLua; -3、LuaTable的几个可能导致gc的api标注为Obsolete; -4、在不指明返回类型的情况下,如果一个number是整数会优先转换成整数; - -bug修复 -1、含能隐式转换int,long,decimal的类型传到lua变成decimal; -2、反射的重载判断,如果可变参数的位置上是一个不匹配的参数,也会判断为匹配成功; -3、可变参数+重载的话,可变部分不传会报无效参数; -4、加了LuaCallCSharp的Extension method,在Editor下不生成代码不可用; - -v2.1.3 2016年11月09日 -新增特性 -1、LuaTable新增Get和Set接口,table操作支持值类型无gc; -2、支持decimal,不丢失精度而且传递到lua无gc; -3、增加LuaEnv.LoadString接口,用于指定返回的delegate类型; -4、例子刷新:新增Helloworld,无GC调用,Lua面向对象,协程例子; -5、enum优化:传递到lua无gc,从int或者string到枚举转换无gc; -6、event的+/-优化:性能提升一倍,而且无gc; -7、生成代码简化; - -变更 -1、uint在lua53映射到lua_Integer; -2、StreamingAssets加载改为优先级最低; - -bug修复 -1、生成代码下,如果LuaTable或者LuaFunction参数为null会抛异常; -2、lua5.3下,浮点到枚举的静默转换失败; -3、反射下struct类型参数带默认值抛异常; -4、lua53下Length返回浮点; - -v2.1.2 2016年10月08日 -新增特性 -1、支持lua5.3,进而支持苹果bitcode,原生64位整数,位运算,utf8等特性; -2、CMake编译,更方便加入第三方插件 -3、数组性能优化,包括访问性能以及gc -4、C#调用lua函数减少一次lua gc; -5、优化启动时间; -6、减少类型加载的gc; -7、优化ObjectPool的内存占用; -8、优化小字符串传入lua的gc; -9、LuaTable添加Cast接口,用于LuaTable到其它类型的转换,比如interface; -10、LuaFunction添加Cast接口,用于LuaFunction到delegate的转换; - -变更 -1、lua内部只有带符号的64整数类型,并增加无符号数库 -2、如果不想对Extension Method生成代码,又希望在反射下用,需要添加ReflectionUse; - -bug修复 -1、对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除功能的内存泄漏问题; -2、规避某些版本(已知是5.3.3)的Unity的bug导致的内存泄漏问题; -3、LuaTable或者LuaFunction做返回值的delegate生成代码可能报错; - -v2.1.1 2016年08月29日 -新增特性 -1、支持编辑器下不用生成代码能运行; -2、新增IntPtr的支持 -3、增加对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除; -4、在LuaEnv添加对lua_gc一些封装; - -bug修复 -1、生成代码传送一个LuaFunction、LuaTable到lua和反射版本不一致,生成代码传送过去是一个C#对象,而反射是Lua函数、table对象,反射的处理更合适; -2、修复同名的静态以及成员方法冲突的问题; -3、修复对interface生成CSharpCallLua代码时,interface含indexer时的报错; -4、修复Editor在运行后会new一个xlua实例的bug; -5、修复通过生成代码调用同时含可变参数和默认值的函数,如果不传参数,将会出错的bug; -6、修复调试时,找不到socket库的bug; - - -变更 -1、反射不做重载方法顺序调整,顺序改为固定且生成代码保持一致; -2、i64加上fade_id,参数传递时更安全; -3、重新加入tdr的from_file的支持; - -v2.1.0 2016年08月08日 -新增特性 -1、满足条件struct传递到lua无gc,struct需要满足什么条件才能被优化呢? -a. struct允许嵌套其它struct,但它以及它嵌套的struct只能包含这几种基本类型:byte、sbyte、short、ushort、int、uint、long、ulong、float、double; -b. struct本身以及使用到该struct的地方需要加LuaCallCSharp,并且加了GCOptimize设置; -2、全新实现的反射机制,更容易和生成代码配合使用 -a. 支持extension methods,Enum.__CastFrom; -b. ios下支持反射使用event; -c. 对类型映射、可变参数调用调整为和生成代码一致; -d. 性能更好,gc更少; -3、生成代码菜单简化,并增加“Generate Minimum”选项; -4、支持生成代码配置文件放Editor目录; - -变更 -1、luajit统一升级成2.1.0b2; -2、luasocket库改为按需加载; -3、重载的string,byte[]参数检查允许为nil; -4、子类访问不触发父类加载; -5、struct的ref参数的修改会修改lua测该参数的值; -6、生成代码加载改为静态(原来是反射); -7、菜单改为更简洁; -8、tdr改为默认不加载; -9、StreamingAssets加载lua改为废弃特性; - -bug修复 -1、参数或者返回值是泛型类的数组,或者是二维数组,生成代码报编译错误; -2、抽象类生成代码报编译错误; -3、消除Clear生成代码的warning; -4、profiler、i64库不支持多实例; - -v2.0.5 2016年05月18日 -新增特性 -1、util.async_to_sync,可以更好的利用lua的协程实现同步编程、异步执行;或者异步等待www等; -2、生成代码的规范度调整,消除一些工具的告警; -bug修复 -1、解决在lua gc移除weak table和调用__gc的时间窗内push同一对象,会生成指向同一C#对象的不同userdata的问题; -2、上版本的的lua内存工具并未打包; -3、修正嵌套类型不能生成代码的问题; - -v2.0.4 2016年05月04日 -新增特性 -1、新增函数调用时长报告功能; -2、新增lua内存泄漏定位工具; -3、lua测加入对64位无符号数的支持; -变更 -1、支持多种delegate绑定到一个clousre。调整之前一个clousre只能对应一种delegate; -bug修复 -1、tdr处理长度为1的数组的错误(本来解包应该是{[1] = {a = 1}}的,却是{{a=1}}); -2、tdr数值处理错误(int的-1会解成一个很大的正数) - -v2.0.3 2016年04月13日 -新功能 -1、添加“Advanced Gen”功能,用户可以自定义生成代码的范围; -2、支持对库生成Static pusher; -变更 -1、LuaTable以及InterfaceBirdage改为触发metatable; -2、Extension Methods不自动加到被扩展类,需要加入生成列表; -3、移除特殊ValueType优化; -bug修复 -1、Extension Methods为私有时,生成代码语法错误; -2、重载函数含ulong时,生成代码语法错误; -3、反射调用时的默认值处理错误; -4、C#向lua传中文字符的长度处理错误; - -v2.0.2 2016年04月06日 -变更 -1、库的生成代码配置支持多份,方便项目的模块化; -2、enum的生成代码合并到一个文件里头; -3、优化异常处理; -4、发布包把库和教程、例子分离,更干净; -5、小bug修改; - -升级指引 -由于文件有点变动,直接覆盖原有lib会报错,需要: -1、删除原来的XLua目录; -2、解压xlua_v2.0.2.zip到Assets下; -3、重新执行代码生成; - -v2.0.1 2016年03月24日 -1、支持C# 的extension methods; -2、lua调试方面的支持; -3、android下require一个不存在的lua文件可能成功的bug; -4、TDR 4 Lua库的更新; -5、多机型的兼容性测试; - -v2.0.0 2016年03月08日 -1、性能优化,性能对比报告请看主页; -2、加入官方lua版本的tdr; -3、支持64位整数; -4、修正lua中对C#异常pcall引发的不稳定; -5、易用性的优化; -6、其它一些bug的修改。 - -1.0.2 2015年12月09日 -1、解决新版本(已知5.2版本)下,streamAssetsPath不允许在构造函数访问导致的bug; -2、新增windows x64版本的支持; -3、对web版本才用到的代码加入条件编译,减少对手机版发布包的影响; -4、生成代码文件名去掉“+”号; -5、删除4.6的生成代码,以免在新版本报引用过时api的错; - -v1.0.1 2015年11月30日 -1、支持pcall捕捉C#异常; -2、新增cast方法,支持这种场景:实现类是internal声明,只提供interface; -3、解决interface下如果有event,生成代码编译报错的bug; -4、解决interface下有Obsolete的方法,字段,生成代码编译报错的bug; -5、解决含private的默认geter/setter生成代码编译报错的bug; -6、修正类在全局空间下生成代码不可用的bug; -7、修正bridge代码返回值处理错误。 - -v1.0.0 2015年03月30日 -第一个版本 \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt.meta deleted file mode 100644 index fb72491..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/CHANGELOG.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: be3fe4ee249c5274693e7b6f8053e861 -timeCreated: 1470364015 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc.meta deleted file mode 100644 index 4cfc5a7..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc.meta +++ /dev/null @@ -1,5 +0,0 @@ -fileFormatVersion: 2 -guid: 67edfc4b640373846b14362bf8769576 -folderAsset: yes -DefaultImporter: - userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials.meta deleted file mode 100644 index 5432a89..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: ee1eae11fbe87b04193ab2c3d15ba2b3 -folderAsset: yes -timeCreated: 1481715983 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat deleted file mode 100644 index dd83212..0000000 Binary files a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat and /dev/null differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat.meta deleted file mode 100644 index 7df12f9..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/Materials/logo.mat.meta +++ /dev/null @@ -1,4 +0,0 @@ -fileFormatVersion: 2 -guid: 953e2ba39b9a2d54388919b75877efb7 -NativeFormatImporter: - userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc deleted file mode 100644 index eb0e80d..0000000 Binary files a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc and /dev/null differ diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc.meta deleted file mode 100644 index a39f42e..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.doc.meta +++ /dev/null @@ -1,4 +0,0 @@ -fileFormatVersion: 2 -guid: f05e875da3e1b3844b2360d177d617c9 -DefaultImporter: - userData: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md deleted file mode 100644 index 20212ec..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md +++ /dev/null @@ -1,284 +0,0 @@ -## C# API -### LuaEnv类 -#### object[] DoString(string chunk, string chunkName = "chuck", LuaTable env = null) -描述: - - 执行一个代码块。 - -参数: - - chunk: Lua代码; - chunkName: 发生error时的debug显示信息中使用,指明某某代码块的某行错误; - env :为这个代码块; -返回值: - - 代码块里return语句的返回值; - 比如:return 1, “hello”,DoString返回将包含两个object, 一个是double类型的1, 一个是string类型的“hello” - -例如: - - LuaEnv luaenv = new LuaEnv(); - object[] ret = luaenv.DoString("print(‘hello’)\r\nreturn 1") - UnityEngine.Debug.Log("ret="+ret[0]); - luaenv.Dispose() - -#### T LoadString(string chunk, string chunkName = "chunk", LuaTable env = null) - -描述: - - 加载一个代码块,但不执行,只返回类型可以指定为一个delegate或者一个LuaFunction - -参数: - - chunk: Lua代码; - chunkName: 发生error时的debug显示信息中使用,指明某某代码块的某行错误; - env :为这个代码块; - -返回值: - - 代表该代码块的delegate或者LuaFunction类; - -#### LuaTable Global; - -描述: - - 代表lua全局环境的LuaTable - -### void Tick() - -描述: - - 清除Lua的未手动释放的LuaBase(比如,LuaTable, LuaFunction),以及其它一些事情。 - 需要定期调用,比如在MonoBehaviour的Update中调用。 - -### void AddLoader(CustomLoader loader) - -描述: - - 增加一个自定义loader - -参数: - - loader:就一个回调,其类型为delegate byte[] CustomLoader(ref string filepath),当一个文件被require时,这个loader会被回调,其参数是require的参数,如果该loader找到文件,可以将其读进内存,返回一个byte数组。如果需要支持调试的话,而filepath要设置成IDE能找到的路径(相对或者绝对都可以) - -#### void Dispose() - -描述: - - Dispose该LuaEnv。 - -> LuaEnv的使用建议:全局就一个实例,并在Update中调用GC方法,完全不需要时调用Dispose - -### LuaTable类 - -#### T Get(string key) - -描述: - - 获取在key下,类型为T的value,如果不存在或者类型不匹配,返回null; - - -#### T GetInPath(string path) - -描述: - - 和Get的区别是,这个会识别path里头的“.”,比如var i = tbl.GetInPath(“a.b.c”)相当于在lua里头执行i = tbl.a.b.c - -#### void SetInPath(string path, T val) - -描述: - - 和GetInPaht对应的setter; - -#### void Get(TKey key, out TValue value) - -描述: - - 上面的API的Key都只能是string,而这个API无此限制; - -#### void Set(TKey key, TValue value) - -描述: - - 对应Get的setter; - -#### T Cast() - -描述: - - 把该table转成一个T指明的类型,可以是一个加了CSharpCallLua声明的interface,一个有默认构造函数的class或者struct,一个Dictionary,List等等。 - -#### void SetMetaTable(LuaTable metaTable) - -描述: - - 设置metaTable为table的metatable - -### LuaFunction类 - -> 注意:用该类访问Lua函数会有boxing,unboxing的开销,为了性能考虑,需要频繁调用的地方不要用该类。建议通过table.Get获取一个delegate再调用(假设ABCDelegate是C#的一个delegate)。在使用使用table.Get之前,请先把ABCDelegate加到代码生成列表。 - -#### object[] Call(params object[] args) - -描述: - - 以可变参数调用Lua函数,并返回该调用的返回值。 - -#### object[] Call(object[] args, Type[] returnTypes) - -描述: - - 调用Lua函数,并指明返回参数的类型,系统会自动按指定类型进行转换。 - -#### void SetEnv(LuaTable env) - -描述: - - 相当于lua的setfenv函数。 - -## Lua API - -### CS对象 - -#### CS.namespace.class(...) - -描述: - - 新建一个C#对象实例 - -例如: - - local v1=CS.UnityEngine.Vector3(1,1,1) - -#### CS.namespace.class.field - -描述: - - 访问一个C#静态成员 - -例如: - - Print(CS.UnityEngine.Vector3.one) - - -#### CS.namespace.enum.field - -描述: - - 访问一个枚举值 - -#### typeof函数 - -描述: - - 类似C#里头的typeof关键字,返回一个Type对象,比如GameObject.AddComponent其中一个重载需要一个Type参数 - -例如: - - newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem)) - - -#### 无符号64位支持 - -##### uint64.tostring - -描述: - - 无符号数转字符串。 - -##### uint64.divide - -描述: - - 无符号数除法。 - -##### uint64.compare - -描述: - - 无符号比较,相对返回0,大于返回正数,小于返回负数。 - -##### uint64.remainder - -描述: - - 无符号数取模。 - -##### uint64.parse - -描述: - 字符串转无符号数。 - -#### xlua.structclone - -描述: - - 克隆一个c#结构体 - -#### cast函数 - -描述: - - 指明以特定的接口访问对象,这在实现类无法访问的时候(比如internal修饰)很有用,这时可以这么来(假设下面的calc对象实现了C#的PerformentTest.ICalc接口) - -例如: - - cast(calc, typeof(CS.PerformentTest.ICalc)) - -然后就木有其它API了 -访问csharp对象和访问一个table一样,调用函数跟调用lua函数一样,也可以通过操作符访问c#的操作符,下面是一个例如: - - local v1=CS.UnityEngine.Vector3(1,1,1) - local v2=CS.UnityEngine.Vector3(1,1,1) - v1.x = 100 - v2.y = 100 - print(v1, v2) - local v3 = v1 + v2 - print(v1.x, v2.x) - print(CS.UnityEngine.Vector3.one) - print(CS.UnityEngine.Vector3.Distance(v1, v2)) - -## 类型映射 - -### 基本数据类型 - - -|C#类型|Lua类型| -|-|-| -|sbyte,byte,short,ushort,int,uint,double,char,float|number| -|decimal|userdata| -|long,ulong|userdata/lua_Integer(lua53)| -|bytes[]|string| -|bool|boolean| -|string|string| - -### 复杂数据类型 - -|C#类型|Lua类型| -|-|-| -|LuaTable|table| -|LuaFunction|function| -|class或者 struct的实例|userdata,table| -|method,delegate|function| - -#### LuaTable: - -C#侧指明从Lua侧输入(包括C#方法的输入参数或者Lua方法的返回值)LuaTable类型,则要求Lua侧为table。或者Lua侧的table,在C#侧未指明类型的情况下转换成LuaTable。 - -#### LuaFunction: - -C#侧指明从Lua侧输入(包括C#方法的输入参数或者Lua方法的返回值)LuaFunction类型,则要求Lua侧为function。或者Lua侧的function,在C#侧未指明类型的情况下转换成LuaFunction。 - -#### LuaUserData: - -对应非C# Managered对象的lua userdata。 - -#### class或者 struct的实例: - -从C#传一个class或者struct的实例,将映射到Lua的userdata,并通过__index访问该userdata的成员 -C#侧指明从Lua侧输入指定类型对象,Lua侧为该类型实例的userdata可以直接使用;如果该指明类型有默认构造函数,Lua侧是table则会自动转换,转换规则是:调用构造函数构造实例,并用table对应字段转换到c#对应值后赋值各成员。 - -#### method, delegate: - -成员方法以及delegate都是对应lua侧的函数。 -C#侧的普通参数以及引用参数,对应lua侧函数参数;C#侧的返回值对应于Lua的第一个返回值;引用参数和out参数则按序对应于Lua的第2到第N个参数。 \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md.meta deleted file mode 100644 index acef135..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua_API.md.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7bf061a839c69a5479d41d808b2fb8d2 -timeCreated: 1502329946 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc" deleted file mode 100644 index ade1ef9..0000000 Binary files "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc" and /dev/null differ diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc.meta" deleted file mode 100644 index d4a8285..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.doc.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 40e0633beaaf4dd49aca86e58539a814 -timeCreated: 1469709930 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md" deleted file mode 100644 index bb2bbd5..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md" +++ /dev/null @@ -1,128 +0,0 @@ -## What&Why - -XLua目前内置的扩展库: - -* 针对luajit的64位整数支持; -* 函数调用耗时以及内存泄漏定位工具; -* 用于支持ZeroBraneStudio的luasocket库; -* tdr 4 lua; - -随着使用项目的增加以及项目使用的深入程度,仅有这几个扩展已经没法满足项目组了,而由于各个项目对扩展差异化比较大,以及手机平台对安装包大小的敏感,XLua是无法通过预集成去满足这些需求,这也是这篇教程的由来。 - -这篇教程,将以lua-rapidjson为例,一步步的讲述怎么往xLua添加c/c++扩展,当然,会添加了,自然删除也就会了,项目组可以自行删除不需要用到的预集成扩展。 - -## How - -分三步 - -1. 修改build文件、工程设置,把要集成的扩展编译到XLua Plugin里头; -2. 调用xLua的C# API,使得扩展可以被按需(在lua代码里头require的时候)加载; -3. 可选,如果你的扩展里头需要用到64位整数,你可以通过XLua的64位扩展库来实现和C#的配合。 - -### 一、添加扩展&编译 - -准备工作 - -1. 把xLua的C源码包解压到你Unity工程的Assets同级目录下。 - - 下载lua-rapidjson代码,按你的习惯放置。本教程是把rapidjson头文件放到$UnityProj\build\lua-rapidjson\include目录下,而扩展的源码rapidjson.cpp放到$UnityProj\build\lua-rapidjson\source目录下(注:$UnityProj指的是你工程的目录) - -2. 在CMakeLists.txt加入扩展 - - xLua的各平台Plugins编译使用cmake编译,好处是所有平台的编译都写在一个makefile,大部分编译处理逻辑是跨平台的。 - - xLua配套的CMakeLists.txt为第三方扩展提供了扩展点(都是list): - - 1. THIRDPART_INC:第三方扩展的头文件搜索路径。 - 2. THIRDPART_SRC:第三方扩展的源代码。 - 3. THIRDPART_LIB:第三方扩展依赖的库。 - - 如下是rapidjson的加法 - - #begin lua-rapidjson - set (RAPIDJSON_SRC lua-rapidjson/source/rapidjson.cpp) - set_property( - SOURCE ${RAPIDJSON_SRC} - APPEND - PROPERTY COMPILE_DEFINITIONS - LUA_LIB - ) - list(APPEND THIRDPART_INC lua-rapidjson/include) - set (THIRDPART_SRC ${THIRDPART_SRC} ${RAPIDJSON_SRC}) - #end lua-rapidjson - - 完整代码请见附件。 - -3. 各平台编译 - - 所有编译脚本都是按这个方式命名:make_平台_lua版本.后缀。 - - 比如windows 64位lua53版本是make_win64_lua53.bat,android的luajit版本是make_android_luajit.sh,要编译哪个版本就执行相应的脚本即可。 - - 执行完编译脚本会自动拷贝到plugin_lua53或者plugin_luajit目录,前者是lua53版本放置路径,后者是luajit。 - - 配套的android脚本是在linux下使用的,脚本开头的NDK路径要根据实际情况修改。 - -### 二、C#侧集成 - -所有lua的C扩展库都会提供个luaopen_xxx的函数,xxx是动态库的名字,比如lua-rapidjson库该函数是luaopen_rapidjson,这类函数由lua虚拟机在加载动态库时自动调用,而在手机平台,由于ios的限制我们加载不了动态库,而是直接编译进进程里头。 - -为此,XLua提供了一个API来替代这功能(LuaEnv的成员方法): - - public void AddBuildin(string name, LuaCSFunction initer) - -参数: - - name:buildin模块的名字,require时输入的参数; - initer:初始化函数,原型是这样的public delegate int lua_CSFunction(IntPtr L),必须是静态函数,而且带MonoPInvokeCallbackAttribute属性修饰,这个api会检查这两个条件。 - -我们以luaopen_rapidjson的调用来看看怎么使用。 - -扩展LuaDLL.Lua类,用pinvoke把luaopen_rapidjson导出到C#,然后写一个符合lua_CSFunction定义的静态函数,你可以在里头做写初始化工作,比如luaopen_rapidjson的调用,以下是完整代码: - - namespace LuaDLL - { - public partial class Lua - { - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaopen_rapidjson(System.IntPtr L); - - [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))] - public static int LoadRapidJson(System.IntPtr L) - { - return luaopen_rapidjson(L); - } - } - } - -然后调用AddBuildin: - - luaenv.AddBuildin("rapidjson", LuaDLL.Lua.LoadRapidJson); - -然后就ok了,在lua代码中试试该扩展: - - local rapidjson = require('rapidjson') - local t = rapidjson.decode('{"a":123}') - print(t.a) - t.a = 456 - local s = rapidjson.encode(t) - print('json', s) - -### 三、64位改造 - -把i64lib.h文件include到需要64位改造的文件里头。 -该头文件的API就以下几个: - - //往栈上放一个int64/uint64 - void lua_pushint64(lua_State* L, int64_t n); - void lua_pushuint64(lua_State* L, uint64_t n); - //判断栈上pos位置是否是int64/uint64 - int lua_isint64(lua_State* L, int pos); - int lua_isuint64(lua_State* L, int pos); - //从栈上pos位置取一个int64/uint64 - int64_t lua_toint64(lua_State* L, int pos); - uint64_t lua_touint64(lua_State* L, int pos); - -这些API的使用依情况而定,可以看看本文附带的附件(rapidjson.cpp文件) - -编译工程相关修改 \ No newline at end of file diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md.meta" deleted file mode 100644 index dd3194d..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\242\236\345\212\240\345\210\240\351\231\244\347\254\254\344\270\211\346\226\271lua\345\272\223.md.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4eabbea9a5068f9448bbd56c1e6dea28 -timeCreated: 1502329945 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc" deleted file mode 100644 index 89ccb48..0000000 Binary files "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc" and /dev/null differ diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc.meta" deleted file mode 100644 index b87083e..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.doc.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 11d97e567c78f3147b86070c103f3d2d -timeCreated: 1472455442 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md" deleted file mode 100644 index 4e84c0f..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md" +++ /dev/null @@ -1,14 +0,0 @@ -## 复杂值类型的gc问题 - -xLua复杂值类型(struct)的默认传递方式是引用传递,这种方式要求先对值类型boxing,传递给lua,lua使用后释放该引用。由于值类型每次boxing将产生一个新对象,当lua侧使用完毕释放该对象的引用时,则产生一次gc。 -为此,xLua实现了一套struct的gc优化方案,您只要通过简单的配置,则可以实现满足条件的struct传递到lua侧无gc。 - -## struct需要满足什么条件? - -1. struct允许嵌套其它struct,但它以及它嵌套的struct只能包含这几种基本类型:byte、sbyte、short、ushort、int、uint、long、ulong、float、double;例如UnityEngine定义的大多数值类型:Vector系列,Quaternion,Color。。。均满足条件,或者用户自定义的一些struct -2. 该struct配置了GCOptimize属性(对于常用的UnityEngine的几个struct,Vector系列,Quaternion,Color。。。均已经配置了该属性),这个属性可以通过配置文件或者C# Attribute实现; -3. 使用到该struct的地方,需要添加到生成代码列表; - -## 如何配置? - -见`XLua的配置.md`的GCOptimize章节。 \ No newline at end of file diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md.meta" deleted file mode 100644 index 9ef8cee..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\345\244\215\346\235\202\345\200\274\347\261\273\345\236\213\357\274\210struct\357\274\211gc\344\274\230\345\214\226\346\214\207\345\215\227.md.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 597c4d1a24f97de42a3a0e3072be5880 -timeCreated: 1502329946 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc" deleted file mode 100644 index 7bb6e3e..0000000 Binary files "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc" and /dev/null differ diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc.meta" deleted file mode 100644 index a02085b..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.doc.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5e83c211c4c43834b9c8027b7480ab5f -timeCreated: 1462265117 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md" deleted file mode 100644 index 54a0d6d..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md" +++ /dev/null @@ -1,36 +0,0 @@ -XLua内置两个小工具进行性能方面问题的分析:一个是Lua函数,Lua调用C#函数的时长(不一定等同于CPU耗时,比如协程yield出去那段时间也会被算入调用时间)分析工具;一个是内存泄漏定位工具。 - -## 函数调用时长分析工具 - -### 典型使用案例: - -说明: - -api很简单,就三个,start和stop都是无参数,也很好理解,分别是统计开始以及结束。在start以及stop之间可以多次调用report(也可以考虑不调stop)。每次report会得到从start到调用report为止的函数时长统计报告(以字符串返回)。report函数只有一个可选参数,可以指明按照总时间(参数是字符串的”TOTAL”,这个是默认值),平均每次调用时间(“AVERAGE”),以及调用次数(“CALLED”)来排序。 -典型的一个时长统计报告如下: - -第一列是函数名 - -第二列是源代码,如果是lua文件将会统计到文件,行号,如果是C#的导出代码,将会标注[C#],如果是C函数,标准为[C]。 - -后面几列分别是总时间,平均每次调用时间,占总统计时间的百分比,以及调用次数。 - -## 内存泄漏定位工具 - -### 典型使用案例: - -说明: - -api就两个,total获取lua虚拟机的内存占用,单位是Kbytes,以lua number返回。而snapshot返回当前内存快照信息,一个典型的快照报告如下: - -第一列是table变量名; - -第二列是table的大小,如果该table下有子table也会被统计到; - -第三列是变量的类型,UPVALUE代表是闭包里头的变量(内层函数对外层local变量的引用),GLOBAL是全局变量,REGISTRY是C侧(包含虚拟机内部的)的一些私有数据。一般主要关注前面两种; - -第四列是变量的ID,其实就是内存指针,如果两次报告间没被重新分配,该ID是不变的,便于识别是否同一table; - -最后一列是一些附加信息,比如闭包变量可能存在很多同名的,这里会通过有那些函数引用了该变量来协助定位。 - -如何定位内存泄漏:通过memory.total检测出内存的持续增长,然后通过memory.snapshot定位出哪里泄漏(lua测的内存泄漏都是表现为往某table添加了数据忘了删除)。 \ No newline at end of file diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md.meta" deleted file mode 100644 index f416b7d..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\200\247\350\203\275\345\210\206\346\236\220\345\267\245\345\205\267.md.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 468ab13ad6def6249a6580591d0f51f7 -timeCreated: 1502329945 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc" deleted file mode 100644 index 07a89f0..0000000 Binary files "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc" and /dev/null differ diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc.meta" deleted file mode 100644 index 1922736..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.doc.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 9678cc58c9b40e147b514f7f5122ee20 -timeCreated: 1456291064 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md" deleted file mode 100644 index 80643f7..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md" +++ /dev/null @@ -1,289 +0,0 @@ -## xLua教程 - -### Lua文件加载 - -1. 执行字符串 - - 最基本是直接用LuaEnv.DoString执行一个字符串,当然,字符串得符合Lua语法 - 比如: - - luaenv.DoString("print('hello world')") - - 完整代码见XLua\Tutorial\LoadLuaScript\ByString目录 - > 但这种方式并不建议,更建议下面介绍这种方法。 - -2. 加载Lua文件 - - 用lua的require函数即可 - 比如: - - DoString("require 'byfile'") - - 完整代码见XLua\Tutorial\LoadLuaScript\ByFile目录 - - require实际上是调一个个的loader去加载,有一个成功就不再往下尝试,全失败则报文件找不到。 - 目前xLua除了原生的loader外,还添加了从Resource加载的loader,需要注意的是因为Resource只支持有限的后缀,放Resources下的lua文件得加上txt后缀(见附带的例子)。 - - 建议的加载Lua脚本方式是:整个程序就一个DoString("require 'main'"),然后在main.lua加载其它脚本(类似lua脚本的命令行执行:lua main.lua)。 - - 有童鞋会问:要是我的Lua文件是下载回来的,或者某个自定义的文件格式里头解压出来,或者需要解密等等,怎么办?问得好,xLua的自定义Loader可以满足这些需求。 - -3. 自定义Loader - - 在xLua加自定义loader是很简单的,只涉及到一个接口: - - public delegate byte[] CustomLoader(ref string filepath); - public void LuaEnv.AddLoader(CustomLoader loader) - - 通过AddLoader可以注册个回调,该回调参数是字符串,lua代码里头调用require时,参数将会透传给回调,回调中就可以根据这个参数去加载指定文件,如果需要支持调试,需要把filepath修改为真实路径传出。该回调返回值是一个byte数组,如果为空表示该loader找不到,否则则为lua文件的内容。 - 有了这个就简单了,用IIPS的IFS?没问题。写个loader调用IIPS的接口读文件内容即可。文件已经加密?没问题,自己写loader读取文件解密后返回即可。。。 - 完整示例见XLua\Tutorial\LoadLuaScript\Loader - -### C#访问Lua - -这里指的是C#主动发起对Lua数据结构的访问。 -本章涉及到的例子都可以在XLua\Tutorial\CSharpCallLua下找到。 - -1. 获取一个全局基本数据类型 - 访问LuaEnv.Global就可以了,上面有个模版Get方法,可指定返回的类型。 - - luaenv.Global.Get("a") - luaenv.Global.Get("b") - luaenv.Global.Get("c") - -2. 访问一个全局的table - - 也是用上面的Get方法,那类型要指定成啥呢? - 1. 映射到普通class或struct - - 定义一个class,有对应于table的字段的public属性,而且有无参数构造函数即可,比如对于{f1 = 100, f2 = 100}可以定义一个包含public int f1;public int f2;的class。 - 这种方式下xLua会帮你new一个实例,并把对应的字段赋值过去。 - - table的属性可以多于或者少于class的属性。可以嵌套其它复杂类型。 - 要注意的是,这个过程是值拷贝,如果class比较复杂代价会比较大。而且修改class的字段值不会同步到table,反过来也不会。 - - 这个功能可以通过把类型加到GCOptimize生成降低开销,详细可参见配置介绍文档。 - 那有没有引用方式的映射呢?有,下面这个就是: - - 2. 映射到一个interface - - 这种方式依赖于生成代码(如果没生成代码会抛InvalidCastException异常),代码生成器会生成这个interface的实例,如果get一个属性,生成代码会get对应的table字段,如果set属性也会设置对应的字段。甚至可以通过interface的方法访问lua的函数。 - - 3. 更轻量级的by value方式:映射到Dictionary<>,List<> - - 不想定义class或者interface的话,可以考虑用这个,前提table下key和value的类型都是一致的。 - - 4. 另外一种by ref方式:映射到LuaTable类 - - 这种方式好处是不需要生成代码,但也有一些问题,比如慢,比方式2要慢一个数量级,比如没有类型检查。 - -3. 访问一个全局的function - - 仍然是用Get方法,不同的是类型映射。 - 1. 映射到delegate - - 这种是建议的方式,性能好很多,而且类型安全。缺点是要生成代码(如果没生成代码会抛InvalidCastException异常)。 - - delegate要怎样声明呢? - 对于function的每个参数就声明一个输入类型的参数。 - 多返回值要怎么处理?从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数。 - - 参数、返回值类型支持哪些呢?都支持,各种复杂类型,out,ref修饰的,甚至可以返回另外一个delegate。 - - delegate的使用就更简单了,直接像个函数那样用就可以了。 - - 2. 映射到LuaFunction - - 这种方式的优缺点刚好和第一种相反。 - 使用也简单,LuaFunction上有个变参的Call函数,可以传任意类型,任意个数的参数,返回值是object的数组,对应于lua的多返回值。 - -4. 使用建议 - - 1. 访问lua全局数据,特别是table以及function,代价比较大,建议尽量少做,比如在初始化时把要调用的lua function获取一次(映射到delegate)后,保存下来,后续直接调用该delegate即可。table也类似。 - - 2. 如果lua测的实现的部分都以delegate和interface的方式提供,使用方可以完全和xLua解耦:由一个专门的模块负责xlua的初始化以及delegate、interface的映射,然后把这些delegate和interface设置到要用到它们的地方。 - -### Lua调用C# - -> 本章节涉及到的实例均在XLua\Tutorial\LuaCallCSharp下 - -#### new C#对象 - -你在C#这样new一个对象: - - var newGameObj = new UnityEngine.GameObject(); - -对应到Lua是这样: - - local newGameObj = CS.UnityEngine.GameObject() - -基本类似,除了: - - 1. lua里头没有new关键字; - 2. 所有C#相关的都放到CS下,包括构造函数,静态成员属性、方法; - -如果有多个构造函数呢?放心,xlua支持重载,比如你要调用GameObject的带一个string参数的构造函数,这么写: - - local newGameObj2 = CS.UnityEngine.GameObject('helloworld') - -#### 访问C#静态属性,方法 - -##### 读静态属性 - - CS.UnityEngine.Time.deltaTime - -##### 写静态属性 - - CS.UnityEngine.Time.timeScale = 0.5 - -##### 调用静态方法 - - CS.UnityEngine.GameObject.Find('helloworld') - -小技巧:如果需要经常访问的类,可以先用局部变量引用后访问,除了减少敲代码的时间,还能提高性能: - - local GameObject = CS.UnityEngine.GameObject - GameObject.Find('helloworld') - -#### 访问C#成员属性,方法 - -##### 读成员属性 - - testobj.DMF - -##### 写成员属性 - - testobj.DMF = 1024 - -##### 调用成员方法 - -注意:调用成员方法,第一个参数需要传该对象,建议用冒号语法糖,如下 - - testobj:DMFunc() - -##### 父类属性,方法 - -xlua支持(通过派生类)访问基类的静态属性,静态方法,(通过派生类实例)访问基类的成员属性,成员方法 - -##### 参数的输入输出属性(out,ref) - -Lua调用测的参数处理规则:C#的普通参数算一个输入形参,ref修饰的算一个输入形参,out不算,然后从左往右对应lua 调用测的实参列表; - -Lua调用测的返回值处理规则:C#函数的返回值(如果有的话)算一个返回值,out算一个返回值,ref算一个返回值,然后从左往右对应lua的多返回值。 - -##### 重载方法 -直接通过不同的参数类型进行重载函数的访问,例如: - - testobj:TestFunc(100) - testobj:TestFunc('hello') - -将分别访问整数参数的TestFunc和字符串参数的TestFunc。 - -注意:xlua只一定程度上支持重载函数的调用,因为lua的类型远远不如C#丰富,存在一对多的情况,比如C#的int,float,double都对应于lua的number,上面的例子中TestFunc如果有这些重载参数,第一行将无法区分开来,只能调用到其中一个(生成代码中排前面的那个) - -##### 操作符 - -支持的操作符有:+,-,*,/,==,一元-,<,<=, %,[] - -##### 参数带默认值的方法 - -和C#调用有默认值参数的函数一样,如果所给的实参少于形参,则会用默认值补上。 - -##### 可变参数方法 -对于C#的如下方法: - - void VariableParamsFunc(int a, params string[] strs) - -可以在lua里头这样调用: - - testobj:VariableParamsFunc(5, 'hello', 'john') - -##### 使用Extension methods - -在C#里定义了,lua里就能直接使用。 - -##### 泛化(模版)方法 - -不直接支持,可以通过Extension methods功能进行封装后调用。 - -##### 枚举类型 - -枚举值就像枚举类型下的静态属性一样。 - - testobj:EnumTestFunc(CS.Tutorial.TestEnum.E1) - -上面的EnumTestFunc函数参数是Tutorial.TestEnum类型的 -另外,如果枚举类加入到生成代码的话,枚举类将支持__CastFrom方法,可以实现从一个整数或者字符串到枚举值的转换,例如: - - CS.Tutorial.TestEnum.__CastFrom(1) - CS.Tutorial.TestEnum.__CastFrom('E1') - -##### delegate使用(调用,+,-) - -C#的delegate调用:和调用普通lua函数一样 - -+操作符:对应C#的+操作符,把两个调用串成一个调用链,右操作数可以是同类型的C# delegate或者是lua函数。 - --操作符:和+相反,把一个delegate从调用链中移除。 - -> Ps:delegate属性可以用一个luafunction来赋值。 - -##### event - -比如testobj里头有个事件定义是这样:public event Action TestEvent; - -增加事件回调 - - testobj:TestEvent('+', lua_event_callback) - -移除事件回调 - - testobj:TestEvent('-', lua_event_callback) - -##### 64位整数支持 - - Lua53版本64位整数(long,ulong)映射到原生的64未整数,而luaji版本t,相当于lua5.1的标准,本身不支持64位,xlua做了个64位支持的扩展库,C#的long和ulong都将映射到userdata: - - 支持在lua里头进行64位的运算,比较,打印 - - 支持和lua number的运算,比较 - - 要注意的是,在64扩展库中,实际上只有int64,ulong也会先强转成long再传递到lua,而对ulong的一些运算,比较,我们采取和java一样的支持方式,提供一组API,详情请看API文档。 - -##### C#复杂类型和table的自动转换 - -对于一个有无参构造函数的C#复杂类型,在lua侧可以直接用一个table来代替,该table对应复杂类型的public字段有相应字段即可,支持函数参数传递,属性赋值等,例如: -C#下B结构体(class也支持)定义如下: - - public struct A - { - public int a; - } - - public struct B - { - public A b; - public double c; - } - -某个类有成员函数如下: - - void Foo(B b) - -在lua可以这么调用 - - obj:Foo({b = {a = 100}, c = 200}) - -##### 获取类型(相当于C#的typeof) - -比如要获取UnityEngine.ParticleSystem类的Type信息,可以这样 - - typeof(CS.UnityEngine.ParticleSystem) - -##### “强”转 - -lua没类型,所以不会有强类型语言的“强转”,但有个有点像的东西:告诉xlua要用指定的生成代码去调用一个对象,这在什么情况下能用到呢?有的时候第三方库对外暴露的是一个interface或者抽象类,实现类是隐藏的,这样我们无法对实现类进行代码生成。该实现类将会被xlua识别为未生成代码而用反射来访问,如果这个调用是很频繁的话还是很影响性能的,这时我们就可以把这个interface或者抽象类加到生成代码,然后指定用该生成代码来访问: - - cast(calc, typeof(CS.Tutorial.Calc)) - -上面就是指定用CS.Tutorial.Calc的生成代码来访问calc对象。 diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md.meta" deleted file mode 100644 index a5a2ad7..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\346\225\231\347\250\213.md.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ba2597346b68fdd4c8aaf4b6f1b3da6f -timeCreated: 1502329946 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc" deleted file mode 100644 index 70e2432..0000000 Binary files "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc" and /dev/null differ diff --git "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc.meta" "b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc.meta" deleted file mode 100644 index 260bdc6..0000000 --- "a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/XLua\347\232\204\351\205\215\347\275\256.doc.meta" +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 57c6cf634c35eb146b95206d498cbf99 -timeCreated: 1480488641 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md deleted file mode 100644 index b561d47..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md +++ /dev/null @@ -1,130 +0,0 @@ -# xLua的配置 - -xLua所有的配置都支持三种方式:打标签;静态列表;动态列表。 - -配置有两必须两建议: - -* 列表方式均必须是static的字段/属性 -* 列表方式均必须放到一个static类 -* 建议不用标签方式 -* 建议列表方式配置放Editor目录 - -**打标签** - -xLua用白名单来指明生成哪些代码,而白名单通过attribute来配置,比如你想从lua调用c#的某个类,希望生成适配代码,你可以为这个类型打一个LuaCallCSharp标签: - -~~~csharp - -[LuaCallCSharp] -publicclassA -{ - -} - -~~~ - -该方式方便,但在il2cpp下会增加不少的代码量,不建议使用。 - -**静态列表** - -有时我们无法直接给一个类型打标签,比如系统api,没源码的库,或者实例化的泛化类型,这时你可以在一个静态类里声明一个静态字段,该字段的类型除BlackList和AdditionalProperties之外只要实现了IEnumerable<Type>就可以了(这两个例外后面具体会说),然后为这字段加上标签: - -~~~csharp - -[LuaCallCSharp] -public static List mymodule_lua_call_cs_list = new List() -{ - typeof(GameObject), - typeof(Dictionary), -}; - -~~~ - -这个字段需要放到一个 **静态类** 里头,建议放到 **Editor目录** 。 - -**动态列表** - -声明一个静态属性,打上相应的标签即可。 - -~~~csharp - -[Hotfix] -public static List by_property -{ - get - { - return (from type in Assembly.GetExecutingAssembly().GetTypes() - where type.Namespace == "XXXX" - select type).ToList(); - } -} - -~~~ - -Getter是代码,你可以实现很多效果,比如按名字空间配置,按程序集配置等等。 - -这个属性需要放到一个 **静态类** 里头,建议放到 **Editor目录** 。 - -### XLua.LuaCallCSharp - -一个C#类型加了这个配置,xLua会生成这个类型的适配代码(包括构造该类型实例,访问其成员属性、方法,静态属性、方法),否则将会尝试用性能较低的反射方式来访问。 - -一个类型的扩展方法(Extension Methods)加了这配置,也会生成适配代码并追加到被扩展类型的成员方法上。 - -xLua只会生成加了该配置的类型,不会自动生成其父类的适配代码,当访问子类对象的父类方法,如果该父类加了LuaCallCSharp配置,则执行父类的适配代码,否则会尝试用反射来访问。 - -反射访问除了性能不佳之外,在il2cpp下还有可能因为代码剪裁而导致无法访问,后者可以通过下面介绍的ReflectionUse标签来避免。 - -### XLua.ReflectionUse - -一个C#类型类型加了这个配置,xLua会生成link.xml阻止il2cpp的代码剪裁。 - -对于扩展方法,必须加上LuaCallCSharp或者ReflectionUse才可以被访问到。 - -建议所有要在Lua访问的类型,要么加LuaCallCSharp,要么加上ReflectionUse,这才能够保证在各平台都能正常运行。 - -### XLua.CSharpCallLua - -如果希望把一个lua函数适配到一个C# delegate(一类是C#侧各种回调:UI事件,delegate参数,比如List<T>:ForEach;另外一类场景是通过LuaTable的Get函数指明一个lua函数绑定到一个delegate)。或者把一个lua table适配到一个C# interface,该delegate或者interface需要加上该配置。 - -### XLua.GCOptimize - -一个C#纯值类型(注:指的是一个只包含值类型的struct,可以嵌套其它只包含值类型的struct)或者C#枚举值加上了这个配置。xLua会为该类型生成gc优化代码,效果是该值类型在lua和c#间传递不产生(C#)gc alloc,该类型的数组访问也不产生gc。各种无GC的场景,可以参考05\_NoGc例子。 - -除枚举之外,包含无参构造函数的复杂类型,都会生成lua table到该类型,以及改类型的一维数组的转换代码,这将会优化这个转换的性能,包括更少的gc alloc。 - -### XLua.AdditionalProperties - -这个是GCOptimize的扩展配置,有的时候,一些struct喜欢把field做成是私有的,通过property来访问field,这时就需要用到该配置(默认情况下GCOptimize只对public的field打解包)。 - -标签方式比较简单,配置方式复杂一点,要求是Dictionary<Type, List<string>>类型,Dictionary的Key是要生效的类型,Value是属性名列表。可以参考XLua对几个UnityEngine下值类型的配置,SysGCOptimize类。 - -### XLua.BlackList - -如果你不要生成一个类型的一些成员的适配代码,你可以通过这个配置来实现。 - -标签方式比较简单,对应的成员上加就可以了。 - -由于考虑到有可能需要把重载函数的其中一个重载列入黑名单,配置方式比较复杂,类型是List<List<string>>,对于每个成员,在第一层List有一个条目,第二层List是个string的列表,第一个string是类型的全路径名,第二个string是成员名,如果成员是一个方法,还需要从第三个string开始,把其参数的类型全路径全列出来。 - -例如下面是对GameObject的一个属性以及FileInfo的一个方法列入黑名单: - -~~~csharp - -[BlackList] -public static List> BlackList = new List>() { - new List(){"UnityEngine.GameObject", "networkView"}, - new List(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"}, -}; - -~~~ - -### 下面是生成期配置,必须放到Editor目录下 - -### CSObjectWrapEditor.GenPath - -配置生成代码的放置路径,类型是string。默认放在"Assets/XLua/Gen/"下。 - -### CSObjectWrapEditor.GenCodeMenu - -该配置用于生成引擎的二次开发,一个无参数函数加了这个标签,在执行"XLua/Generate Code"菜单时会触发这个函数的调用。 \ No newline at end of file diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md.meta deleted file mode 100644 index 5d8c727..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/configure.md.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 8e8a250c7dbdf6b48ae79313470374dc -timeCreated: 1498554474 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md deleted file mode 100644 index 7620e98..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md +++ /dev/null @@ -1,109 +0,0 @@ -## 生成引擎二次开发 - -xLua的生成引擎支持二次开发,你可以利用它来生成一些文本类型的文件(比如代码,配置等)。xLua本身的link.xml文件的生成就是一个生成引擎插件做的。其它应用场景,比如生成Lua IDE的自动完成配置文件,都可以用这特性来完成。 - -## 总体介绍 - -插件需要提供两个东西:1、生成文件的模版;2、一个回调函数,该回调函数接受用户的配置,返回需要注入到模版的数据以及文件的输出流。 - -## 模版语法 - -模版语法很简单,只有三种元素: - -* eval:语法是<%=exp%>,exp是任意表达式,将计算并以字符串形式输出exp的值; -* code:语法是<% if true then end%>,蓝色部分是任意lua代码,这些代码会执行; -* literal:除eval和code之外其它部分,literal原样输出。 - -示例: - -~~~xml -<% -require "TemplateCommon" -%> - - -<%ForEachCsList(assembly_infos, function(assembly_info)%> - - <%ForEachCsList(assembly_info.Types, function(type) - %> - <%end)%> - -<%end)%> - -~~~ - -TemplateCommon有一些预定义的函数可以使用,比如ForEachCsList,可以搜索下工程的TemplateCommon.lua.txt看下有那些函数可以用,就普通的lua而已,你自己写一套也可以。 - -## API - -~~~csharp -public static void CSObjectWrapEditor.Generator.CustomGen(string template_src, GetTasks get_tasks) -~~~ - -* template_src : 模版的源码; -* get_tasks : 回调函数,类型是GetTasks,用来接受用户的配置,返回需要注入到模版的数据以及文件的输出流; - -~~~csharp -public delegate IEnumerable GetTasks(LuaEnv lua_env, UserConfig user_cfg); -~~~ - -* lua_env : LuaEnv对象,因为返回的模版数据需要放到LuaTable,需要用到LuaEnv.NewTable; -* user_cfg : 用户的配置; -* return : 返回值中,CustomGenTask代表的是一个生成文件,而IEnumerable类型表示同一个模版可以生成多个文件; - -~~~csharp -public struct UserConfig -{ - public IEnumerable LuaCallCSharp; - public IEnumerable CSharpCallLua; - public IEnumerable ReflectionUse; -} -~~~ - -~~~csharp -public struct CustomGenTask -{ - public LuaTable Data; - public TextWriter Output; -} -~~~ - -示例: - -~~~csharp -public static IEnumerable GetTasks(LuaEnv lua_env, UserConfig user_cfg) -{ - LuaTable data = lua_env.NewTable(); - var assembly_infos = (from type in user_cfg.ReflectionUse - group type by type.Assembly.GetName().Name into assembly_info - select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList(); - data.Set("assembly_infos", assembly_infos); - - yield return new CustomGenTask - { - Data = data, - Output = new StreamWriter(GeneratorConfig.common_path + "/link.xml", - false, Encoding.UTF8) - }; -} -~~~ - -* 这里只生成一个文件,故只返回一个CustomGenTask; -* data就是模版要使用的数据,这里塞了一个assembly_infos字段,这个字段如何使用可以回头看看模版部分; - -## 标签 - -一般来说你可以通过MenuItem开一个菜单来执行触发自定义生成操作,但有时你希望生成操作直接由xLua的“Generate Code”菜单触发,你就需要用到CSObjectWrapEditor.GenCodeMenu - -示例: - -~~~csharp -[GenCodeMenu]//加到Generate Code菜单里头 -public static void GenLinkXml() -{ - Generator.CustomGen(ScriptableObject.CreateInstance().Template.text, GetTasks); -} -~~~ - - -ps:以上所有相关代码都在XLua\Src\Editor\LinkXmlGen目录下,也正是文章开头说的link.xml的生成功能的实现。 diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md.meta b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md.meta deleted file mode 100644 index 0512380..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/custom_generate.md.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6436d38981b6f5a4d8a2255ea3145ed1 -timeCreated: 1486519283 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/faq.md b/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/faq.md deleted file mode 100644 index 14998c1..0000000 --- a/AutofaceXlua/unity/AutoFaceAndXlua/Assets/3RD/XLua/Doc/faq.md +++ /dev/null @@ -1,261 +0,0 @@ -# FAQ - -## xLua发布包怎么用? - -xLua目前以zip包形式发布,在工程目录下解压即可。 - -## xLua可以放别的目录吗? - -可以,但生成代码目录需要配置一下(默认放Assets\XLua\Gen目录),具体可以看《XLua的配置.doc》的GenPath配置介绍。 - -## lua源码只能以txt后缀? - -什么后缀都可以。 - -如果你想以TextAsset打包到安装包(比如放到Resources目录),Unity不认lua后缀,这是Unity的规则。 - -如果你不打包到安装包,就没有后缀的限制:比如自行下载到某个目录(这也是热更的正确姿势),然后通过CustomLoader或者设置package.path去读这个目录。 - -那为啥xLua本身带的lua源码(包括示例)为什么都是txt结尾呢?因为xLua本身就一个库,不含下载功能,也不方便运行时去某个地方下载代码,通过TextAsset是较简单的方式。 - -## Plugins源码在哪里可以找到,怎么使用? - -Plugins源码位于xLua_Project_Root/build下。 - -源码编译依赖cmake,安装cmake后执行make_xxxx_yyyy.zz即可,xxxx代表平台,比如ios,android等,yyyy是要集成的虚拟机,有lua53和luajit两者,zz是后缀,windows下是bat,其它平台是sh。 - -windows编译依赖Visual Studio 2015。 - -android编译在linux下执行,依赖NDK,并且需要把脚本中ANDROID_NDK指向NDK的安装目录。 - -ios和osx需要在mac下编译。 - -## 报类似“xlua.access, no field __Hitfix0_Update”的错误怎么解决? - -按[Hotfix操作指南](hotfix.md)一步步操作。 - -## 报“please install the Tools” - -没有把Tools安装到Assets平级目录,安装包,或者master下都能找到这个目录。 - -## 报“This delegate/interface must add to CSharpCallLua : XXX”异常怎么解决? - -在编辑器下xLua不生成代码都可以运行,出现这种提示,要么是该类型没加CSharpCallLua,要么是加之前生成过代码,没重新执行生成。 - -解决办法,确认XXX(类型名)加上CSharpCallLua后,清除代码后运行。 - -如果编辑器下没问题,发布到手机报这错,表示你发布前没生成代码(执行“XLua/Generate Code”)。 - -## hotfix下怎么触发一个event - -首先通过xlua.private_accessible开启私有成员访问。 - -跟着通过对象的"&事件名"字段调用delegate,例如self\['&MyEvent'\](),其中MyEvent是事件名。 - -## 怎么对Unity Coroutine的实现函数打补丁? - -见[Hotfix操作指南](hotfix.md)相应章节。 - -## 支持NGUI(或者UGUI/DOTween等等)么? - -支持,xLua最主要的特性是让你原来用C#写的地方可以换成用lua写,你C#能用的插件,基本都能用。 - -## 如果需要调试,CustomLoader的filepath参数该如何处理? - -lua里头调用require 'a.b'时,CustomLoader会被调用,并传入字符串"a.b",你需要理解这字符串,(从文件/内存/网络等)加载好lua文件,返回两个东西,第一个是调试器可以理解的路径,比如:a/b.lua,这个通过设置ref类型的filepath参数返回,第二个是UTF8格式的源码的字节流(byte[]),通过返回值返回。 - -## 什么是生成代码? - -xLua支持的lua和C#间交互技术之一,这种技术通过生成两者间的适配代码来实现交互,性能较好,是推荐的方式。 - -另一种交互技术是反射,这种方式对安装包的影响更少,可以在性能要求不高或者对安装包大小很敏感的场景下使用。 - -## 改了接口后,之前生成的代码出现错误怎么办? - -清除掉生成代码(执行“Clear Generated Code”菜单,如果你重启过,会找不到这个菜单,这时你可以手动删除整个生成代码目录),等编译完成后重新生成。 - -## 应该什么时候生成代码? - -开发期不建议生成代码,可以避免很多由于不一致导致的编译失败,以及生成代码本身的编译等待。 - -build手机版本前必须执行生成代码,建议做成自动化的。 - -做性能调优,性能测试前必须执行生成代码,因为生成和不生成性能的区别还是很大的。 - -## CS名字空间下有所有C# API是不是很占内存? - -由于用了lazyload,这个“有”只是个虚拟的概念,比如UnityEngine.GameObject,是访问第一次CS.UnityEngine.GameObject或者第一个实例往lua传送才加载该类型方法,属性等。 - -## LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用? - -看调用者和被调用者,比如要在lua调用C#的GameObject.Find函数,或者调用gameobject的实例方法,属性等,GameObject类要加LuaCallSharp,而想把一个lua函数挂到UI回调,这是调用者是C#,被调用的是一个lua函数,所以回调声明的delegate要加CSharpCallLua。 - -有时会比较迷惑人,比如List.Find(Predicate match)的调用,List当然是加LuaCallSharp,而Predicate却要加CSharpCallLua,因为match的调用者在C#,被调用的是一个lua函数。 - -更无脑一点的方式是看到“This delegate/interface must add to CSharpCallLua : XXX”,就把XXX加到CSharpCallLua即可。 - -## 值类型传递会有gc alloc么? - -如果你使用的是delegate调用lua函数,或者用LuaTable、LuaFunction的无gc接口,或者数组的话,以下值类型都是没gc的: - -1、所有的基本值类型(所有整数,所有浮点数,decimal); - -2、所有的枚举类型; - -3、字段只包含值类型的struct,可嵌套其它只包含值类型struct; - -其中2、3需要把该类型加到GCOptimize。 - -## 反射在ios下可用吗? - -ios下的限制有两个:1、没有jit;2、代码剪裁(stripping); - -对于C#通过delegate或者interface调用lua,如果不生成代码是用反射的emit,这依赖jit,所以这目前只在编辑器可用。 - -对于lua调用C#,主要会被代码剪裁影响,这时你可以配置ReflectionUse(不要配LuaCallSharp),执行“Generate Code”,这时不会对该类生成封装代码,而是生成link.xml把该类配置为不剪裁。 - -简而言之,除了CSharpCallLua是必须的(这类生成代码往往不多),LuaCallSharp生成都可以改为用反射。 - -## 支持泛化方法的调用么? - -不直接支持,但能调用到。如果是静态方法,可以自己写个封装来实例化泛化方法。 - -如果是成员方法,xLua支持扩展方法,你可以添加一个扩展方法来实例化泛化方法。该扩展方法使用起来就和普通成员方法一样。 - -```csharp -// C# -public static Button GetButton(this GameObject go) -{ - return go.GetComponent