Exemple #1
0
        public frmMarkerEditor(string currentMapFile, List <MapMarker> currentMarkers, string selectedMarkerName)
        {
            InitializeComponent();

            markerList  = currentMarkers;
            selectedMap = currentMapFile;

            for (int markerIndex = 0; markerIndex <= 32; markerIndex++)
            {
                Image markerImage = (Image)ARKViewer.Properties.Resources.ResourceManager.GetObject($"marker_{markerIndex}");
                if (markerImage != null)
                {
                    markerIcons.Add(markerImage);
                }
            }

            if (selectedMarkerName.Length > 0)
            {
                //attempt to find and load it
                MapMarker selectedMarker = currentMarkers.Where(m => m.Map == currentMapFile && m.Name == selectedMarkerName).FirstOrDefault();
                EditingMarker = selectedMarker;
            }

            txtName.Enabled = selectedMarkerName.Length == 0;

            UpdateDisplay();
        }
        public void Load()
        {
            var savePath     = AppDomain.CurrentDomain.BaseDirectory;
            var saveFilename = Path.Combine(savePath, "config.json");

            Mode           = ViewerModes.Mode_SinglePlayer;
            SelectedFile   = "TheIsland.ark";
            SelectedServer = "";

            //load colours

            ColourMap = new List <ColourMap>();
            string colourMapFilename = Path.Combine(savePath, "colours.json");

            if (File.Exists(colourMapFilename))
            {
                string jsonFileContent = File.ReadAllText(colourMapFilename);

                JObject itemFile = JObject.Parse(jsonFileContent);
                JArray  itemList = (JArray)itemFile.GetValue("colors");
                foreach (JObject itemObject in itemList)
                {
                    ColourMap item = new ColourMap();
                    item.Id  = itemObject.Value <int>("id");
                    item.Hex = itemObject.Value <string>("hex");
                    ColourMap.Add(item);
                }
            }

            //load markers
            MapMarkerList = new List <MapMarker>();
            string markerFilename = Path.Combine(savePath, "mapmarkers.json");

            if (File.Exists(markerFilename))
            {
                string jsonFileContent = File.ReadAllText(markerFilename);

                JObject markerFile = JObject.Parse(jsonFileContent);
                JArray  markerList = (JArray)markerFile.GetValue("markers");
                foreach (JObject markerObject in markerList)
                {
                    MapMarker mapMarker = new MapMarker();

                    mapMarker.Map          = markerObject.Value <string>("Map");
                    mapMarker.Name         = markerObject.Value <string>("Name");
                    mapMarker.Colour       = markerObject.Value <int>("Colour");
                    mapMarker.BorderColour = markerObject.Value <int>("BorderColour");
                    mapMarker.BorderWidth  = markerObject.Value <int>("BorderWidth");
                    mapMarker.Marker       = markerObject.Value <int>("Marker");
                    mapMarker.Lat          = markerObject.Value <double>("Lat");
                    mapMarker.Lon          = markerObject.Value <double>("Lon");


                    MapMarkerList.Add(mapMarker);
                }
            }


            //load terminal markers
            string structureMarkerFilename = Path.Combine(savePath, "structuremarkers.json");

            if (File.Exists(structureMarkerFilename))
            {
                string jsonFileContent = File.ReadAllText(structureMarkerFilename);

                TerminalMarkers = new List <StructureMarker>();
                JObject markerFile   = JObject.Parse(jsonFileContent);
                JArray  terminalList = (JArray)markerFile.GetValue("terminals");

                foreach (JObject markerObject in terminalList)
                {
                    StructureMarker mapMarker = new StructureMarker();

                    mapMarker.Map = markerObject.Value <string>("Map");
                    mapMarker.Lat = markerObject.Value <double>("Lat");
                    mapMarker.Lon = markerObject.Value <double>("Lon");
                    mapMarker.X   = markerObject.Value <float>("X");
                    mapMarker.Y   = markerObject.Value <float>("Y");
                    mapMarker.Z   = markerObject.Value <float>("Z");

                    mapMarker.Colour = markerObject.Value <string>("Colour");

                    TerminalMarkers.Add(mapMarker);
                }


                GlitchMarkers = new List <StructureMarker>();
                JArray glitchList = (JArray)markerFile.GetValue("glitches");

                foreach (JObject markerObject in glitchList)
                {
                    StructureMarker mapMarker = new StructureMarker();

                    mapMarker.Map = markerObject.Value <string>("Map");
                    mapMarker.Lat = markerObject.Value <double>("Lat");
                    mapMarker.Lon = markerObject.Value <double>("Lon");
                    mapMarker.X   = markerObject.Value <float>("X");
                    mapMarker.Y   = markerObject.Value <float>("Y");
                    mapMarker.Z   = markerObject.Value <float>("Z");

                    mapMarker.Colour = markerObject.Value <string>("Colour");

                    GlitchMarkers.Add(mapMarker);
                }
            }


            //load item map
            ItemMap = new List <ItemClassMap>();
            string itemMapFilename = Path.Combine(savePath, "itemmap.json");

            if (File.Exists(itemMapFilename))
            {
                string jsonFileContent = File.ReadAllText(itemMapFilename);

                JObject itemFile = JObject.Parse(jsonFileContent);
                JArray  itemList = (JArray)itemFile.GetValue("items");
                foreach (JObject itemObject in itemList)
                {
                    ItemClassMap item = new ItemClassMap();
                    item.ClassName    = itemObject.Value <string>("ClassName");
                    item.FriendlyName = itemObject.Value <string>("FriendlyName");
                    item.Category     = itemObject.Value <string>("Category");
                    item.Icon         = itemObject.Value <int>("Icon");
                    ItemMap.Add(item);
                }
            }

            //load structure map
            StructureMap = new List <StructureClassMap>();
            string structureMapFilename = Path.Combine(savePath, "structuremap.json");

            if (File.Exists(structureMapFilename))
            {
                string jsonFileContent = File.ReadAllText(structureMapFilename);

                JObject itemFile = JObject.Parse(jsonFileContent);
                JArray  itemList = (JArray)itemFile.GetValue("structures");
                foreach (JObject itemObject in itemList)
                {
                    StructureClassMap item = new StructureClassMap();
                    item.ClassName    = itemObject.Value <string>("ClassName");
                    item.FriendlyName = itemObject.Value <string>("FriendlyName");
                    StructureMap.Add(item);
                }
            }

            //load dino map
            DinoMap = new List <DinoClassMap>();
            string dinoMapFilename = Path.Combine(savePath, "creaturemap.json");

            if (File.Exists(dinoMapFilename))
            {
                string jsonFileContent = File.ReadAllText(dinoMapFilename);

                JObject dinoFile = JObject.Parse(jsonFileContent);
                JArray  dinoList = (JArray)dinoFile.GetValue("creatures");
                foreach (JObject dinoObject in dinoList)
                {
                    DinoClassMap dino = new DinoClassMap();
                    dino.ClassName    = dinoObject.Value <string>("ClassName");
                    dino.FriendlyName = dinoObject.Value <string>("FriendlyName");
                    DinoMap.Add(dino);
                }
            }

            ServerList = new List <ServerConfiguration>();
            if (File.Exists(saveFilename))
            {
                //found, load the saved state
                string jsonFileContent = File.ReadAllText(saveFilename);
                configFromJson(jsonFileContent);

                //decrypt server password after reading from disk
                if (EncryptionPassword != null && EncryptionPassword.Length > 0)
                {
                    //decode from base64
                    byte[] passwordBytes = Convert.FromBase64String(EncryptionPassword);
                    this.EncryptionPassword = ASCIIEncoding.ASCII.GetString(passwordBytes);

                    if (ServerList.Count > 0)
                    {
                        foreach (var server in ServerList)
                        {
                            string mapFilename = "theisland.ark";
                            if (server.SaveGamePath.ToLower().EndsWith(".ark"))
                            {
                                if (server.SaveGamePath.Contains("/"))
                                {
                                    mapFilename         = server.SaveGamePath.Substring(server.SaveGamePath.LastIndexOf("/") + 1).ToLower();
                                    server.SaveGamePath = server.SaveGamePath.Substring(0, server.SaveGamePath.LastIndexOf("/") + 1);
                                }
                            }
                            else
                            {
                                mapFilename = server.Map;
                            }
                            server.Map = mapFilename.ToLower();
                            if (server.Address.ToLower().Contains("ftp://"))
                            {
                                server.Address = server.Address.Substring(server.Address.IndexOf("ftp://") + 6);
                            }

                            server.Username = DecryptString(server.Username, Convert.FromBase64String(this.IV), this.EncryptionPassword);
                            server.Password = DecryptString(server.Password, Convert.FromBase64String(this.IV), this.EncryptionPassword);
                        }
                    }
                }
                else
                {
                    //create random initial password for this installation
                    Random rnd = new Random();

                    string randomPasswordString = "";
                    for (int charIndex = 0; charIndex < 16; charIndex++)
                    {
                        int nextRand = rnd.Next(32, 126);
                        randomPasswordString += (char)nextRand;
                    }

                    this.EncryptionPassword = randomPasswordString;
                }
            }
            else
            {
                Aes aes = Aes.Create();
                this.IV = Convert.ToBase64String(aes.IV);

                Save();
            }
        }