转换DLL

///

// DllSwitcher
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;

public class DllSwitcher : EditorWindow
{
    private enum PathType
    {
        Reference,
        AbsolutePath
    }

    private enum DirectoryType
    {
        Root,
        SpecificDirectory
    }

    public const string DEFAULT_FILE_ID_OF_SCRIPT = "11500000";

    public Object dllFile;

    public Object replaceDir;

    public Object srcDir;

    private Dictionary<string, string> fileIDMappingTableFromDll;

    private Dictionary<string, string> guidMappingTableFromScripts;

    private string guidOfDllFile;

    private string dllFilePath;

    private const int PreLabelWidth = 140;

    private PathType dllInputPath;

    private DirectoryType srcDirectory;

    private DirectoryType resDirectory;

    [MenuItem("Window/DllSwitcher")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(DllSwitcher));
    }

    private void OnGUI()
    {
        //IL_0006: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
        //IL_0145: Unknown result type (might be due to invalid IL or missing references)
        EditorGUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
        EditorGUILayout.LabelField("Dll File", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(140f) });
        dllInputPath = (PathType)(object)EditorGUILayout.EnumPopup((Enum)dllInputPath, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
        EditorGUILayout.EndHorizontal();
        if (dllInputPath.Equals(PathType.Reference))
        {
            dllFile = EditorGUILayout.ObjectField(dllFile, typeof(Object), false, (GUILayoutOption[])(object)new GUILayoutOption[0]);
        }
        else
        {
            dllFilePath = EditorGUILayout.TextField(dllFilePath, (GUILayoutOption[])(object)new GUILayoutOption[0]);
        }
        EditorGUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
        EditorGUILayout.LabelField("Source Code Directory", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(140f) });
        srcDirectory = (DirectoryType)(object)EditorGUILayout.EnumPopup((Enum)srcDirectory, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
        EditorGUILayout.EndHorizontal();
        if (srcDirectory.Equals(DirectoryType.SpecificDirectory))
        {
            srcDir = EditorGUILayout.ObjectField(srcDir, typeof(Object), false, (GUILayoutOption[])(object)new GUILayoutOption[0]);
        }
        EditorGUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
        EditorGUILayout.LabelField("Replace Dirctory", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(140f) });
        resDirectory = (DirectoryType)(object)EditorGUILayout.EnumPopup((Enum)resDirectory, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
        EditorGUILayout.EndHorizontal();
        if (resDirectory.Equals(DirectoryType.SpecificDirectory))
        {
            replaceDir = EditorGUILayout.ObjectField(replaceDir, typeof(Object), false, (GUILayoutOption[])(object)new GUILayoutOption[0]);
        }
        if (GUILayout.Button("Replace From Dll To Src", (GUILayoutOption[])(object)new GUILayoutOption[0]))
        {
            replaceSriptReference(dllToSrc: true);
        }
        if (GUILayout.Button("Replace From Src To Dll", (GUILayoutOption[])(object)new GUILayoutOption[0]))
        {
            replaceSriptReference(dllToSrc: false);
        }
    }

    public void replaceSriptReference(bool dllToSrc)
    {
        if (resDirectory.Equals(DirectoryType.SpecificDirectory))
        {
            replaceSriptReferenceOfSelectDirectory(dllToSrc);
        }
        else
        {
            replaceSriptReferenceOfAllScripts(dllToSrc);
        }
    }

    public void replaceSriptReferenceOfSelectDirectory(bool dllToSrc = true)
    {
        string assetPath = AssetDatabase.GetAssetPath(replaceDir);
        initFileIDMappingTableOfDll(dllToSrc);
        InitGuidMappingTable(dllToSrc);
        ReplaceSriptReferenceOfPath(assetPath, dllToSrc);
    }

    public void replaceSriptReferenceOfAllScripts(bool dllToSrc = true)
    {
        initFileIDMappingTableOfDll(dllToSrc);
        InitGuidMappingTable(dllToSrc);
        ReplaceSriptReferenceOfPath(Application.get_dataPath(), dllToSrc);
    }

    private void ReplaceSriptReferenceOfPath(string path, bool dllToSrc = true)
    {
        List<string> list = FindAllFileWithSuffixs(path, new string[3] { ".asset", ".prefab", ".unity" });
        for (int i = 0; i < list.Count; i++)
        {
            EditorUtility.DisplayProgressBar("Replace Dll", list[i], (float)i * 1f / (float)list.Count);
            ReplaceScriptReference(list[i], dllToSrc);
        }
        AssetDatabase.Refresh();
        EditorUtility.ClearProgressBar();
    }

    private void initFileIDMappingTableOfDll(bool dllToSrc = true)
    {
        if (dllInputPath.Equals(PathType.Reference))
        {
            dllFilePath = AssetDatabase.GetAssetPath(dllFile);
        }
        fileIDMappingTableFromDll = new Dictionary<string, string>();
        Assembly assembly = Assembly.LoadFrom(dllFilePath);
        Type[] array = null;
        try
        {
            array = assembly.GetTypes();
        }
        catch (ReflectionTypeLoadException ex)
        {
            array = ex.Types.Where((Type t) => t != null).ToArray();
            Exception[] loaderExceptions = ex.LoaderExceptions;
            for (int i = 0; i < loaderExceptions.Length; i++)
            {
                Debug.LogWarning((object)loaderExceptions[i]);
            }
        }
        Type[] array2 = array;
        foreach (Type type in array2)
        {
            if (dllToSrc)
            {
                if (fileIDMappingTableFromDll.ContainsKey(FileIDUtil.Compute(type).ToString()))
                {
                    Debug.LogWarning((object)("Reduplicated GUID:" + FileIDUtil.Compute(type) + ";Script Name:" + type.Name));
                }
                else
                {
                    fileIDMappingTableFromDll[FileIDUtil.Compute(type).ToString()] = type.Name;
                }
            }
            else
            {
                fileIDMappingTableFromDll[type.Name] = FileIDUtil.Compute(type).ToString();
            }
        }
        if (!dllToSrc)
        {
            initGuidOfDllFile();
        }
    }

    private Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
    {
        Debug.LogWarning((object)("Need Loading:" + args.Name));
        return Assembly.ReflectionOnlyLoad(dllFilePath.Substring(0, dllFilePath.LastIndexOf("\\")) + "\\" + args.Name);
    }

    private void InitGuidMappingTable(bool dllToSrc)
    {
        if (srcDirectory.Equals(DirectoryType.SpecificDirectory))
        {
            InitGuidMappingTableOfSelectScripts(dllToSrc);
        }
        else
        {
            InitGuidMappingTableOfAllScripts(dllToSrc);
        }
    }

    private void InitGuidMappingTableOfAllScripts(bool dllToSrc = true)
    {
        guidMappingTableFromScripts = new Dictionary<string, string>();
        InitGuidMappingTableOfPath(Application.get_dataPath(), dllToSrc);
    }

    private void InitGuidMappingTableOfSelectScripts(bool dllToSrc = true)
    {
        guidMappingTableFromScripts = new Dictionary<string, string>();
        string assetPath = AssetDatabase.GetAssetPath(srcDir);
        InitGuidMappingTableOfPath(assetPath, dllToSrc);
    }

    private void InitGuidMappingTableOfPath(string path, bool dllToSrc = true)
    {
        foreach (string item in FindAllFileWithSuffixs(path, new string[2] { ".cs.meta", ".js.meta" }))
        {
            if (dllToSrc)
            {
                guidMappingTableFromScripts[getFileNameFromPath(item)] = GetGuidFromMeta(item);
            }
            else
            {
                guidMappingTableFromScripts[GetGuidFromMeta(item)] = getFileNameFromPath(item);
            }
        }
    }

    private void initGuidOfDllFile()
    {
        guidOfDllFile = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(dllFile));
    }

    private void ReplaceScriptReference(string filePath, bool dllToSrc = true)
    {
        Debug.Log((object)("Ready to replace:" + filePath));
        string[] array = File.ReadAllLines(filePath);
        int i = 0;
        bool flag = false;
        for (; i < array.Length; i++)
        {
            if (array[i].StartsWith("MonoBehaviour:"))
            {
                do
                {
                    i++;
                }
                while (!array[i].TrimStart().StartsWith("m_Script:"));
                flag = ((!dllToSrc) ? (flag | replaceGUIDAnfFileIDFromSrcToDll(ref array[i])) : (flag | replaceGUIDAnfFileIDFromDllToSrc(ref array[i])));
            }
        }
        if (flag)
        {
            File.WriteAllLines(filePath, array);
        }
    }

    private string GetGuidFromMeta(string filePath)
    {
        string result = "";
        using StreamReader streamReader = new StreamReader(filePath);
        while (!streamReader.EndOfStream)
        {
            string text = streamReader.ReadLine();
            if (text.StartsWith("guid:"))
            {
                result = text.Substring(text.IndexOf(":") + 2);
                break;
            }
        }
        streamReader.Close();
        return result;
    }

    private bool replaceGUIDAnfFileIDFromDllToSrc(ref string lineStr)
    {
        bool result = false;
        string fileIDFrommScriptReferenceLine = getFileIDFrommScriptReferenceLine(lineStr);
        if (fileIDFrommScriptReferenceLine == null || fileIDFrommScriptReferenceLine.Equals("11500000"))
        {
            return false;
        }
        if (fileIDMappingTableFromDll.TryGetValue(fileIDFrommScriptReferenceLine, out var value))
        {
            if (guidMappingTableFromScripts.TryGetValue(value, out var value2))
            {
                string gUIDFrommScriptReferenceLine = getGUIDFrommScriptReferenceLine(lineStr);
                Debug.Log((object)("Replacing script reference:" + value));
                lineStr = lineStr.Replace(fileIDFrommScriptReferenceLine, "11500000");
                lineStr = lineStr.Replace(gUIDFrommScriptReferenceLine, value2);
                result = true;
            }
            else
            {
                Debug.LogWarning((object)("Can't find the GUID of file:" + value));
            }
        }
        else
        {
            Debug.LogWarning((object)("Can't find the file of fileID:" + fileIDFrommScriptReferenceLine));
        }
        return result;
    }

    private bool replaceGUIDAnfFileIDFromSrcToDll(ref string lineStr)
    {
        bool result = false;
        string gUIDFrommScriptReferenceLine = getGUIDFrommScriptReferenceLine(lineStr);
        if (gUIDFrommScriptReferenceLine == null)
        {
            return false;
        }
        if (guidMappingTableFromScripts.TryGetValue(gUIDFrommScriptReferenceLine, out var value))
        {
            if (fileIDMappingTableFromDll.TryGetValue(value, out var value2))
            {
                Debug.Log((object)("Replacing script reference:" + value));
                lineStr = lineStr.Replace("11500000", value2);
                lineStr = lineStr.Replace(gUIDFrommScriptReferenceLine, guidOfDllFile);
                result = true;
            }
            else
            {
                Debug.LogWarning((object)("Can't find the GUID of file:" + value));
            }
        }
        else
        {
            Debug.LogWarning((object)("Can't find the file of GUID:" + gUIDFrommScriptReferenceLine));
        }
        return result;
    }

    private string getFileIDFrommScriptReferenceLine(string lineStr)
    {
        int num = lineStr.IndexOf("fileID:") + "fileID: ".Length;
        int num2 = lineStr.IndexOf(",") - num;
        if (num2 <= 0)
        {
            return null;
        }
        return lineStr.Substring(num, num2);
    }

    private string getGUIDFrommScriptReferenceLine(string lineStr)
    {
        int num = lineStr.IndexOf("guid:") + "guid: ".Length;
        int num2 = lineStr.LastIndexOf(",") - num;
        if (num2 <= 0)
        {
            return null;
        }
        return lineStr.Substring(num, num2);
    }

    private string getFileNameFromPath(string path)
    {
        string text = path.Substring(path.LastIndexOf("\\") + 1);
        return text.Substring(0, text.IndexOf("."));
    }

    private List<string> FindAllFileWithSuffixs(string path, string[] suffixs)
    {
        List<string> resultList = new List<string>();
        FindAllFileWithSuffixs(path, suffixs, ref resultList);
        return resultList;
    }

    private void FindAllFileWithSuffixs(string path, string[] suffixs, ref List<string> resultList)
    {
        if (File.Exists(path))
        {
            resultList.Add(path);
        }
        else
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            string[] files = Directory.GetFiles(path);
            foreach (string text in files)
            {
                foreach (string value in suffixs)
                {
                    if (text.EndsWith(value))
                    {
                        resultList.Add(text);
                        break;
                    }
                }
            }
            files = Directory.GetDirectories(path);
            foreach (string path2 in files)
            {
                FindAllFileWithSuffixs(path2, suffixs, ref resultList);
            }
        }
    }

    private void WriteDebugFile(string[] lines, string filename)
    {
    }
}

