RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Gump ID different in MONO? See here...

fwiffo

Sorceror
As for reference, I've picked up this code from .net:

http://referencesource.microsoft.com/netframework.aspx
where the "String.GetHashCode" is also referenced, for our purpose anyway you have to pick up the Gump.cs, in Server/Gumps folder, and change accordingly:

Original RunUO code to be changed, also mind that if you're using x64 machines, this could come handy even to non-unices users...
Code:
        public static int GetTypeID( Type type )
        {
            return type.FullName.GetHashCode();
        }

Modified code:
Code:
        public static int GetTypeID( Type type )
        {
            return GetHashCode32(type.FullName);
        }
 
        private static int GetHashCode32(string s)
        {
            unsafe
            {
                fixed (char *src = s)
                {
                    Contract.Assert(src[s.Length] == '\0', "src[this.Length] == '\\0'");
                    Contract.Assert( ((int)src)%4 == 0, "Managed string should start at 4 bytes boundary");
 
                    int hash1 = (5381<<16) + 5381;
                    int hash2 = hash1;
 
                    // 32 bit machines.
                    int* pint = (int *)src;
                    int len = s.Length;
                    while (len > 2)
                    {
                        hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
                        hash2 = ((hash2 << 5) + hash2 + (hash2 >> 27)) ^ pint[1];
                        pint += 2;
                        len  -= 4;
                    }
 
                    if (len > 0)
                    {
                        hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
                    }
                    return hash1 + (hash2 * 1566083941);
                }
            }
        }

that's all, simple uh?
 
Top