コード例 #1
0
        //Buttons
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectionMode == SelectionMode.None || listBox1.SelectedIndex == -1)
            {
                listBox1.SelectionMode = SelectionMode.One;
                MessageBox.Show("Please select Base save file for New saves.");

                listBox1.SelectedValue = Globals.SelectedSavePath;
            }
            else
            {
                //Check if selected existing and valid save files 0,1 not 2,4
                DataRowView sI = (DataRowView)listBox1.SelectedItem;

                BaseSave = (string)sI.Row["savePath"];

                if ((byte)sI.Row[2] == 0 || (byte)sI.Row[2] == 1)
                {
                    string   SiiSavePath          = (string)sI.Row[0] + "\\game.sii"; //bool FileDecoded = false;
                    string[] tempSavefileInMemory = null;

                    //Load Base save file
                    if (!File.Exists(SiiSavePath))
                    {
                        MessageBox.Show("File does not exist in " + SiiSavePath);
                        MainForm.ShowStatusMessages("e", "error_could_not_find_file", this, statusStripCCpositions.Name, statusStripCCpositions.Items[0].Name);
                    }
                    else
                    {
                        MainForm.FileDecoded = false;
                        try
                        {
                            int decodeAttempt = 0;
                            while (decodeAttempt < 5)
                            {
                                tempSavefileInMemory = MainForm.NewDecodeFile(SiiSavePath, this, statusStripCCpositions.Name, statusStripCCpositions.Items[0].Name);

                                if (MainForm.FileDecoded)
                                {
                                    break;
                                }
                                decodeAttempt++;
                            }

                            if (decodeAttempt == 5)
                            {
                                MessageBox.Show("Could not decrypt after 5 attempts");
                                MainForm.ShowStatusMessages("e", "error_could_not_decode_file", this, statusStripCCpositions.Name, statusStripCCpositions.Items[0].Name);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Could not read: " + SiiSavePath);
                        }

                        if ((tempSavefileInMemory == null) || (tempSavefileInMemory[0] != "SiiNunit"))
                        {
                            MessageBox.Show("Wrongly decoded Save file or wrong file format");
                            MainForm.ShowStatusMessages("e", "error_file_not_decoded", this, statusStripCCpositions.Name, statusStripCCpositions.Items[0].Name);
                        }
                        else
                        {
                            //Delete overwritten savefiles
                            foreach (KeyValuePair <string, string> ftd in FoldersToClear)
                            {
                                Directory.Delete(ftd.Key, true);
                            }

                            Globals.SavesHex = Directory.GetDirectories(Globals.SelectedProfilePath + @"\save").OrderByDescending(f => new FileInfo(f).LastWriteTime).ToArray();

                            List <byte> CustomFolders = new List <byte>();

                            //Find all custom folders
                            foreach (string saveF in Globals.SavesHex)
                            {
                                string saveFname = Path.GetFileName(saveF);
                                bool   result    = byte.TryParse(saveFname, out byte number);
                                if (result)
                                {
                                    CustomFolders.Add(number);
                                }
                            }

                            List <byte> NewCustomFolders = new List <byte>();

                            byte CustomFoldersCount = 1;
                            while (true)
                            {
                                if (CustomFolders.Exists(x => x == CustomFoldersCount))
                                {
                                }
                                else
                                {
                                    NewCustomFolders.Add(CustomFoldersCount);
                                }

                                if (NewCustomFolders.Count() == NewSave.Count)
                                {
                                    break;
                                }

                                CustomFoldersCount++;
                            }

                            //Create new numbered folder and new save files
                            int iSave = 0;
                            foreach (KeyValuePair <int, string[]> entry in NewSave)
                            {
                                //Create folder
                                string fp = Directory.GetParent(Globals.SavesHex[0]).FullName + "\\" + NewCustomFolders[iSave].ToString();
                                Directory.CreateDirectory(fp);

                                //Copy info file
                                string[] infoSii = MainForm.NewDecodeFile(BaseSave + @"\info.sii", this, statusStripCCpositions.Name, statusStripCCpositions.Items[0].Name);

                                //Prepare data
                                double tDT = Utilities.DateTimeUtilities.DateTimeToUnixTimeStamp(DateTime.UtcNow.ToLocalTime());

                                SaveFileInfoData infoData = new SaveFileInfoData();
                                infoData.Name     = entry.Value[0];//Save name
                                infoData.FileTime = Convert.ToUInt32(Math.Floor(tDT));

                                //Write info file
                                MainForm.WriteInfoFile(infoSii, fp + "\\info.sii", infoData);

                                //Create thumbnail files
                                //mat
                                Encoding utf8WithoutBom = new UTF8Encoding(false);
                                using (StreamWriter writer = new StreamWriter(fp + "\\preview.mat", true, utf8WithoutBom))
                                {
                                    writer.WriteLine(preview_mat);
                                }

                                //tobj
                                using (BinaryWriter binWriter = new BinaryWriter(File.Open(fp + "\\preview.tobj", FileMode.Create)))
                                {
                                    binWriter.Write(preview_tobj);
                                    string pathToTGA      = "/home/profiles/" + Globals.SelectedProfile + "/save/" + NewCustomFolders[iSave] + "/preview.tga";
                                    byte   filePathLength = (byte)pathToTGA.Length;
                                    binWriter.Write(filePathLength);
                                    binWriter.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0 });
                                    binWriter.Write(Encoding.UTF8.GetBytes(pathToTGA));
                                }

                                //image tga
                                //Default thumbnail
                                TGA tgaImg; Bitmap newbmp = null; int custThumbCount = 0;

                                if (!checkBoxCustomThumbnail.Checked)
                                {
                                    string[] imgpaths = new string[] { "img\\" + MainForm.GameType + "\\autosave.dds" };
                                    newbmp = new Bitmap(MainForm.ExtImgLoader(imgpaths, 256, 128, 0, 0)[0]);
                                }
                                else if (checkBoxCustomThumbnail.Checked && Thumbnails.Length != 0)
                                {
                                    if (custThumbCount < Thumbnails.Length)
                                    {
                                        newbmp = new Bitmap(Thumbnails[custThumbCount]);
                                        custThumbCount++;
                                    }
                                    else
                                    {
                                        custThumbCount = 0;
                                        newbmp         = new Bitmap(Thumbnails[custThumbCount]);
                                    }
                                }

                                tgaImg = (TGA)newbmp;
                                tgaImg.Save(fp + "\\preview.tga");

                                //Create game save file
                                using (StreamWriter writer = new StreamWriter(fp + "\\game.sii", true))
                                {
                                    writer.Write(tempSavefileInMemory[0]);

                                    for (int line = 1; line < tempSavefileInMemory.Length; line++)
                                    {
                                        string SaveInMemLine = tempSavefileInMemory[line];

                                        if (SaveInMemLine.StartsWith(" truck_placement:"))
                                        {
                                            writer.Write("\r\n" + " truck_placement: " + entry.Value[1]);
                                            line++;
                                            writer.Write("\r\n" + " trailer_placement: (0, 0, 0) (1; 0, 0, 0)");
                                            line++;
                                            int slave_trailers = int.Parse(tempSavefileInMemory[line].Split(new char[] { ' ' })[2]);
                                            writer.Write("\r\n" + tempSavefileInMemory[line]);
                                            if (slave_trailers > 0)
                                            {
                                                for (int i = 0; i < slave_trailers; i++)
                                                {
                                                    writer.Write("\r\n" + " slave_trailer_placements[" + i + "]: (0, 0, 0) (1; 0, 0, 0)");
                                                    line++;
                                                }
                                            }
                                            continue;
                                        }

                                        //EndWrite:
                                        writer.Write("\r\n" + SaveInMemLine);
                                    }
                                }

                                iSave++;
                            }

                            //
                            buttonSave.Enabled = false;
                            GC.Collect();
                            MessageBox.Show("Saves are created.\nNow you can close this window.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Not a valid save file for base file.\nPlease select existing save file not marked for deleting.");
                    //return;
                }
            }
        }
