private void ChangeChunkIdByWheel(object sender, MouseWheelEventArgs e)
        {
            if (RootData.Sons.Count() <= 0)
            {
                return;
            }
            Image  obj = (Image)sender;
            string x   = obj.Name.Split('_')[1];
            string y   = obj.Name.Split('_')[2];
            int    num = Convert.ToInt32(x) * 7 + Convert.ToInt32(y);
            int    inc = 1;

            if (e.Delta > 0)
            {
                inc = -1;
            }
            ChunkNowIdNum[num] = (ChunkNowIdNum[num] + inc + ChunkIdDict.Count()) % ChunkIdDict.Count();
            if (ChunkNowIdNum[num] < 0)
            {
                return;
            }
            obj.Source = new BitmapImage(new Uri("/Resources/" + ChunkIdDict[ChunkNowIdNum[num]] + ".png", UriKind.Relative));
            SData thechunk = RootData.TurnTo("Chunks").Search("ChunkPosition", "\"" + x + "," + y + "\"");

            thechunk.TurnTo("ChunkId").Value = "\"" + ChunkIdDict[ChunkNowIdNum[num]] + "\"";
            Console.WriteLine(thechunk.TurnTo("ChunkPosition").Value);
        }
        private void AutoActivityItemsCodeChange(object sender, RoutedEventArgs e)
        {
            Button obj = (Button)sender;

            if (FarmInfoRootData.Sons.Count() > 0)
            {
                ActivityItemsCodeChange(null, null);
            }
            else if (AutoSearch())
            {
                SData.TotalLoadFromUserData(gameinfopath + "\\farms.data", FarmInfoRootData);
                string itemcodes = TxtItemCodes.Text;
                string legalcode = itemcodes.Replace("\"Rewards\":", "").TrimEnd(',');
                Console.WriteLine(legalcode);

                SData dt = FarmInfoRootData.TurnTo("\"Rewards\"");
                dt.sonKind = 0;
                dt.Value   = legalcode;

                if (SData.TotalSaveUserData())
                {
                    MessageBox.Show("修改成功!");
                }
            }
            else
            {
                obj.Content = "自动搜索失败,请使用下面的按钮手动选择存档";
            }
        }
        public static bool MainWindowSetFlat()//从主窗口过来的一键设置平原
        {
            Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
            op.Filter = "游戏存档文件(farm_*.data)|farm_*.data";
            op.ShowDialog();
            if (op.FileName == "" || op.FileName == null)
            {
                return(false);
            }
            SaveAddress = op.FileName;
            SData.LoadFromSave(SaveAddress, RootData);

            SData chunks = RootData.TurnTo("Chunks");

            foreach (var chunk in chunks.Sons)
            {
                Console.WriteLine(chunk.TurnTo("ChunkPosition").Value);
                chunk.TurnTo("ChunkId").Value = "\"Flat_Chunk\"";
            }
            if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\DataGenerated"))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\DataGenerated");
            }
            StreamWriter SW0 = new StreamWriter("DataGenerated\\farm_" + TheSaveNumber);

            SData.SaveFromSData(RootData, SW0);
            SW0.Close();
            return(SData.GzipPack());
        }
        private void ActivityItemsCodeChange(object sender, RoutedEventArgs e)
        {
            if (FarmInfoRootData.Sons.Count() <= 0)
            {
                Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
                op.Title  = "请选择farms.data文件,这通常在remote文件夹中";
                op.Filter = "farms.data文件|farms.data";
                op.ShowDialog();
                string addr = op.FileName;
                if (addr == "" || addr == null)
                {
                    return;
                }
                SData.TotalLoadFromUserData(addr, FarmInfoRootData);
            }

            //下面是修改过程
            string itemcodes = TxtItemCodes.Text;
            string legalcode = itemcodes.Replace("\"Rewards\":", "").TrimEnd(',');

            if (legalcode[0] != '[' || legalcode[legalcode.Length - 1] != ']')
            {
                MessageBox.Show("代码格式错误。请检查输入的代码。");
                return;
            }
            SData dt = FarmInfoRootData.TurnTo("\"Rewards\"");

            dt.sonKind = 0;
            dt.Value   = legalcode;

            if (SData.TotalSaveUserData())
            {
                MessageBox.Show("修改成功!");
            }
        }
Exemple #5
0
 public SData(SData fatherIN, string keyIN)
 {
     Key     = keyIN;
     Value   = "";
     sonKind = 0;
     Sons    = new List <SData>();
     Father  = fatherIN;
 }