///

// FileIDUtil
using System;
using System.Security.Cryptography;
using System.Text;

public static class FileIDUtil
{
    public static int Compute(Type t)
    {
        string s = "s\0\0\0" + t.Namespace + t.Name;
        using HashAlgorithm hashAlgorithm = new MD4();
        byte[] array = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(s));
        int num = 0;
        for (int num2 = 3; num2 >= 0; num2--)
        {
            num <<= 8;
            num |= array[num2];
        }
        return num;
    }
}

///

// MD4
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

public class MD4 : HashAlgorithm
{
    private uint _a;

    private uint _b;

    private uint _c;

    private uint _d;

    private uint[] _x;

    private int _bytesProcessed;

    public MD4()
    {
        _x = new uint[16];
        Initialize();
    }

    public override void Initialize()
    {
        _a = 1732584193u;
        _b = 4023233417u;
        _c = 2562383102u;
        _d = 271733878u;
        _bytesProcessed = 0;
    }

    protected override void HashCore(byte[] array, int offset, int length)
    {
        ProcessMessage(Bytes(array, offset, length));
    }

    protected override byte[] HashFinal()
    {
        try
        {
            ProcessMessage(Padding());
            return new uint[4] { _a, _b, _c, _d }.SelectMany((uint word) => Bytes(word)).ToArray();
        }
        finally
        {
            Initialize();
        }
    }

