[Question] ItemType.dat version 4351 or lower

06/23/2019 21:06 12tails#1
Hey guys!

It's been a while since my last thread about making a server. I need a bit of help because i'm out of CO2 programming for too long and forgot some little things.

I could read and write all other .dat usefull files (levelxp, magic, monster, autoallot and etc) but not ItemType.dat, is there an public script for it? i remmember something about itemtype being encrypted in older versions.

Since i'm doing this, i have to edit the client to get the desired result.

If someone could help me with that, i would be very gratefull!

Thanks for all who gave me help and for the amazing samples found in this forum (alive after more than 10 years hehe).
06/23/2019 23:20 CptSky#2
ItemType.dat was a binary file on the first clients. I think my CO2_CORE_DLL library supported the binary version, but you might have to tweak the parsing.
06/24/2019 00:01 12tails#3
Yeah, i tested using your library, but worked just with the newer clients, even changing a few things... as i see it seems to be encrypted, guess i'm loosing something... this makes me few stupid hehe

#Edit
Here's the way to decrypt and encrypt the itemtype.dat for older clients:
Code:
       private Byte[] Key = new byte[] { 173, 107, 79, 251, 221, 184, 14, 9, 19, 51, 143, 245, 67, 9, 21, 136, 93, 128, 163, 69, 45, 66, 8, 86, 128, 248, 25, 197,
            136, 27, 62, 239, 129, 7, 48, 54, 149, 82, 0, 247, 253, 91, 92, 188, 106, 38, 14, 178, 163, 103, 197, 93, 111, 220, 24, 138, 181, 224, 200, 133, 226,
            62, 69, 141, 139, 67, 116, 133, 84, 23, 176, 236, 16, 77, 15, 15, 41, 184, 230, 125, 66, 128, 143, 188, 28, 118, 105, 58, 182, 165, 33, 134, 185, 41,
            48, 192, 18, 69, 165, 79, 225, 175, 37, 209, 146, 46, 48, 88, 73, 103, 165, 211, 132, 244, 137, 202, 252, 183, 4, 79, 204, 110, 172, 49, 212, 135, 7,
            114 };

        /// <summary>
        /// Save all the dictionary to the specified itemtype file (in custom binary format).
        /// </summary>
        public void SaveToDat(String FilePath)
        {
            if (File.Exists(FilePath))
            {
                byte[] pBuf = File.ReadAllBytes(FilePath);
                Encrypt(ref pBuf);

                string szRealName = Path.GetDirectoryName(FilePath) + "\\" + Path.GetFileNameWithoutExtension(FilePath);
                File.WriteAllBytes(Environment.CurrentDirectory + "\\" + szRealName + ".dat", pBuf);
            }
        }

        /// <summary>
        /// Save all the dictionary to the specified itemtype file (in plain format).
        /// </summary>
        public void SaveToTxt(String FilePath)
        {
            if (File.Exists(FilePath))
            {
                byte[] pBuf = File.ReadAllBytes(FilePath);
                Decrypt(ref pBuf);

                string szRealName = Path.GetDirectoryName(FilePath) + "\\" + Path.GetFileNameWithoutExtension(FilePath);
                File.WriteAllBytes(Environment.CurrentDirectory + "\\" + szRealName + ".txt", pBuf);
            }
        }

        /// <summary>
        /// Decrypt the ItemType.dat File
        /// </summary>
        /// <param name="pBuffer"></param>
        public void Decrypt(ref byte[] pBuffer)
        {
            for (int i = 0; i < pBuffer.Length; i++)
            {
                byte byt_ = (byte)(pBuffer[i] ^ Key[(int)((byte)i % 128)]);
                int int_ = i % 8;
                pBuffer[i] = (byte)(((int)byt_ << (8 - int_ & 31)) + ((int)byt_ >> (int_ & 31)));
            }
        }

        /// <summary>
        /// Encrypt the ItemType.dat File
        /// </summary>
        /// <param name="pBuffer"></param>
        public void Encrypt(ref byte[] pBuffer)
        {
            for (int i = 0; i < pBuffer.Length; i++)
            {
                int int_ = i % 8;
                byte byt_ = (byte)(((int)pBuffer[i] >> (8 - int_ & 31)) + ((int)pBuffer[i] << (int_ & 31)));
                pBuffer[i] = (byte)((byt_ ^ Key[(int)((byte)i % 128)]));
            }
        }