Exemple #6
0
        public static bool SaveFromSData(SData dt, StreamWriter sw)
        {
            if (dt.Key != "" && dt.Key != null)
            {
                sw.Write(dt.Key + ":");
            }


            if (dt.sonKind == 0)
            {
                sw.Write(dt.Value);
                if (dt.Father.Sons.IndexOf(dt) != (dt.Father.Sons.Count() - 1))
                {
                    sw.Write(",");
                }
            }
            else
            {
                if (dt.sonKind == 1)
                {
                    sw.Write('{');
                }
                else if (dt.sonKind == 2)
                {
                    sw.Write('[');
                }

                foreach (var son in dt.Sons)
                {
                    SaveFromSData(son, sw);
                }
                if (dt.sonKind == 1)
                {
                    sw.Write('}');
                }
                else if (dt.sonKind == 2)
                {
                    sw.Write(']');
                }
                if (dt.Father != null)
                {
                    if (dt.Father.Sons.IndexOf(dt) != (dt.Father.Sons.Count() - 1))
                    {
                        sw.Write(",");
                    }
                }
            }

            return(true);
        }
        }//自动搜寻存档位置并返回成功或失败的bool

        private bool InitComboBox()//按照选好的或者搜到的位置配置下拉列表供选择
        {
            //下面是选择存档号
            Cb_FileNum.Items.Clear();
            SData.TotalLoadFromUserData(gameinfopath + "\\farms.data", FarmInfoRootData);
            farmnames = new List <string>();
            farmnums  = new List <string>();
            int count = 0;//有效存档个数

            foreach (var farm in FarmInfoRootData.TurnTo("\"Farms\"").Sons)
            {
                string thenum = farm.TurnTo("\"slot\"").Value;
                if (File.Exists(gamesavepathNoName + "\\farm_" + thenum + ".data"))
                {
                    string thename = farm.TurnTo("\"name\"").Value;
                    if (farmnames.Contains(thename))
                    {
                        thename += "_" + thenum;
                    }
                    farmnames.Add(thename);
                    Cb_FileNum.Items.Add(thename);
                    farmnums.Add(thenum);

                    if (count == 0)
                    {
                        Cb_FileNum.SelectedItem = thename;
                        Console.WriteLine("usecount=0 at count" + count.ToString());
                    }
                    if (thenum == TheSaveNumber)
                    {
                        CbIsLoading             = false;
                        Cb_FileNum.SelectedItem = thename;
                        Console.WriteLine("use num " + TheSaveNumber + " at count" + count.ToString());
                    }
                    count++;
                }
            }
            if (count > 0)
            {
                CbIsLoading          = false;
                Cb_FileNum.IsEnabled = true;
                return(true);
            }
            else
            {
                CbIsLoading = false;
                return(false);
            }
        }
 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (Cb_FileNum.Items.Count <= 0)
     {
         return;
     }
     if (CbIsLoading)
     {
         return;
     }
     TheSaveNumber = farmnums[farmnames.IndexOf(Cb_FileNum.SelectedItem.ToString())];
     SaveAddress   = gamesavepathNoName + "\\farm_" + TheSaveNumber + ".data";
     SData.LoadFromSave(SaveAddress, RootData);
     RefreshChunks();
 }
        private void SaveGame()
        {
            if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\DataGenerated"))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\DataGenerated");
            }
            StreamWriter SW0 = new StreamWriter("DataGenerated\\farm_" + TheSaveNumber);

            SData.SaveFromSData(RootData, SW0);
            SW0.Close();
            if (SData.GzipPack())
            {
                MessageBox.Show("修改成功!修改后第一次进入游戏并载入存档可能会有较长时间卡顿,请耐心等待。");
            }
            else
            {
                MessageBox.Show("修改失败。");
            }
        }
        private void OpenFileAndLoad(object sender, RoutedEventArgs e)//打开存档文件并将其同目录下的所有文档添加到备选下拉菜单,同时加载选择的存档到内存中
        {
            CbIsLoading = true;
            Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
            op.Filter = "游戏存档文件(farm_*.data)|farm_*.data";
            op.ShowDialog();
            if (op.FileName == "" || op.FileName == null)
            {
                return;
            }
            SaveAddress = op.FileName;
            string[] splt    = SaveAddress.Split('_');
            string   savenum = splt[splt.Length - 1];

            savenum       = savenum.Split('.')[0];
            TheSaveNumber = savenum;//剥离出存档编码并存储
            try
            {
                string savedir = System.IO.Path.GetDirectoryName(SaveAddress);
                gamesavepathNoName = savedir;
                DirectoryInfo savedirInfo = new DirectoryInfo(savedir);
                string        farminfodir = savedirInfo.Parent.FullName;
                if (File.Exists(farminfodir + "\\farms.data"))
                {
                    gameinfopath = farminfodir;
                    if (!InitComboBox())
                    {
                        SData.LoadFromSave(SaveAddress, RootData);
                    }
                    BtSaveTheChange.Background = new SolidColorBrush(Color.FromRgb(162, 243, 139));
                    BtAutoFlat.Background      = new SolidColorBrush(Color.FromRgb(162, 243, 139));
                }
                else
                {
                    Cb_FileNum.IsEnabled = false;
                    SData.LoadFromSave(SaveAddress, RootData);
                    BtSaveTheChange.Background = new SolidColorBrush(Color.FromRgb(162, 243, 139));
                    BtAutoFlat.Background      = new SolidColorBrush(Color.FromRgb(162, 243, 139));
                }
            }
            catch { }
        }
        private void SetFlatAuto(object sender, RoutedEventArgs e)
        {
            if (RootData.Sons.Count <= 0 || gamesavepathNoName == "")
            {
                OpenFileAndLoad(null, null);
            }
            if (RootData.Sons.Count <= 0 || gamesavepathNoName == "")
            {
                return;
            }
            SData chunks = RootData.TurnTo("Chunks");

            foreach (var chunk in chunks.Sons)
            {
                Console.WriteLine(chunk.TurnTo("ChunkPosition").Value);
                chunk.TurnTo("ChunkId").Value = "\"Flat_Chunk\"";
            }
            RefreshChunks();
            SaveGame();
        }
 public void RefreshChunks()
 {
     try
     {
         SData chunkdata = RootData.TurnTo("Chunks");
         foreach (var chunk in chunkdata.Sons)
         {
             string coord    = chunk.TurnTo("ChunkPosition").Value.Trim('\"');
             string ckid     = chunk.TurnTo("ChunkId").Value.Trim('\"');
             int    chunkpos = Convert.ToInt32(coord.Split(',')[0]) * 7 + Convert.ToInt32(coord.Split(',')[1]);
             if (ChunkIdDict.Contains(ckid))
             {
                 ChunkNowIdNum[chunkpos]      = ChunkIdDict.IndexOf(ckid);
                 AllMapChunk[chunkpos].Source = new BitmapImage(new Uri("/Resources/" + ckid + ".png", UriKind.Relative));
             }
             else
             {
                 ChunkNowIdNum[chunkpos]      = 0;
                 AllMapChunk[chunkpos].Source = new BitmapImage(new Uri("/Resources/Flat_Chunk.png", UriKind.Relative));
             }
         }
     }
     catch { }
 }