    private void ProcessMessage(IEnumerable<byte> bytes)
    {
        foreach (byte @byte in bytes)
        {
            int num = _bytesProcessed & 0x3F;
            int num2 = num >> 2;
            int num3 = (num & 3) << 3;
            _x[num2] = (_x[num2] & (uint)(~(255 << num3))) | (uint)(@byte << num3);
            if (num == 63)
            {
                Process16WordBlock();
            }
            _bytesProcessed++;
        }
    }

    private static IEnumerable<byte> Bytes(byte[] bytes, int offset, int length)
    {
        for (int i = offset; i < length; i++)
        {
            yield return bytes[i];
        }
    }

    private IEnumerable<byte> Bytes(uint word)
    {
        yield return (byte)(word & 0xFFu);
        yield return (byte)((word >> 8) & 0xFFu);
        yield return (byte)((word >> 16) & 0xFFu);
        yield return (byte)((word >> 24) & 0xFFu);
    }

    private IEnumerable<byte> Repeat(byte value, int count)
    {
        for (int i = 0; i < count; i++)
        {
            yield return value;
        }
    }

    private IEnumerable<byte> Padding()
    {
        return Repeat(128, 1).Concat(Repeat(0, ((_bytesProcessed + 8) & 0x7FFFFFC0) + 55 - _bytesProcessed)).Concat(Bytes((uint)(_bytesProcessed << 3))).Concat(Repeat(0, 4));
    }

