public static void LoadScriptFromFile(out MethodParamCollection script, string fileName)
        {
            script = new MethodParamCollection();
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                file.ReadBegin(fileName);

                if (file.ReadBlock() == "Script")
                {
                    int count = -1;
                    count = int.Parse(file.ReadLine());

                    script._methods = new MethodParamPair[count];

                    for (int i = 0; i < count; i++)
                    {
                        MethodParamPair method;
                        string          methodName = file.ReadBlock();
                        int             paramNum   = int.Parse(file.ReadLine());
                        string[]        tempParams = new string[paramNum];
                        for (int j = 0; j < paramNum; j++)
                        {
                            tempParams[j] = file.ReadLine();
                        }
                        int      exitNum   = int.Parse(file.ReadLine());
                        string[] tempExits = new string[exitNum];
                        for (int j = 0; j < exitNum; j++)
                        {
                            tempExits[j] = file.ReadLine();
                        }
                        file.ReadEndBlock();
                        method = EngineGlobals.GenerateMethodFromArgs(methodName, tempParams, tempExits);
                        method.PostExecuteHandler += script.MethodExecuted;
                        script._methods[i]         = method;
                    }
                    file.ReadEndBlock();
                    file.ReadEnd();
                }
                else
                {
                    throw new EngineException("Could not load script " + fileName, false);
                }
            }
        }
        public static void LoadScriptFromFile(out MethodParamCollection script, string fileName)
        {
            script = new MethodParamCollection();
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                file.ReadBegin(fileName);

                if (file.ReadBlock() == "Script")
                {
                    int count = -1;
                    count = int.Parse(file.ReadLine());

                    script._methods = new MethodParamPair[count];

                    for (int i = 0; i < count; i++)
                    {
                        MethodParamPair method;
                        string methodName = file.ReadBlock();
                        int paramNum = int.Parse(file.ReadLine());
                        string[] tempParams = new string[paramNum];
                        for (int j = 0; j < paramNum; j++)
                        {
                            tempParams[j] = file.ReadLine();
                        }
                        int exitNum = int.Parse(file.ReadLine());
                        string[] tempExits = new string[exitNum];
                        for (int j = 0; j < exitNum; j++)
                        {
                            tempExits[j] = file.ReadLine();
                        }
                        file.ReadEndBlock();
                        method = EngineGlobals.GenerateMethodFromArgs(methodName, tempParams, tempExits);
                        method.PostExecuteHandler += script.MethodExecuted;
                        script._methods[i] = method;

                    }
                    file.ReadEndBlock();
                    file.ReadEnd();
                }
                else
                    throw new EngineException("Could not load script " + fileName, false);
            }
        }
        public static void LoadList(out TextureLoadList list, string file)
        {
            list = new TextureLoadList();
            try
            {
                using (Utilities.FormattedFile formatFile = new Utilities.FormattedFile())
                {
                    formatFile.ReadBegin(@"Data\LoadLists\" + file + LOAD_EXTENSION);
                    if (formatFile.ReadBlock() != "LoadList")
                        throw new Data.Exceptions.EngineException("Missing correct block header, should be \"LoadList\"", true);
                    int entries = int.Parse(formatFile.ReadLine());
                    try
                    {
                        for (int i = 0; i < entries; i++)
                        {
                            string type = formatFile.ReadBlock();
                            string name = formatFile.ReadLine();
                            string path = "";
                            object extra = null;
                            switch (type)
                            {
                                #region Atlas Loading
                                case "Atlas":
                                    {
                                        int x, y, w, h;
                                        string atlasName;
                                        path = formatFile.ReadBlock();
                                        int atlastEntries = int.Parse(formatFile.ReadLine());
                                        Dictionary<string, Data.Scenes.Rectangle> _areas = new Dictionary<string, Data.Scenes.Rectangle>();

                                        for (int j = 0; j < atlastEntries; j++)
                                        {
                                            Data.Scenes.Rectangle rect;
                                            atlasName = formatFile.ReadBlock();
                                            string raw = formatFile.ReadLine();
                                            formatFile.ReadEndBlock();
                                            var temp = raw.Split(',');
                                            if (temp.Length != 4)
                                                throw new Data.Exceptions.EngineException("Invalid atlas entry", true);
                                            x = int.Parse(temp[0]);
                                            y = int.Parse(temp[1]);
                                            w = int.Parse(temp[2]);
                                            h = int.Parse(temp[3]);
                                            rect = new Data.Scenes.Rectangle(x, y, w, h);
                                            _areas[atlasName] = rect;
                                        }
                                        extra = _areas;
                                        formatFile.ReadEndBlock();
                                    }
                                    break;
                                case "Target":
                                    {
                                        int w, h;
                                        string raw = formatFile.ReadLine();
                                        var temp = raw.Split(',');
                                        w = int.Parse(temp[0]);
                                        h = int.Parse(temp[1]);
                                        extra = new int[] { w, h };
                                    }
                                    break;
                                case "Texture":
                                    path = formatFile.ReadLine();
                                    break;
                                #endregion
                            }

                            formatFile.ReadEndBlock();
                            if (type == "Target" || type == "Atlas")
                                list._entries[name] = new object[] { path, type, extra };
                            else
                                list._entries[name] = new object[] { path, type };

                        }
                    }
                    catch(System.Exception ex)
                    {

                    }
                    formatFile.ReadEndBlock();
                    formatFile.ReadEnd();
                }
                list._ready = true;
            }
            catch
            {
                list._ready = false;
            }
        }
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception("Invalid params passed");
            }

            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                string temp = "";
                Dictionary <int, object[]> _methodsRaw = new Dictionary <int, object[]>();

                //Read in the .ell script format to compile to a .ecs file
                file.ReadBegin(args[0] + ".ell");

                temp = file.ReadLine(); //Read in the version
                if (temp != "1.0.0.0")
                {
                    throw new Exception("Script is not for this version of the compiler");
                }

                temp = file.ReadBlock(); //Read in the header

                if (temp != "ElegyScript")
                {
                    throw new Exception("Invalid header tag");
                }

                int entries = int.Parse(file.ReadLine());

                for (int i = 0; i < entries; i++)
                {
                    temp = file.ReadBlock();    //Read in the method name

                    switch (temp)
                    {
                    case "ShowMessageBox":
                    {
                        int      lines      = int.Parse(file.ReadLine());
                        string[] methodArgs = new string[lines];

                        for (int l = 0; l < lines; l++)
                        {
                            methodArgs[l] = file.ReadLine();
                        }

                        _methodsRaw[i]    = new object[2];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = methodArgs;
                        break;
                    }

                    case "SetVariable":
                    {
                        string name, val;
                        name              = file.ReadLine();
                        val               = file.ReadLine();
                        _methodsRaw[i]    = new object[3];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        _methodsRaw[i][2] = val;
                        break;
                    }

                    case "SetSwitch":
                    {
                        string name;
                        string rawVal;
                        bool   val = false;
                        name   = file.ReadLine();
                        rawVal = file.ReadLine();
                        if (rawVal == "ON")
                        {
                            val = true;
                        }
                        else if (rawVal == "OFF")
                        {
                            val = false;
                        }
                        _methodsRaw[i]    = new object[3];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        _methodsRaw[i][2] = val;
                        break;
                    }

                    case "ToggleSwitch":
                    case "AddGold":
                    case "Wait":
                    {
                        string name;
                        name              = file.ReadLine();
                        _methodsRaw[i]    = new object[2];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        break;
                    }

                    case "Conditional":
                    {
                        break;
                    }

                    case "OpenSaveScreen":
                    case "StartBattle":
                    case "DamageActor":

                    //Audio
                    case "SetBgm":
                    case "SetSfx":
                        break;

                    case "ChangeBattleBgm":
                        break;

                    default:
                        throw new Exception("No such method exists or is implemented");
                    }


                    file.ReadEndBlock();
                }

                file.ReadEndBlock();

                file.ReadEnd();

                using (System.IO.BinaryWriter bw = new BinaryWriter(File.Create(args[1] + ".esl")))
                {
                    foreach (var kvp in _methodsRaw)
                    {
                        bw.Write(kvp.Key);
                        bw.Write(_methodIndexes[kvp.Value[0].ToString()]);
                        switch (kvp.Value[0].ToString())
                        {
                        case "ShowMessageBox":
                        {
                            string[] lines = (string[])kvp.Value[1];
                            bw.Write((byte)lines.Length);
                            for (byte i = 0; i < lines.Length; i++)
                            {
                                bw.Write(lines[i]);
                            }
                        }
                        break;

                        case "SetVariable":
                        case "SetSwitch":
                        case "ToggleSwitch":
                        case "AddGold":
                        case "Wait":
                        case "Conditional":
                        case "OpenSaveScreen":
                        case "StartBattle":
                        case "DamageActor":

                        //Audio
                        case "SetBgm":
                        case "SetSfx":
                        case "ChangeBattleBgm":
                            break;
                        }
                    }
                }
            }
        }
        public static void LoadList(out TextureLoadList list, string file)
        {
            list = new TextureLoadList();
            try
            {
                using (Utilities.FormattedFile formatFile = new Utilities.FormattedFile())
                {
                    formatFile.ReadBegin(@"Data\LoadLists\" + file + LOAD_EXTENSION);
                    if (formatFile.ReadBlock() != "LoadList")
                    {
                        throw new EngineException("Missing correct block header, should be \"LoadList\"", true);
                    }
                    int entries = int.Parse(formatFile.ReadLine());
                    for (int i = 0; i < entries; i++)
                    {
                        string type  = formatFile.ReadBlock();
                        string name  = formatFile.ReadLine();
                        string path  = "";
                        object extra = null;
                        switch (type)
                        {
                            #region Atlas Loading
                        case "Atlas":
                        {
                            int    x, y, w, h;
                            string atlasName;
                            path = formatFile.ReadBlock();
                            int atlastEntries = int.Parse(formatFile.ReadLine());
                            Dictionary <string, Data.Scenes.Rectangle> _areas = new Dictionary <string, Data.Scenes.Rectangle>();

                            for (int j = 0; j < atlastEntries; j++)
                            {
                                Data.Scenes.Rectangle rect;
                                atlasName = formatFile.ReadBlock();
                                string raw = formatFile.ReadLine();
                                formatFile.ReadEndBlock();
                                var temp = raw.Split(',');
                                if (temp.Length != 4)
                                {
                                    throw new EngineException("Invalid atlas entry", true);
                                }
                                x    = int.Parse(temp[0]);
                                y    = int.Parse(temp[1]);
                                w    = int.Parse(temp[2]);
                                h    = int.Parse(temp[3]);
                                rect = new Data.Scenes.Rectangle(x, y, w, h);
                                _areas[atlasName] = rect;
                            }
                            extra = _areas;
                            formatFile.ReadEndBlock();
                        }
                        break;

                        case "Target":
                        {
                            int    w, h;
                            string raw  = formatFile.ReadLine();
                            var    temp = raw.Split(',');
                            w     = int.Parse(temp[0]);
                            h     = int.Parse(temp[1]);
                            extra = new int[] { w, h };
                        }
                        break;

                        case "Texture":
                            path = formatFile.ReadLine();
                            break;
                            #endregion
                        }

                        formatFile.ReadEndBlock();
                        if (type == "Target" || type == "Atlas")
                        {
                            list._entries[name] = new object[] { path, type, extra }
                        }
                        ;
                        else
                        {
                            list._entries[name] = new object[] { path, type }
                        };
                    }
                    formatFile.ReadEndBlock();
                    formatFile.ReadEnd();
                }
                list._ready = true;
            }
            catch
            {
                list._ready = false;
            }
        }
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception("Invalid params passed");
            }

            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                string temp = "";
                Dictionary<int, object[]> _methodsRaw = new Dictionary<int, object[]>();

                //Read in the .ell script format to compile to a .ecs file
                file.ReadBegin(args[0] + ".ell");

                temp = file.ReadLine(); //Read in the version
                if (temp != "1.0.0.0")
                    throw new Exception("Script is not for this version of the compiler");

                temp = file.ReadBlock(); //Read in the header

                if (temp != "ElegyScript")
                    throw new Exception("Invalid header tag");

                int entries = int.Parse(file.ReadLine());

                for (int i = 0; i < entries; i++)
                {
                    temp = file.ReadBlock();    //Read in the method name

                    switch (temp)
                    {
                        case "ShowMessageBox":
                            {
                                int lines = int.Parse(file.ReadLine());
                                string[] methodArgs = new string[lines];

                                for (int l = 0; l < lines; l++)
                                    methodArgs[l] = file.ReadLine();

                                _methodsRaw[i] = new object[2];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = methodArgs;
                                break;
                            }
                        case "SetVariable":
                            {
                                string name, val;
                                name = file.ReadLine();
                                val = file.ReadLine();
                                _methodsRaw[i] = new object[3];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                _methodsRaw[i][2] = val;
                                break;
                            }
                        case "SetSwitch":
                            {
                                string name;
                                string rawVal;
                                bool val = false;
                                name = file.ReadLine();
                                rawVal = file.ReadLine();
                                if (rawVal == "ON")
                                    val = true;
                                else if (rawVal == "OFF")
                                    val = false;
                                _methodsRaw[i] = new object[3];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                _methodsRaw[i][2] = val;
                                break;
                            }
                        case "ToggleSwitch":
                        case "AddGold":
                        case "Wait":
                            {
                                string name;
                                name = file.ReadLine();
                                _methodsRaw[i] = new object[2];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                break;
                            }
                        case "Conditional":
                            {
                                break;
                            }
                        case "OpenSaveScreen":
                        case "StartBattle":
                        case "DamageActor":

                        //Audio
                        case "SetBgm":
                        case "SetSfx":
                            break;
                        case "ChangeBattleBgm":
                            break;
                        default:
                            throw new Exception("No such method exists or is implemented");
                    }

                    file.ReadEndBlock();
                }

                file.ReadEndBlock();

                file.ReadEnd();

                using (System.IO.BinaryWriter bw = new BinaryWriter(File.Create(args[1] + ".esl")))
                {
                    foreach (var kvp in _methodsRaw)
                    {
                        bw.Write(kvp.Key);
                        bw.Write(_methodIndexes[kvp.Value[0].ToString()]);
                        switch (kvp.Value[0].ToString())
                        {
                            case "ShowMessageBox":
                                {
                                    string[] lines = (string[])kvp.Value[1];
                                    bw.Write((byte)lines.Length);
                                    for (byte i = 0; i < lines.Length; i++)
                                    {
                                        bw.Write(lines[i]);
                                    }
                                }
                                break;
                            case "SetVariable":
                            case "SetSwitch":
                            case "ToggleSwitch":
                            case "AddGold":
                            case "Wait":
                            case "Conditional":
                            case "OpenSaveScreen":
                            case "StartBattle":
                            case "DamageActor":

                            //Audio
                            case "SetBgm":
                            case "SetSfx":
                            case "ChangeBattleBgm":
                                break;
                        }
                    }
                }
            }
        }