MagicType.dat 5017

12/24/2011 13:43 Kiyono#1
Well since the source downgrading progress ran into some problems (client closing as soon as other entities appeared) and I couldn't fix it, I decided to mess around with something else that has always bothered me; the magictype.dat for lower patches.

This is the code I have for converting the MagicType.dat to MagicType.txt:
Code:
private void button2_Click(object sender, EventArgs e)
        {
            IniFile Ini = new IniFile("./Config.ini");

            ConquerPath = Ini.ReadString("Config", "ConquerPath", "");
            OutputPath = Ini.ReadString("Config", "OutputPath", "");

            StreamWriter Writer = new StreamWriter(new FileStream(OutputPath + @"MagicType.txt", FileMode.Create));
            using (BinaryReader Reader = new BinaryReader(new FileStream(ConquerPath + @"MagicType.dat", FileMode.Open)))
            {
                int TotalSpells = Reader.ReadInt32();

                for (int i = 0; i < TotalSpells; i++)
                {

                    Writer.WriteLine(Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(16)) + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(256)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(260)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(260)) + " " +
                        Reader.ReadInt32() + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(260)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Encoding.ASCII.GetString(Reader.ReadBytes(64)) + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32() + " " +
                        Reader.ReadInt32());
                }
                MessageBox.Show("Finished");
            }
            Writer.Flush();
            Writer.Close();
        }
It's based on this post:
Quote:
Originally Posted by nTL3fTy View Post
Magictype.dat structure:
datatypename
intamount
uint[amount]id
MagicType[amount]magictypes

MagicType structure:

I believe this should be all you need to parse the file. The id mentioned in the beginning of the file is type*10+level. With that information, you can build a dictionary.
But I probably applied it in the wrong way since the result is quite odd, I attached it to this post.

Any help?
12/27/2011 16:55 Zero47#2
Trying to decrypt that for ages, still couldn't. Wanted to get it decrypted so I can modify the spells and then encrypt it back. I don't have my code used to decrypt that but mine was decrypting it in another way (the result was more accurate but it didn't decrypted the whole .dat dunno why, it was messy also).
12/27/2011 19:23 nTL3fTy#3
There are several different versions of Magictype.dat, but it looks like the Magictype.dat in the archive is valid for that structure.

Here's some code that will load it correctly:
Extensions:
Code:
public static class Extensions
{
    public static string ReadCString(this BinaryReader reader, int size)
    {
        return Encoding.ASCII.GetString(reader.ReadBytes(size)).Split('\0')[0];
    }
}
Magictype:
Code:
public class Magictype
{
    public uint Id;
    public uint Type;
    public uint Sort;
    public string Name;
    public uint Crime;
    public uint Ground;
    public uint Multi;
    public uint Target;
    public uint Level;
    public uint UseMana;
    public int Power;
    public uint IntoneSpeed;
    public uint Percent;
    public uint StepSecs;
    public uint Range;
    public uint Distance;
    public uint Status;
    public uint NeedProfession;
    public uint NeedExperience;
    public uint NeedLevel;
    public uint UseXp;
    public uint WeaponSubtype;
    public uint ActiveTimes;
    public uint AutoActive;
    public uint FloorAttr;
    public uint AutoLearn;
    public uint LearnLevel;
    public uint DropWeapon;
    public uint UseStamina;
    public uint WeaponHit;
    public uint UseItem;
    public uint NextMagic;
    public uint DelayMS;
    public uint UseItemNum;
    public uint SenderAction;
    public string Description;
    public string DescriptionEx;
    public string IntoneEffect;
    public string IntoneSound;
    public string SenderEffect;
    public string SenderSound;
    public uint TargetDelay;
    public string TargetEffect;
    public string TargetSound;
    public string GroundEffect;
    public string TraceEffect;
    public uint ScreenRepresent;
    public uint UseInMarket;
    public uint TargetWoundDelay;

    public Magictype(uint id, BinaryReader reader)
    {
        Id = id;
        Type = reader.ReadUInt32();
        Sort = reader.ReadUInt32();
        Name = reader.ReadCString(16);
        Crime = reader.ReadUInt32();
        Ground = reader.ReadUInt32();
        Multi = reader.ReadUInt32();
        Target = reader.ReadUInt32();
        Level = reader.ReadUInt32();
        UseMana = reader.ReadUInt32();
        Power = reader.ReadInt32();
        IntoneSpeed = reader.ReadUInt32();
        Percent = reader.ReadUInt32();
        StepSecs = reader.ReadUInt32();
        Range = reader.ReadUInt32();
        Distance = reader.ReadUInt32();
        Status = reader.ReadUInt32();
        NeedProfession = reader.ReadUInt32();
        NeedExperience = reader.ReadUInt32();
        NeedLevel = reader.ReadUInt32();
        UseXp = reader.ReadUInt32();
        WeaponSubtype = reader.ReadUInt32();
        ActiveTimes = reader.ReadUInt32();
        AutoActive = reader.ReadUInt32();
        FloorAttr = reader.ReadUInt32();
        AutoLearn = reader.ReadUInt32();
        LearnLevel = reader.ReadUInt32();
        DropWeapon = reader.ReadUInt32();
        UseStamina = reader.ReadUInt32();
        WeaponHit = reader.ReadUInt32();
        UseItem = reader.ReadUInt32();
        NextMagic = reader.ReadUInt32();
        DelayMS = reader.ReadUInt32();
        UseItemNum = reader.ReadUInt32();
        SenderAction = reader.ReadUInt32();

        Description = reader.ReadCString(64);
        DescriptionEx = reader.ReadCString(256);

        IntoneEffect = reader.ReadCString(64);
        IntoneSound = reader.ReadCString(260);

        SenderEffect = reader.ReadCString(64);
        SenderSound = reader.ReadCString(260);

        TargetDelay = reader.ReadUInt32();

        TargetEffect = reader.ReadCString(64);
        TargetSound = reader.ReadCString(260);

        GroundEffect = reader.ReadCString(64);
        TraceEffect = reader.ReadCString(64);

        ScreenRepresent = reader.ReadUInt32();
        UseInMarket = reader.ReadUInt32();
        TargetWoundDelay = reader.ReadUInt32();
    }
}
MagictypeFile:
Code:
public class MagictypeFile
{
    private readonly IDictionary<uint, Magictype> _magictypes;

    public MagictypeFile(string path)
        : this(File.OpenRead(path))
    {
    }

    public MagictypeFile(Stream stream)
    {
        _magictypes = new Dictionary<uint, Magictype>();

        using (var reader = new BinaryReader(stream))
        {
            // read the number of entries in the file
            var amount = reader.ReadInt32();

            // read the magictype unique id list
            var idArray = new uint[amount];
            for (var i = 0; i < amount; i++)
            {
                idArray[i] = reader.ReadUInt32();
            }

            // read magictypes now
            for (var i = 0; i < amount; i++)
            {
                var id = idArray[i];
                var magictype = new Magictype(id, reader);

                if (_magictypes.ContainsKey(id))
                {
                    _magictypes.Remove(id);
                }

                _magictypes.Add(id, magictype);
            }
        }
    }
}
Usage:
Code:
var file = new MagictypeFile("MagicType.dat");
12/28/2011 16:35 shitboi#4
my thanks to nTL3fTy for the detailed class defn for magictype. I never knew what most of the fields are meant for. I only knew a couples fields that are can be understood directly by doing numeric comparisons.
12/28/2011 16:56 Kiyono#5
Oh, I already received a PM with a working en/decrypter, thanks though.