    private void Process16WordBlock()
    {
        uint num = _a;
        uint num2 = _b;
        uint num3 = _c;
        uint num4 = _d;
        int[] array = new int[4] { 0, 4, 8, 12 };
        foreach (int num5 in array)
        {
            num = Round1Operation(num, num2, num3, num4, _x[num5], 3);
            num4 = Round1Operation(num4, num, num2, num3, _x[num5 + 1], 7);
            num3 = Round1Operation(num3, num4, num, num2, _x[num5 + 2], 11);
            num2 = Round1Operation(num2, num3, num4, num, _x[num5 + 3], 19);
        }
        array = new int[4] { 0, 1, 2, 3 };
        foreach (int num6 in array)
        {
            num = Round2Operation(num, num2, num3, num4, _x[num6], 3);
            num4 = Round2Operation(num4, num, num2, num3, _x[num6 + 4], 5);
            num3 = Round2Operation(num3, num4, num, num2, _x[num6 + 8], 9);
            num2 = Round2Operation(num2, num3, num4, num, _x[num6 + 12], 13);
        }
        array = new int[4] { 0, 2, 1, 3 };
        foreach (int num7 in array)
        {
            num = Round3Operation(num, num2, num3, num4, _x[num7], 3);
            num4 = Round3Operation(num4, num, num2, num3, _x[num7 + 8], 9);
            num3 = Round3Operation(num3, num4, num, num2, _x[num7 + 4], 11);
            num2 = Round3Operation(num2, num3, num4, num, _x[num7 + 12], 15);
        }
        _a += num;
        _b += num2;
        _c += num3;
        _d += num4;
    }

