Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

MultiCore CheckSum.dat Generator

Joined
Aug 6, 2005
Messages
552
Reaction score
298
MultiCore CheckSum.dat Generator *Optimized*

Hi guys,
I was bored and tried the new Parallel feature of .NET on the CheckSum.dat Generator ;) Its pretty fast now, around 2.6s on my Intel i750.

Update: Optimized it a bit

How to use:
1. Copy the main.exe to this Generators Directory, or vice versa.
2. Run the Generator. It will automatically take the main.exe located in the same Directory, and also saves the CheckSum.dat in the same Directory. Note: It will overwrite an existing CheckSum.dat.
3. Use the generated CheckSum.dat for your Server.
4. Enjoy :)

To run this thing, you need .NET Framework 4 installed.

Source(C#):
Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading.Tasks;

namespace MainChecksumGen
{
    static class Program
    {
        static uint filesize;

        static void Main(string[] args)
        {
            CheckSumFile csf = new CheckSumFile();
            csf.Checksums = new uint[1024];
            byte[] lpFileBuffer;
            int ms = 0;
            try
            {
                using (FileStream fs = new FileStream("main.exe", FileMode.Open))
                {
                    lpFileBuffer = new byte[fs.Length];
                    fs.Read(lpFileBuffer, 0, lpFileBuffer.Length);
                }

                filesize = (uint)lpFileBuffer.Length;
                int start = Environment.TickCount;
                Parallel.For(0, 1024, i =>
                {
                    csf.Checksums[i] = GetChecksum(lpFileBuffer, (ushort)i);
                });

                ms = Environment.TickCount - start;
                using (FileStream ss = File.Create("CheckSum.dat"))
                {
                    ss.Write(Serialize(csf), 0, 4096);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Couldn't find main.exe. Make sure its in the same directory as the Program");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Completed in {0} ms. Saved to CheckSum.dat.\nPress Any Key to continue...", ms);

            Console.ReadKey();
        }

        static uint GetChecksum(byte[] lpFileBuffer, ushort wChecksumKey)
        {
            uint dwResult = (uint)wChecksumKey << 9;
            for (uint I = 0; I < filesize; I += 4)
            {
                uint dwKey = MakeDword(lpFileBuffer, I);
                switch (((I >> 2) + wChecksumKey) % 3)
                {
                    case 0:
                        dwResult ^= dwKey;
                        break;
                    case 1:
                        dwResult += dwKey;
                        break;
                    case 2:
                        dwResult = dwResult << (int)(dwKey % 11);
                        dwResult ^= dwKey;
                        break;
                }
                dwResult ^= (wChecksumKey + dwResult) >> (int)((I >> 2) % 16 + 3);
            }
            return dwResult;
        }

        public static byte[] Serialize(object Obj)
        {
            int rawsize = Marshal.SizeOf(Obj);
            byte[] rawdata = new byte[rawsize];
            GCHandle handle = GCHandle.Alloc(rawdata, GCHandleType.Pinned);
            Marshal.StructureToPtr(Obj, handle.AddrOfPinnedObject(), false);
            handle.Free();
            return rawdata;
        }

        public static uint MakeDword(byte[] bytes, uint start)
        {
            return (uint)((bytes[start + 3] << 24) | (bytes[start + 2] << 16) | (bytes[start + 1] << 8) | bytes[start]);
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4096)]
    struct CheckSumFile
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
        internal uint[] Checksums;
    }
}
Compiled .exe attached to this Post.

Credits: Deathway for the C++ Source

EDIT: Attachment didn´t work anymore, and cant attach it again, so i upped it at 1-click-hoster. Sry.
Download Mirrors:
 
Last edited:
MFS Team Owner
Joined
Jan 10, 2007
Messages
767
Reaction score
227
put new link for download couse the attachment is not working
 
Experienced Elementalist
Joined
Nov 8, 2009
Messages
273
Reaction score
15
wat exactly is that?i listen it couple times but the uses of that i dunno:(
 
NN - Nord & Noob
Loyal Member
Joined
Jul 15, 2004
Messages
1,207
Reaction score
689
Thanks for source, but where i can found C++ source the NET crap is hard to read for me

PS. Parallel feature looks really nice!
 
Joined
Aug 6, 2005
Messages
552
Reaction score
298
I dont know how old you mean, but yea season 1~5.3 it works.
current gmo(and maybe also the other new versions) got the gameguard.csr file from which you need to calculate the checksums.
 
Last edited:
Back
Top