Exemple #13
0
        public static bool LoadFromSave(string saveaddr, SData root) //root作为根结点存储整个树
        {
            if (!GzipUnpack(saveaddr))                               //解压
            {
                return(false);
            }

            StreamReader sr = new StreamReader("SaveGenerated\\farm_" + GameSaveCodeCreator.TheSaveNumber);

            root.sonKind = 0;
            root.Sons    = new List <SData>();
            SData p = root;

            p.sonKind = 1;
            List <char> readchrs = new List <char>();
            char        nowread  = (char)sr.Read();
            char        lastread = '0';
            bool        realsign = true;  //忽视在双引号之间的符号
            bool        atend    = false; //在结尾时会出现一堆逗号,哪个是不需要退至上层的,而到这个结尾的标志就是

            while (!sr.EndOfStream)
            {
                lastread = nowread;
                nowread  = (char)sr.Read();
                if (string.Join("", readchrs.ToArray()) == "ViewedItems")
                {
                    atend = true;
                    //Console.WriteLine(string.Join("", readchrs.ToArray()) + "6666666666666666666");
                }
                if (atend && nowread != ']' && nowread != ':')//对于ViewedItems的特殊处理
                {
                    readchrs.Add(nowread);
                }
                else if (atend && nowread == ']')
                {
                    readchrs.Add(nowread);
                    atend = false;
                }
                else if (nowread == ':' && realsign)
                {
                    p = new SData(p, string.Join("", readchrs.ToArray()));
                    p.Father.Sons.Add(p);
                    //Console.WriteLine(string.Join("", readchrs.ToArray()) + "→");
                    readchrs.Clear();
                }
                else if ((nowread == ',' && realsign && (!atend)) || (nowread == '}' && realsign) || (nowread == ']' && (!atend) && lastread != '[' && realsign))
                {
                    atend = false;
                    if (readchrs.Count > 0)
                    {
                        p.Value = string.Join("", readchrs.ToArray());
                        //Console.WriteLine(string.Join("", readchrs.ToArray()) + "←");
                    }
                    readchrs.Clear();
                    p = p.Father;
                }
                else if (nowread == '[' && realsign)
                {
                    p.sonKind = 2;
                }
                else if (nowread == '{' && realsign)
                {
                    if (p.sonKind == 2)
                    {
                        p = new SData(p, "");
                        //Console.WriteLine(p.Father.Key + "[的{ →");
                        p.Father.Sons.Add(p);
                        p.sonKind = 1;
                    }
                    else
                    {
                        p.sonKind = 1;
                    }
                }
                else if (nowread == '\"')//会出现"144,23"这种影像数据读取的逗号,该逗号实际上属于value而不是分隔符,这些符号由于在""引号中间,通过识别复数个引号(数次反转realsign)来达到忽略这种逗号(或冒号等)的目的
                {
                    realsign = !realsign;
                    readchrs.Add(nowread);
                }
                else
                {
                    readchrs.Add(nowread);
                }
            }
            sr.Close();
            if (p == root && root.Sons.Count() > 0)
            {
                Console.WriteLine("成功加载存档");
            }
            return(true);
        }