    private static uint ROL(uint value, int numberOfBits)
    {
        return (value << numberOfBits) | (value >> 32 - numberOfBits);
    }

    private static uint Round1Operation(uint a, uint b, uint c, uint d, uint xk, int s)
    {
        return ROL(a + ((b & c) | (~b & d)) + xk, s);
    }

    private static uint Round2Operation(uint a, uint b, uint c, uint d, uint xk, int s)
    {
        return ROL(a + ((b & c) | (b & d) | (c & d)) + xk + 1518500249, s);
    }

    private static uint Round3Operation(uint a, uint b, uint c, uint d, uint xk, int s)
    {
        return ROL(a + (b ^ c ^ d) + xk + 1859775393, s);
    }
}

//

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
高斯投影转换 DLL 是一个用于进行高斯投影坐标转换的动态链接库(DLL)。高斯投影是一种常用的地理坐标系统,用于将地球表面上的点投影到平面上,以方便测量和计算。 这个 DLL 提供了一系列函数,可以实现不同高斯投影坐标系之间的转换。通过使用这些函数,开发人员可以将一个高斯投影坐标系的坐标转换为另一个高斯投影坐标系的坐标。具体来说,该 DLL 可以实现以下功能: 1. 高斯投影坐标系的创建和销毁:该 DLL 提供了函数来创建和销毁高斯投影坐标系对象。开发人员可以使用这些函数来创建一个特定高斯投影坐标系的实例,并在不需要时将其销毁。 2. 坐标转换:该 DLL 提供了函数来执行高斯投影坐标系之间的转换。开发人员可以使用这些函数将一个高斯投影坐标系的坐标转换为另一个高斯投影坐标系的坐标。这使得在不同的高斯投影坐标系之间进行坐标转换变得简单和高效。 3. 坐标计算:该 DLL 提供了函数来执行一些高斯投影坐标的计算,例如两点之间的距离计算、面积计算等。通过这些函数,开发人员可以方便地进行各种与高斯投影坐标有关的计算操作。 4. 精度控制:该 DLL 提供了函数来控制高斯投影坐标转换的精度。开发人员可以根据需求设置转换的精度级别,以确保转换结果的准确性。 总之,高斯投影转换 DLL 提供了一种方便和高效的方式来进行高斯投影坐标的转换和计算。通过使用这个 DLL,开发人员可以快速地实现各种高斯投影相关的功能,并提高工作效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值