Beispiel #1
0
        public static int ComputeSubstanceTextureName(string filename)
        {
            var          memoryStream = new MemoryStream();
            BinaryWriter bw           = new BinaryWriter(memoryStream);

            bw.Write((int)186);
            bw.Write(System.Text.Encoding.ASCII.GetBytes(filename));

            using (HashAlgorithm hash = new MD4())
            {
                byte[] hashed = hash.ComputeHash(memoryStream.ToArray());

                int result = 0;

                for (int i = 3; i >= 0; --i)
                {
                    result <<= 8;
                    result  |= hashed[i];
                }

                return(result);
            }

            return(0);
        }
Beispiel #2
0
        public static int Compute(int id, string name)
        {
            var classID = System.Text.Encoding.UTF8.GetString(BitConverter.GetBytes(id));

            if (id < 255)
            {
                classID = ((char)id) + "\0\0\0";
            }

            string toBeHashed = classID + name;

            using (HashAlgorithm hash = new MD4())
            {
                byte[] hashed = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toBeHashed));

                int result = 0;

                for (int i = 3; i >= 0; --i)
                {
                    result <<= 8;
                    result  |= hashed[i];
                }

                return(result);
            }
        }
Beispiel #3
0
        public static int Compute(Type t)
        {
            string toBeHashed = "s\0\0\0" + t.Namespace + t.Name;

            using (HashAlgorithm hash = new MD4())
            {
                byte[] hashed = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toBeHashed));

                int result = 0;

                for (int i = 3; i >= 0; --i)
                {
                    result <<= 8;
                    result  |= hashed[i];
                }

                return(result);
            }
        }