static public bool ReadWorldInfo()
        {
            string TableName;
            Dictionary <int, string> dicWorld;
            Dictionary <int, string> dicWorldIDString;

            m_WorldList.Clear();
            m_LocalMapList.Clear();
            m_StartPosList.Clear();

            ScriptParser.m_DicEnumString.Clear();

            if (ScriptParser.ParseIDString(ScriptTreeManager.strDialogDir + "DLG_Map_World.lua", out dicWorldIDString, out TableName) &&
                ScriptParser.ParseIDandValue <string>(ScriptTreeManager.strDialogDir + "DLG_Map_World.lua", TableName, out dicWorld))
            {
                //{{ 각 World Info에 대해
                foreach (KeyValuePair <int, string> entry in dicWorldIDString)
                {
                    WorldInfo WI = new WorldInfo();
                    WI.m_iID         = (int)entry.Key;
                    WI.m_strEnumName = (string)entry.Value;

                    try
                    {
                        WI.m_strFileName = dicWorld[WI.m_iID];
                        WI.m_bOn         = true;
                    }
                    catch (Exception)
                    {
                        WI.m_strFileName = "";
                        WI.m_bOn         = false;
                    }
                    WI.m_LocalMapList = new Dictionary <int, LocalMapInfo>();

                    m_WorldList.Add(WI.m_iID, WI);
                } //}} World

                // Local Info 안에 자기가 어떤 World에 속하는지가 있으므로 따로 뽑자. 스크립트 상하관계가 좀 이상한데 뭐 한두날 이런가..
                ReadLocalInfo(ref m_WorldList);

                VillageInfoData VD  = new VillageInfoData();
                Lua             lua = new Lua();

                LuaTool.DoFile(lua, ScriptTreeManager.strMajorDir + "Enum.lua");
                LuaTool.DoFile(lua, ScriptTreeManager.strMajorDir + "StringID_def.lua");

                m_StartPosList.Clear();
                VD.ParseVillage(lua, ref m_StartPosList);
            }
            else
            {
                return(false);
            }



            return(true);
        }
        static private void ReadLocalInfo(ref Dictionary <int, WorldInfo> WorldMapList)
        {
            //{{ World Info에 속하는 Local Info들에 대해
            Dictionary <int, string> dicLocal;
            Dictionary <int, string> dicLocalIDString;
            string LocalTableName;

            if (ScriptParser.ParseIDString(ScriptTreeManager.strDialogDir + "DLG_Map_Local.lua", out dicLocalIDString, out LocalTableName) &&
                ScriptParser.ParseIDandValue <string>(ScriptTreeManager.strDialogDir + "Dlg_Map_Local.lua", LocalTableName, out dicLocal))
            {
                //LocalmapList = new Dictionary<int, LocalMapInfo>();
                foreach (KeyValuePair <int, string> localentry in dicLocalIDString)
                {
                    LocalMapInfo LI = new LocalMapInfo();
                    LI.m_iID         = localentry.Key;
                    LI.m_strEnumName = localentry.Value;

                    int BaseWorldmapID = -1;
                    try
                    {
                        LI.m_strFileName = dicLocal[LI.m_iID];
                        LI.m_bOn         = true;

                        Lua Locallua = new Lua();

                        LuaTool.DoFile(Locallua, ScriptTreeManager.strMajorDir + "Enum.lua");
                        LuaTool.DoFile(Locallua, ScriptTreeManager.strDialogDir + LI.m_strFileName);

                        LuaTool.GetValue(Locallua, "BaseWorldStateID", out BaseWorldmapID, -1);

                        ReadDungeonInfo(ScriptTreeManager.strDialogDir + LI.m_strFileName, Locallua, out LI.m_DungeonList);
                    }
                    catch (Exception)
                    {
                        LI.m_strFileName = "";
                        LI.m_bOn         = false;
                    }

                    if (BaseWorldmapID != -1)
                    {
                        try
                        {
                            m_LocalMapList.Add(LI.m_iID, LI);
                            WorldMapList[BaseWorldmapID].m_LocalMapList.Add(LI.m_iID, LI);
                        }
                        catch (KeyNotFoundException)
                        {
                            MessageBox.Show("World ID " + BaseWorldmapID.ToString() + " : No such World ID");
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }
                }
            }
        }
        static public bool ParseIDandValue <T>(string filename, string TableName, out Dictionary <int, T> OutPutDic)
        {
            OutPutDic = new Dictionary <int, T>();
            // 1. ID - Lua File 추출
            try
            {
                LuaTool.DoFile(lua, filename);

                LuaTable ltWorld = lua.GetTable(TableName);

                foreach (DictionaryEntry entry in ltWorld)
                {
                    OutPutDic.Add((int)(double)entry.Key, (T)entry.Value);
                }

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
        }
        static void ExportDungeonData(string TargetFolder, bool AddCode, string code, Encoding encoding)
        {
            // 4. DungeonData.lua Export
            string swfilename;

            if (AddCode && code.Length > 0)
            {
                swfilename = TargetFolder + "\\DungeonData@" + code + ".lua";
            }
            else
            {
                swfilename = TargetFolder + "\\DungeonData.lua";
            }

            StreamReader srDungeonData = null;
            StreamWriter swDungeonData = null;

            try
            {
                srDungeonData = new StreamReader(ScriptTreeManager.strDungeonDir + "DungeonData.lua", Encoding.UTF8, false);
                swDungeonData = new StreamWriter(swfilename, false, encoding);

                // DungeonIDList만 잘 확인하고, 나머지는 전부 그대로 Output.
                Lua lua = new Lua();
                LuaTool.DoFile(lua, ScriptTreeManager.strMajorDir + "Enum.lua");
                while (false == srDungeonData.EndOfStream)
                {
                    string strReadBuffer = srDungeonData.ReadLine();

                    if (strReadBuffer.Contains("dungeonID"))
                    {
                        int    indexequal    = strReadBuffer.IndexOf('=');
                        int    indexofcolon  = strReadBuffer.IndexOf(',');
                        string DIDEnumString = strReadBuffer.Substring(indexequal + 1, indexofcolon - indexequal - 1);
                        DIDEnumString = DIDEnumString.Trim();
                        DIDEnumString = DIDEnumString.Replace("HARD", "NORMAL");
                        DIDEnumString = DIDEnumString.Replace("EXPERT", "NORMAL");

                        try
                        {
                            int IDValue = (int)(double)lua[LuaTool.ConvertStringForm(DIDEnumString)];
                            if (m_CheckList[IDValue])
                            {
                                strReadBuffer = strReadBuffer.Replace("--dungeonID", "dungeonID");
                            }
                            else
                            {
                                strReadBuffer = strReadBuffer.Replace("dungeonID", "--dungeonID");
                            }
                        }
                        catch (Exception)
                        {
                            // 딱히 List에 없었던 던전의 경우 그냥 넘어간다.
                        }
                    }

                    swDungeonData.WriteLine(strReadBuffer);
                }
            }
            finally
            {
                if (srDungeonData != null)
                {
                    srDungeonData.Close();
                }
                if (swDungeonData != null)
                {
                    swDungeonData.Close();
                }
            }
        }
        static void ExportDetailedLocalMapScript(string filename, string TargetFolder, bool AddCode, string code, Encoding encoding)
        {
            // 2-1. Export Files in DLG_Map_Local
            string swfilename;

            if (AddCode && code.Length > 0)
            {
                int    extensionpos = filename.IndexOf(".lua");
                string namepart     = filename.Substring(0, extensionpos);

                swfilename = TargetFolder + "\\" + namepart + "@" + code + ".lua";
            }
            else
            {
                swfilename = TargetFolder + "\\" + filename;
            }


            StreamReader srLocal = null;
            StreamWriter swLocal = null;

            try
            {
                srLocal = new StreamReader(ScriptTreeManager.strDialogDir + filename, Encoding.UTF8, false);
                swLocal = new StreamWriter(swfilename, false, encoding);

                // DungeonIDList만 잘 확인하고, 나머지는 전부 그대로 Output.
                bool bInDungeonIDList = false;
                int  ContextDepth     = 0;
                Lua  lua = new Lua();
                LuaTool.DoFile(lua, ScriptTreeManager.strMajorDir + "Enum.lua");
                while (false == srLocal.EndOfStream)
                {
                    string strReadBuffer = srLocal.ReadLine();

                    if (bInDungeonIDList)
                    {
                        int searchindex = 0;
                        while (strReadBuffer.IndexOf('{', searchindex) != -1)
                        {
                            searchindex = strReadBuffer.IndexOf('{', searchindex) + 1;
                            ContextDepth++;
                        }

                        searchindex = 0;
                        while (strReadBuffer.IndexOf('}', searchindex) != -1)
                        {
                            searchindex = strReadBuffer.IndexOf('}', searchindex) + 1;
                            ContextDepth--;
                        }

                        if (ContextDepth < 1)
                        {
                            bInDungeonIDList = false;
                        }

                        if (strReadBuffer.Contains("DUNGEON_ID"))
                        {
                            strReadBuffer = strReadBuffer.TrimStart('-');
                            strReadBuffer = strReadBuffer.TrimStart();
                            strReadBuffer = strReadBuffer.TrimStart('-');

                            int    indexofcolon  = strReadBuffer.IndexOf(',');
                            string DIDEnumString = strReadBuffer.Substring(0, indexofcolon);
                            int    IDValue       = (int)(double)lua[LuaTool.ConvertStringForm(DIDEnumString)];

                            if (m_CheckList[IDValue])
                            {
                                strReadBuffer = "\t" + strReadBuffer;
                            }
                            else
                            {
                                strReadBuffer = "\t--" + strReadBuffer;
                            }
                        }
                    }

                    if (strReadBuffer.Contains("DungeonIDList ="))
                    {
                        bInDungeonIDList = true;
                    }

                    swLocal.WriteLine(strReadBuffer);
                }
            }
            finally
            {
                if (srLocal != null)
                {
                    srLocal.Close();
                }
                if (swLocal != null)
                {
                    swLocal.Close();
                }
            }
        }
        public void ParseDungeonInfoData(string filename)
        {
            bool   bNormalScript  = true;
            string normalFilename = null;

            if (filename.IndexOf("HARD") != -1)
            {
                normalFilename = filename.Replace("HARD", "NORMAL");
                bNormalScript  = false;
            }
            else if (filename.IndexOf("EXPERT") != -1)
            {
                normalFilename = filename.Replace("EXPERT", "NORMAL");
                bNormalScript  = false;
            }

            if (bNormalScript == false)
            {
                ParseDungeonInfoData(normalFilename);
            }

            StreamReader sr = null;

            try
            {
                sr = new StreamReader(filename, Encoding.UTF8);
                string strFile = sr.ReadToEnd();
                if (strFile.IndexOf("g_pDungeonManager:AddDungeonData") != -1)
                {
                    strFile = strFile.Replace("g_pDungeonManager:AddDungeonData", "TABLE = ");
                    //strFile = strFile.Substring(0, strFile.Length - 3);

                    // Valid file

                    Lua newlua = new Lua();
                    LuaTool.DoFile(newlua, ScriptTreeManager.strMajorDir + "Enum.lua");
                    LuaTool.DoFile(newlua, ScriptTreeManager.strMajorDir + "StringID_def.lua");

                    newlua.DoString(strFile);

                    LuaTool.GetValue(newlua, "TABLE.dungeonID", out m_DungeonID, 0);

                    LuaTool.GetValue(newlua, "TABLE.dungeonName", out m_DungeonName_ID, -1);

                    LuaTool.GetValue(newlua, "TABLE.dataFileName", out m_DataFileName, "");

                    #region CopyedCode
#if false
                    //LUA_GET_VALUE(				luaManager, L"requireLevel",		pDungeonData->m_RequireLevel, 0 );
                    LUA_GET_VALUE_ENUM(luaManager, L"requireDungeonID", pDungeonData->m_RequireDungeonID,
                                       CX2Dungeon::DUNGEON_ID, CX2Dungeon::DI_NONE);


                    if (true == luaManager.BeginTable("EXTRA_REQUIRE_DUNGEON_ID"))
                    {
                        for (int iValueIndex = 1; true; iValueIndex++)
                        {
                            int iExtraDungeonID = -1;
                            if (true == luaManager.GetValue(iValueIndex, iExtraDungeonID))
                            {
                                if (-1 != iExtraDungeonID)
                                {
                                    pDungeonData->m_vecExtraRequireDungeonID.push_back((CX2Dungeon::DUNGEON_ID)iExtraDungeonID);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        luaManager.EndTable(); // EXTRA_REQUIRE_DUNGEON_ID
                    }


                    LUA_GET_VALUE(luaManager, L"IS_HELL_MODE", pDungeonData->m_bHellMode, false);


                    //{{ 2007. 8. 29  최육사
                    LUA_GET_VALUE(luaManager, L"requireItemID", pDungeonData->m_RequireItemID, 0);
                    LUA_GET_VALUE(luaManager, L"requireItemCount", pDungeonData->m_RequireItemCount, 0);
                    //}}


                    LUA_GET_VALUE(luaManager, L"requireItemID2", pDungeonData->m_RequireItemID2, 0);
                    LUA_GET_VALUE(luaManager, L"requireItemCount2", pDungeonData->m_RequireItemCount2, 0);



                    //{{ 2007. 10. 4  최육사  근성도
                    LUA_GET_VALUE(luaManager, L"requireSpirit", pDungeonData->m_RequireSpirit, 0);
                    //}}

                    LUA_GET_VALUE_ENUM(luaManager, L"difficulty", pDungeonData->m_eDifficulty, CX2Dungeon::DIFFICULTY_LEVEL, CX2Dungeon::DL_NORMAL);

                    LUA_GET_VALUE(luaManager, L"normalOnly", pDungeonData->m_bNormalOnly, false);
                    LUA_GET_VALUE(luaManager, L"m_fTimeLimit", pDungeonData->m_fTimeLimit, -1.f);


                    LUA_GET_VALUE(luaManager, L"m_MinLevel", pDungeonData->m_MinLevel, 0);
                    LUA_GET_VALUE(luaManager, L"m_MaxLevel", pDungeonData->m_MaxLevel, 0);


                    LUA_GET_VALUE_ENUM(luaManager, L"m_eDefaultDungeonLoungeWorldID", pDungeonData->m_eDefaultDungeonLoungeWorldID, CX2World::WORLD_ID, CX2World::WI_NONE);



                    LUA_GET_VALUE_ENUM(luaManager, L"m_eDungeonType", pDungeonData->m_eDungeonType, CX2Dungeon::DUNGEON_TYPE, CX2Dungeon::DT_NORMAL);
                    LUA_GET_VALUE(luaManager, L"m_bRelativeMonsterLevel", pDungeonData->m_bRelativeMonsterLevel, false);



                    // UI Data About..
                    LUA_GET_VALUE(luaManager, L"m_bArcadeMode", pDungeonData->m_UIData.m_bArcadeMode, false);

                    LUA_GET_VALUE(luaManager, L"m_TextureName", pDungeonData->m_UIData.m_TextureName, L"");
                    LUA_GET_VALUE(luaManager, L"m_PieceName", pDungeonData->m_UIData.m_PieceName, L"");
                    LUA_GET_VALUE(luaManager, L"m_Explanation", iStringIndex, STR_ID_EMPTY);
                    pDungeonData->m_UIData.m_Explanation = GET_STRING(iStringIndex);

                    LUA_GET_VALUE(luaManager, L"m_LocalStarPosX", pDungeonData->m_UIData.m_LocalStarPos.x, -999.0f);
                    LUA_GET_VALUE(luaManager, L"m_LocalStarPosY", pDungeonData->m_UIData.m_LocalStarPos.y, -999.0f);

                    LUA_GET_VALUE(luaManager, L"m_PopUpOffsetPosX", pDungeonData->m_UIData.m_PopUpOffsetPos.x, 0.0f);
                    LUA_GET_VALUE(luaManager, L"m_PopUpOffsetPosY", pDungeonData->m_UIData.m_PopUpOffsetPos.y, 0.0f);

                    //{{ 2009.1.22 김태완 던전별 로딩화면

                    LUA_GET_VALUE(luaManager, L"m_LoadingScreenFileName", pDungeonData->m_UIData.m_LoadingScreenFileName, L"");
                    LUA_GET_VALUE(luaManager, L"m_LoadingScreenFileName2", pDungeonData->m_UIData.m_LoadingScreenFileName2, L"");

                    //}}



                    wstring wstrBuf = L"";
                    if (true == luaManager.BeginTable("AUTO_DUNGEON_ROOM_TITLE"))
                    {
                        for (int iValueIndex = 1; true; iValueIndex++)
                        {
                            LUA_GET_VALUE_RETURN(luaManager, iValueIndex, iStringIndex, STR_ID_EMPTY, break; );

                            pDungeonData->m_UIData.m_vecAutoRoomTitle.push_back(GET_STRING(iStringIndex));
                        }
        // dicStartPos : <StartPosID, LocalMapID>
        public void ParseVillage(Lua lua, ref Dictionary <int, int> dicStartPos)
        {
            m_fCameraDistance = 1200.0f;
            m_fLookAtHeight   = 200.0f;
            m_fEyeHeight      = 300.0f;

            LuaTool.DoFile(lua, ScriptTreeManager.strDialogDir + "DLG_Map_Village.lua");

            LuaTable VillageTable;

            try
            {
                VillageTable = lua.GetTable("Village");
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
                return;
            }

            foreach (DictionaryEntry Entry in VillageTable)
            {
                int      villageID   = (int)(double)Entry.Key;
                LuaTable Villageinfo = (LuaTable)Entry.Value;

                LuaTool.GetValue(Villageinfo, "NAME", out m_Name_ID, 0);
                LuaTool.GetValue(Villageinfo, "BaseLocalStateID", out m_BaseLocalStateID, 0);

                LuaTable HouseIDList;
                if (true == LuaTool.GetTable(Villageinfo, "HouseIDList", out HouseIDList))
                {
                    m_HouseList = new List <int>();
                    foreach (DictionaryEntry entry in HouseIDList)
                    {
                        m_HouseList.Add((int)(double)entry.Value);
                    }
                }

                LuaTool.GetValue(Villageinfo, "WORLD_ID", out m_WorldID, 0);
                // m_mapWorldMap.insert(std::make_pair((int)villageID, worldId));

                LuaTable Camera;
                if (true == LuaTool.GetTable(Villageinfo, "CAMERA", out Camera))
                {
                    m_fCameraDistance = (float)(double)Camera[1];
                    m_fLookAtHeight   = (float)(double)Camera[2];
                    m_fEyeHeight      = (float)(double)Camera[3];
                }

                LuaTable StartPos;
                if (true == LuaTool.GetTable(Villageinfo, "START_POS", out StartPos))
                {
                    m_vecStartPos = new List <VillageStartPos>();
                    foreach (DictionaryEntry ent in StartPos)
                    {
                        LuaTable        startposentry = (LuaTable)ent.Value;
                        VillageStartPos VSP           = new VillageStartPos();
                        VSP.m_VillageID = m_VillageID;
                        LuaTool.GetValue(startposentry, "StartPosId", out VSP.m_StartPosID, 0);
                        float x, y, z;
                        LuaTool.GetValue(startposentry, "StartPosX", out x, 0.0f);
                        VSP.m_StartPos.X = x;
                        LuaTool.GetValue(startposentry, "StartPosY", out y, 0.0f);
                        VSP.m_StartPos.Y = y;
                        LuaTool.GetValue(startposentry, "StartPosZ", out z, 0.0f);
                        VSP.m_StartPos.Z = z;

                        LuaTool.GetValue(startposentry, "IsMarket", out VSP.m_bIsMarket, false);
                        LuaTool.GetValue(startposentry, "IsNPC", out VSP.m_bIsNPC, false);
                        LuaTool.GetValue(startposentry, "IsSummon", out VSP.m_bIsSummon, false);
                        LuaTool.GetValue(startposentry, "IsWarp", out VSP.m_bIsWarp, false);

                        LuaTool.GetValue(startposentry, "LinkDungeon", out VSP.m_iDungeonId, 0);
                        LuaTool.GetValue(startposentry, "LinkDungeonPos", out VSP.m_iDungeonPos, 0);

                        LuaTable LinkPos;
                        if (true == LuaTool.GetTable(startposentry, "LinkPos", out LinkPos))
                        {
                            VSP.m_vecLinkStartPos = new List <int>();
                            foreach (DictionaryEntry LinkPosEntry in LinkPos)
                            {
                                if ((int)(double)LinkPosEntry.Value >= 0)
                                {
                                    VSP.m_vecLinkStartPos.Add((int)(double)LinkPosEntry.Value);
                                }
                            }
                        }
                        dicStartPos.Add(VSP.m_StartPosID, m_BaseLocalStateID);
                        m_vecStartPos.Add(VSP);
                    }
                } // StartPos
            }
        }
 static ScriptParser()
 {
     lua = new Lua();
     LuaTool.DoFile(lua, ScriptTreeManager.strMajorDir + "Enum.lua");
     m_DicEnumString = new Dictionary <int, string>();
 }