Exemple #1
0
        public frmCreatureClassMap(List <DinoClassMap> classMapList, DinoClassMap selectedClassMap)
        {
            InitializeComponent();

            dinoClassMapList    = classMapList;
            ClassMap            = selectedClassMap;
            txtClassName.Text   = selectedClassMap.ClassName;
            txtDisplayName.Text = selectedClassMap.FriendlyName;
        }
        private void btnRemoveDinoClass_Click(object sender, EventArgs e)
        {
            if (lvwDinoClasses.SelectedItems.Count == 0)
            {
                return;
            }

            DinoClassMap selectedClassMap = (DinoClassMap)lvwDinoClasses.SelectedItems[0].Tag;

            if (MessageBox.Show($"Are you sure you want to remove the display name for '{selectedClassMap.ClassName}'?", "Remove Name?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                SavedConfig.DinoMap.Remove(selectedClassMap);
                PopulateDinoClassMap("");
            }
        }
        public frmDinoInventoryViewer(ArkGameData gameData, ArkTamedCreature selectedCreature)
        {
            InitializeComponent();

            currentCreature = selectedCreature;

            string dinoName = selectedCreature.Name != null ? selectedCreature.Name : string.Empty;

            if (dinoName.Length == 0)
            {
                dinoName = selectedCreature.ClassName;
                DinoClassMap classMap = Program.ProgramConfig.DinoMap.Where(d => d.ClassName == selectedCreature.ClassName).FirstOrDefault();
                if (classMap != null && classMap.FriendlyName.Length > 0)
                {
                    dinoName = classMap.FriendlyName;
                }
            }

            lblPlayerName.Text  = dinoName;
            lblPlayerLevel.Text = selectedCreature.Level.ToString();
            lblTribeName.Text   = selectedCreature.TribeName;

            //inventory images
            imageList1.Images.Clear();
            int x = 1;

            while (true)
            {
                Image itemImage = (Image)ARKViewer.Properties.Resources.ResourceManager.GetObject($"item_{x}");
                if (itemImage == null)
                {
                    break;
                }

                imageList1.Images.Add(itemImage);
                x++;
            }

            PopulateCreatureInventory();
        }
        private void btnAddDinoClass_Click(object sender, EventArgs e)
        {
            frmCreatureClassMap mapEditor = new frmCreatureClassMap(SavedConfig.DinoMap, new DinoClassMap());

            if (mapEditor.ShowDialog() == DialogResult.OK)
            {
                //if line already exist for this class update the friendly name.
                DinoClassMap existingMap = SavedConfig.DinoMap.Where(d => d.ClassName.ToLower() == mapEditor.ClassMap.ClassName.ToLower()).FirstOrDefault <DinoClassMap>();
                if (existingMap != null && existingMap.ClassName.Length != 0)
                {
                    //found it, update
                    existingMap.FriendlyName = mapEditor.ClassMap.FriendlyName;
                }
                else
                {
                    //not found, add new
                    SavedConfig.DinoMap.Add(mapEditor.ClassMap);
                }

                PopulateDinoClassMap(mapEditor.ClassMap.ClassName);
            }
        }
        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();
            }
        }