MultiCore CheckSum.dat Generator

Results 1 to 14 of 14
  1. #1
    Developer nevS is offline
    MemberRank
    Aug 2005 Join Date
    GermanyLocation
    531Posts

    cool 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: http://www.mirrorcreator.com/files/FBEVQGFO/
    Last edited by nevS; 08-03-15 at 07:37 PM.


  2. #2
    Legend MuIsBest is offline
    LegendRank
    Dec 2006 Join Date
    NorwayLocation
    2,144Posts

    Re: MultiCore CheckSum.dat Generator

    Approved

  3. #3
    Apprentice kissmark69 is offline
    MemberRank
    Jan 2009 Join Date
    9Posts

    Re: MultiCore CheckSum.dat Generator

    how to enable checksum in gameserver?

  4. #4
    MFS Team Owner diablo71 is offline
    MemberRank
    Jan 2007 Join Date
    BulgariaLocation
    876Posts

    Re: MultiCore CheckSum.dat Generator

    put new link for download couse the attachment is not working

  5. #5
    TheUninvited TheUninvited is offline
    MemberRank
    Nov 2009 Join Date
    TheUninvitedLocation
    464Posts

    Re: MultiCore CheckSum.dat Generator

    wat exactly is that?i listen it couple times but the uses of that i dunno:(

  6. #6
    Member naja04 is offline
    MemberRank
    Sep 2005 Join Date
    89Posts

    Re: MultiCore CheckSum.dat Generator

    link for download not'work

  7. #7
    Developer nevS is offline
    MemberRank
    Aug 2005 Join Date
    GermanyLocation
    531Posts

    Re: MultiCore CheckSum.dat Generator

    reupped, Attachment is broken...

  8. #8
    NN - Nord & Noob mauka is offline
    MemberRank
    Jul 2004 Join Date
    1,728Posts

    Re: MultiCore CheckSum.dat Generator

    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!

  9. #9
    Developer nevS is offline
    MemberRank
    Aug 2005 Join Date
    GermanyLocation
    531Posts

    Re: MultiCore CheckSum.dat Generator

    Quote Originally Posted by mauka View Post
    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!
    i think he posted it in this thread:
    http://forum.ragezone.com/f197/deathway-work-445090/
    but i think the download link is down now, so i reupped it for u:
    http://rapidshare.com/files/428347923/DeathwayWORK.rar

  10. #10
    NN - Nord & Noob mauka is offline
    MemberRank
    Jul 2004 Join Date
    1,728Posts

    Re: MultiCore CheckSum.dat Generator

    Thanks ^^ i converted it from C# to delphi xD

  11. #11
    Enthusiast pegasus128 is offline
    MemberRank
    Jan 2008 Join Date
    43 61 6E 61 64Location
    49Posts

    Re: MultiCore CheckSum.dat Generator

    works on older versions?

  12. #12
    Developer nevS is offline
    MemberRank
    Aug 2005 Join Date
    GermanyLocation
    531Posts

    Re: MultiCore CheckSum.dat Generator

    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 by nevS; 06-06-11 at 08:21 AM.

  13. #13
    NN - Nord & Noob mauka is offline
    MemberRank
    Jul 2004 Join Date
    1,728Posts

    Re: MultiCore CheckSum.dat Generator

    Only small changes.. algo is still same

  14. #14
    Developer nevS is offline
    MemberRank
    Aug 2005 Join Date
    GermanyLocation
    531Posts

    Re: MultiCore CheckSum.dat Generator

    Updated first post, cleaner code + optimized speed.
    On my Intel i5 750 machine it's now a half second faster than the old version.



Advertisement