Exemple #14
0
        public static bool TotalLoadFromUserData(string saveaddr, SData root)
        {
            //下面是解压
            GameSaveCodeCreator.UserDataAddress = saveaddr;
            using (FileStream fileStream = new FileStream(saveaddr, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (GZipStream decompressedStream = new GZipStream(fileStream, CompressionMode.Decompress))
                {
                    StreamReader reader = new StreamReader(decompressedStream);
                    string       result = reader.ReadToEnd();
                    reader.Close();
                    if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\SaveGenerated"))
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\SaveGenerated");
                    }
                    StreamWriter sw = new StreamWriter("SaveGenerated\\farms");
                    sw.Write(result);
                    sw.Close();
                }
            }

            //下面是读取
            StreamReader sr = new StreamReader("SaveGenerated\\farms");

            root.sonKind = 0;
            root.Sons    = new List <SData>();
            SData p = root;

            p.sonKind = 1;
            List <char> readchrs = new List <char>();
            char        nowread  = (char)sr.Read();
            char        lastread = '0';
            bool        realsign = true;  //忽视在双引号之间的符号
            bool        atend    = false; //在结尾时会出现一堆逗号,哪个是不需要退至上层的,而到这个结尾的标志就是

            while (!sr.EndOfStream)
            {
                lastread = nowread;
                nowread  = (char)sr.Read();
                if (string.Join("", readchrs.ToArray()) == "ViewedItems")
                {
                    atend = true;
                    //Console.WriteLine(string.Join("", readchrs.ToArray()) + "6666666666666666666");
                }
                if (atend && nowread != ']' && nowread != ':')//对于ViewedItems的特殊处理
                {
                    readchrs.Add(nowread);
                }
                else if (atend && nowread == ']')
                {
                    readchrs.Add(nowread);
                    atend = false;
                }
                else if (nowread == ':' && realsign)
                {
                    p = new SData(p, string.Join("", readchrs.ToArray()));
                    p.Father.Sons.Add(p);
                    //Console.WriteLine(string.Join("", readchrs.ToArray()) + "→");
                    readchrs.Clear();
                }
                else if ((nowread == ',' && realsign && (!atend)) || (nowread == '}' && realsign) || (nowread == ']' && (!atend) && lastread != '[' && realsign))
                {
                    atend = false;
                    if (readchrs.Count > 0)
                    {
                        p.Value = string.Join("", readchrs.ToArray());
                        //Console.WriteLine(string.Join("", readchrs.ToArray()) + "←");
                    }
                    readchrs.Clear();
                    p = p.Father;
                }
                else if (nowread == '[' && realsign)
                {
                    p.sonKind = 2;
                }
                else if (nowread == '{' && realsign)
                {
                    if (p.sonKind == 2)
                    {
                        p = new SData(p, "");
                        //Console.WriteLine(p.Father.Key + "[的{ →");
                        p.Father.Sons.Add(p);
                        p.sonKind = 1;
                    }
                    else
                    {
                        p.sonKind = 1;
                    }
                }
                else if (nowread == '\"')//会出现"144,23"这种影像数据读取的逗号,该逗号实际上属于value而不是分隔符,这些符号由于在""引号中间,通过识别复数个引号(数次反转realsign)来达到忽略这种逗号(或冒号等)的目的
                {
                    realsign = !realsign;
                    readchrs.Add(nowread);
                }
                else
                {
                    readchrs.Add(nowread);
                }
            }
            sr.Close();
            if (p == root && root.Sons.Count() > 0)
            {
                Console.WriteLine("成功读取用户数据!");
            }
            return(true);
        }