コード例 #2
0
        public void SetDefaultValues(bool _initial)
        {
            if (_initial)
            {
                listBoxFreightMarketAddedJobs.DrawMode       = DrawMode.OwnerDrawVariable;
                comboBoxFreightMarketCargoList.DrawMode      = DrawMode.OwnerDrawVariable;
                comboBoxFreightMarketUrgency.DrawMode        = DrawMode.OwnerDrawVariable;
                comboBoxFreightMarketTrailerDef.DrawMode     = DrawMode.OwnerDrawVariable;
                comboBoxFreightMarketTrailerVariant.DrawMode = DrawMode.OwnerDrawVariable;

                ResourceManagerMain = new PlainTXTResourceManager();
                ProgSettingsV       = new ProgSettings();

                ProgSettingsV.ProgramVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                SupportedSavefileVersionETS2 = new int[] { 39, 49 }; //Supported save version
                SupportedGameVersionETS2     = "1.33.x - 1.38.x";    //Last game version Tested on
                //SupportedSavefileVersionATS;
                SupportedGameVersionATS = "1.33.x - 1.38.x";         //Last game version Tested on

                comboBoxPrevProfiles.FlatStyle  =
                    comboBoxProfiles.FlatStyle  =
                        comboBoxSaves.FlatStyle = FlatStyle.Flat;

                ProfileETS2        = @"\Euro Truck Simulator 2";
                ProfileATS         = @"\American Truck Simulator";
                dictionaryProfiles = new Dictionary <string, string> {
                    { "ETS2", ProfileETS2 }, { "ATS", ProfileATS }
                };
                GameType = "ETS2";
                //Globals.CurrentGame = dictionaryProfiles[GameType];

                CompaniesLngDict = new Dictionary <string, string>();
                CitiesLngDict    = new Dictionary <string, string>();
                CountriesLngDict = new Dictionary <string, string>();
                CargoLngDict     = new Dictionary <string, string>();
                UrgencyLngDict   = new Dictionary <string, string>();
                //CustomStringsDict = new Dictionary<string, string>();
                TruckBrandsLngDict = new Dictionary <string, string>();
                DriverNames        = new Dictionary <string, string>();

                DistancesTable = new DataTable();
                DistancesTable.Columns.Add("SourceCity", typeof(string));
                DistancesTable.Columns.Add("SourceCompany", typeof(string));
                DistancesTable.Columns.Add("DestinationCity", typeof(string));
                DistancesTable.Columns.Add("DestinationCompany", typeof(string));
                DistancesTable.Columns.Add("Distance", typeof(int));
                DistancesTable.Columns.Add("FerryTime", typeof(int));
                DistancesTable.Columns.Add("FerryPrice", typeof(int));

                CountryDictionary = new CountryDictionary();
                CountriesDataList = new Dictionary <string, Country>();

                PlayerLevelNames = new List <LevelNames>();

                #region Player level names
                LevelNames lvl_name0 = new LevelNames(0, "Newbie", "FFE0E0E0");
                LevelNames lvl_name1 = new LevelNames(5, "Enthusiast", "FF45C294");
                LevelNames lvl_name2 = new LevelNames(10, "Workhorse", "FF75BAEA");
                LevelNames lvl_name3 = new LevelNames(15, "Entrepeneur", "FF3A88F4");
                LevelNames lvl_name4 = new LevelNames(20, "Master", "FF5847F0");
                LevelNames lvl_name5 = new LevelNames(25, "Instructor", "FFDA9356");
                LevelNames lvl_name6 = new LevelNames(30, "Elite", "FFF58493");
                LevelNames lvl_name7 = new LevelNames(40, "King of the Road", "FFC99EF2");
                LevelNames lvl_name8 = new LevelNames(50, "Legend", "FFC2F9FF");
                LevelNames lvl_name9 = new LevelNames(100, "Divine Champion", "FFF1DEA5");

                PlayerLevelNames.Add(lvl_name0);
                PlayerLevelNames.Add(lvl_name1);
                PlayerLevelNames.Add(lvl_name2);
                PlayerLevelNames.Add(lvl_name3);
                PlayerLevelNames.Add(lvl_name4);
                PlayerLevelNames.Add(lvl_name5);
                PlayerLevelNames.Add(lvl_name6);
                PlayerLevelNames.Add(lvl_name7);
                PlayerLevelNames.Add(lvl_name8);
                PlayerLevelNames.Add(lvl_name9);
                #endregion

                string curName = ""; string[] input; List <string> curLst = new List <string>();

                #region Currency ETS2

                curName = "EUR";
                CurrencyDictConversionETS2.Add(curName, 1);
                input  = new string[] { "", "€", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "CHF";
                CurrencyDictConversionETS2.Add(curName, 1.142);
                input  = new string[] { "", "", " CHF" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "CZK";
                CurrencyDictConversionETS2.Add(curName, 25.88);
                input  = new string[] { "", "", " Kč" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "GBP";
                CurrencyDictConversionETS2.Add(curName, 0.875);
                input  = new string[] { "", "£", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "PLN";
                CurrencyDictConversionETS2.Add(curName, 4.317);
                input  = new string[] { "", "", " zł" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "HUF";
                CurrencyDictConversionETS2.Add(curName, 325.3);
                input  = new string[] { "", "", " Ft" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "DKK";
                CurrencyDictConversionETS2.Add(curName, 7.46);
                input  = new string[] { "", "", " kr" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "SEK";
                CurrencyDictConversionETS2.Add(curName, 10.52);
                input  = new string[] { "", "", " kr" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "NOK";
                CurrencyDictConversionETS2.Add(curName, 9.51);
                input  = new string[] { "", "", " kr" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);

                curName = "RUB";
                CurrencyDictConversionETS2.Add(curName, 77.05);
                input  = new string[] { "", "₽", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatETS2.Add(curName, curLst);
                #endregion

                #region Currency ATS

                curName = "USD";
                CurrencyDictConversionATS.Add(curName, 1);
                input  = new string[] { "", "$", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatATS.Add(curName, curLst);

                curName = "CAD";
                CurrencyDictConversionATS.Add(curName, 1.3);
                input  = new string[] { "", "$", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatATS.Add(curName, curLst);

                curName = "MXN";
                CurrencyDictConversionATS.Add(curName, 18.69);
                input  = new string[] { "", "$", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatATS.Add(curName, curLst);

                curName = "EUR";
                CurrencyDictConversionATS.Add(curName, 0.856);
                input  = new string[] { "", "€", "" };
                curLst = new List <string>(input);
                CurrencyDictFormatATS.Add(curName, curLst);
                #endregion

                //Urgency
                UrgencyArray = new int[] { 0, 1, 2 };

                DistanceMultipliers = new Dictionary <string, double> {
                    { "km", 1 }, { "mi", km_to_mileconvert }
                };

                ADRImgS         = new Image[6];
                ADRImgSGrey     = new Image[6];
                SkillImgSBG     = new Image[5];
                SkillImgS       = new Image[6];
                GaragesImg      = new Image[1];
                GaragesHQImg    = new Image[1];
                CitiesImg       = new Image[2];
                UrgencyImg      = new Image[3];
                CargoTypeImg    = new Image[3];
                CargoType2Img   = new Image[3];
                GameIconeImg    = new Image[2];
                TruckPartsImg   = new Image[5];
                TrailerPartsImg = new Image[4];

                ProgUIImgsDict = new Dictionary <string, Image>();

                TabpagesImages = new ImageList();

                ADRbuttonArray   = new CheckBox[6];
                SkillButtonArray = new CheckBox[5, 6];
            }

            unCertainRouteLength = "";
            FileDecoded          = false;
            SavefilePath         = "";

            tempInfoFileInMemory    = null;
            tempSavefileInMemory    = null;
            tempProfileFileInMemory = null;


            //Game dependant
            if (GameType == "ETS2")
            {
                Globals.PlayerLevelUps = new int[] { 200, 500, 700, 900, 1000, 1100, 1300, 1600, 1700, 2100, 2300, 2600, 2700,
                                                     2900, 3000, 3100, 3400, 3700, 4000, 4300, 4600, 4700, 4900, 5200, 5700, 5900, 6000, 6200, 6600, 6800 };
                //Currency
                CurrencyDictFormat     = CurrencyDictFormatETS2;
                CurrencyDictConversion = CurrencyDictConversionETS2;
                Globals.CurrencyName   = ProgSettingsV.CurrencyMesETS2;
            }
            else
            {
                Globals.PlayerLevelUps = new int[] { 200, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300, 2500, 2700,
                                                     2900, 3100, 3300, 3500, 3700, 4000, 4300, 4600, 4900, 5200, 5500, 5800, 6100, 6400, 6700, 7000, 7300 };
                //Currency
                CurrencyDictFormat     = CurrencyDictFormatATS;
                CurrencyDictConversion = CurrencyDictConversionATS;
                Globals.CurrencyName   = ProgSettingsV.CurrencyMesATS;
            }

            PlayerDataData = new PlayerData();

            MainSaveFileProfileData = new SaveFileProfileData();
            MainSaveFileInfoData    = new SaveFileInfoData();

            UserCompanyAssignedTruckPlacementEdited = false;

            InfoDepContinue = false;

            CompaniesList = new List <string>();
            CitiesList    = new List <City>();

            CountriesList             = new List <string>();
            CargoesList               = new List <Cargo>();
            TrailerDefinitionVariants = new Dictionary <string, List <string> >();
            TrailerVariants           = new List <string>();

            HeavyCargoList       = new List <string>();
            CompanyTruckList     = new List <CompanyTruck>();
            CompanyTruckListDB   = new List <CompanyTruck>();
            CompanyTruckListDiff = new List <CompanyTruck>();

            UserColorsList           = new List <Color>();
            GaragesList              = new List <Garages>();
            UserTruckDictionary      = new Dictionary <string, UserCompanyTruckData>();
            UserDriverDictionary     = new Dictionary <string, UserCompanyDriverData>();
            DriverPool               = new List <string>();
            UserTrailerDictionary    = new Dictionary <string, UserCompanyTruckData>();
            UserTrailerDefDictionary = new Dictionary <string, List <string> >();

            extraVehicles = new List <string>();
            extraDrivers  = new List <string>();

            VisitedCities = new List <VisitedCity>();

            CargoesListDB     = new List <Cargo>();
            CitiesListDB      = new List <string>();
            CompaniesListDB   = new List <string>();
            CargoesListDiff   = new List <Cargo>();
            CitiesListDiff    = new List <string>();
            CompaniesListDiff = new List <string>();

            DBDependencies = new List <string>();
            //SFDependencies = new List<string>();

            ExternalCompanies = new List <ExtCompany>();

            ExtCargoList = new List <ExtCargo>();

            EconomyEventsTable             = new string[0, 0];
            EconomyEventUnitLinkStringList = new string[0];

            JobsAmountAdded = 0;
            LastVisitedCity = "";
            InGameTime      = 0;
            RandomValue     = new Random();

            LastModifiedTimestamp = new DateTime();

            AddedJobsDictionary = new Dictionary <string, List <JobAdded> >();
            AddedJobsList       = new List <JobAdded>();

            GPSbehind = new Dictionary <string, List <string> >();
            GPSahead  = new Dictionary <string, List <string> >();
            GPSAvoid  = new Dictionary <string, List <string> >();

            GPSbehindOnline = new Dictionary <string, List <string> >();
            GPSaheadOnline  = new Dictionary <string, List <string> >();

            namelessList     = new List <string>();
            namelessLast     = "";
            LoopStartCity    = "";
            LoopStartCompany = "";
            ProgPrevVersion  = "0.0.1.0";

            RouteList = new Routes();
            DistancesTable.Clear();

            components = null;
        }