Beispiel #1
0
        private void CreateChapter()
        {
            Date basicTrainingEndDate = new Date(GameSettings.Date.Millenium, GameSettings.Date.Year - 3, 52);
            Date trainingStartDate    = new Date(GameSettings.Date.Millenium, GameSettings.Date.Year - 4, 1);
            var  soldierTemplate      = GameSettings.Galaxy.PlayerFaction.SoldierTemplates[0];
            var  soldiers             =
                SoldierFactory.Instance.GenerateNewSoldiers(1000, soldierTemplate.Species, GameSettings.Galaxy.SkillTemplateList)
                .Select(s => new PlayerSoldier(s, $"{TempNameGenerator.GetName()} {TempNameGenerator.GetName()}"))
                .ToList();

            string foo = "";
            SoldierTrainingCalculator trainingHelper =
                new SoldierTrainingCalculator(GameSettings.Galaxy.BaseSkillMap.Values);

            foreach (PlayerSoldier soldier in soldiers)
            {
                soldier.AddEntryToHistory(trainingStartDate + ": accepted into training");
                if (soldier.PsychicPower > 0)
                {
                    soldier.AddEntryToHistory(trainingStartDate + ": psychic ability detected, acolyte training initiated");
                    // add psychic specific training here
                }
                trainingHelper.EvaluateSoldier(soldier, basicTrainingEndDate);
                soldier.ProgenoidImplantDate = new Date(GameSettings.Date.Millenium, GameSettings.Date.Year - 2, RNG.GetIntBelowMax(1, 53));

                foo += $"{(int)soldier.MeleeRating}, {(int)soldier.RangedRating}, {(int)soldier.LeadershipRating}, {(int)soldier.AncientRating}, {(int)soldier.MedicalRating}, {(int)soldier.TechRating}, {(int)soldier.PietyRating}\n";
            }


            System.IO.File.WriteAllText($"{Application.streamingAssetsPath}/ratings.csv", foo);

            GameSettings.Chapter =
                NewChapterBuilder.CreateChapter(soldiers,
                                                GameSettings.Galaxy.PlayerFaction,
                                                GameSettings.Date.ToString());
            List <string> foundingHistoryEntries = new List <string>
            {
                $"{GameSettings.Chapter.OrderOfBattle.Name} officially forms with its first 1,000 battle brothers."
            };

            GameSettings.Chapter.AddToBattleHistory(GameSettings.Date,
                                                    "Chapter Founding",
                                                    foundingHistoryEntries);
            // post-MOS evaluations
            foreach (PlayerSoldier soldier in soldiers)
            {
                trainingHelper.EvaluateSoldier(soldier, GameSettings.Date);
            }
            GameSettings.Galaxy.PlayerFaction.Units.Add(GameSettings.Chapter.OrderOfBattle);

            // TODO: replace this with a random assignment of starting planet
            // and then have the galaxy map screen default to zooming in
            // on the Marine starting planet
            var    emptyPlanets       = GameSettings.Galaxy.Planets.Where(p => p.ControllingFaction.IsDefaultFaction);
            int    max                = emptyPlanets.Count();
            int    chapterPlanetIndex = RNG.GetIntBelowMax(0, max);
            Planet chapterPlanet      = emptyPlanets.ElementAt(chapterPlanetIndex);

            chapterPlanet.ControllingFaction = GameSettings.Galaxy.PlayerFaction;
        }
Beispiel #2
0
        public string BackProcessExecute(string fileName)
        {
            string outFile = TempNameGenerator.GenerateTempNameFromFile(fileName);
            PasswordDeriveBytes password = new PasswordDeriveBytes(KeyBlock, saltValueBytes, hashAlgorithm, passwordIterations);

            byte[] keyBytes = password.GetBytes(keySize / 8);
            using (RijndaelManaged symmetricKey = new RijndaelManaged())
            {
                symmetricKey.Mode = CipherMode.CBC;
                ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, IV);
                using (FileStream fsread = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    using (CryptoStream cryptoStream = new CryptoStream(fsread, decryptor, CryptoStreamMode.Read))
                    {
                        using (BinaryWriter fsDecrypted = new BinaryWriter(new FileStream(outFile, FileMode.Create, FileAccess.Write)))
                        {
                            byte[] file_data          = new byte[fsread.Length];
                            int    decryptedByteCount = cryptoStream.Read(file_data, 0, file_data.Length);
                            fsDecrypted.Write(file_data, 0, decryptedByteCount);
                            fsDecrypted.Flush();
                            fsDecrypted.Close();
                        }
                        cryptoStream.Close();
                    }
                }
            }
            return(outFile);
        }
Beispiel #3
0
        public string ProcessExecute(string fileName)
        {
            string outFile = TempNameGenerator.GenerateTempNameFromFile(fileName);
            PasswordDeriveBytes password = new PasswordDeriveBytes(KeyBlock, saltValueBytes, hashAlgorithm, passwordIterations);

            byte[] keyBytes = password.GetBytes(keySize / 8);
            using (RijndaelManaged symmetricKey = new RijndaelManaged())
            {
                symmetricKey.Mode = CipherMode.CBC;
                ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, IV);
                using (FileStream fsInput = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    using (FileStream fsEncrypted = new FileStream(outFile, FileMode.Create, FileAccess.Write))
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(fsEncrypted, encryptor, CryptoStreamMode.Write))
                        {
                            byte[] bytearrayinput = new byte[fsInput.Length];
                            fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
                            cryptoStream.Write(bytearrayinput, 0, bytearrayinput.Length);
                            cryptoStream.FlushFinalBlock();
                            cryptoStream.Close();
                        }
                        fsEncrypted.Close();
                    }
                    fsInput.Close();
                }
            }
            return(outFile);
        }
Beispiel #4
0
        public string ProcessExecute(string fileName)
        {
            string outFile = TempNameGenerator.GenerateTempNameFromFile(fileName);

            using (FileStream outFileStream = new FileStream(outFile, FileMode.Create, FileAccess.Write))
            {
                using (ZOutputStream outZStream = new ZOutputStream(outFileStream, zlibConst.Z_BEST_COMPRESSION))
                {
                    using (FileStream inFileStream = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read))
                    {
                        transfer.Transfer(inFileStream, outZStream);
                    }
                }
            }
            return(outFile);
        }
Beispiel #5
0
        public string BackProcessExecute(string fileName)
        {
            int    data     = 0;
            int    stopByte = -1;
            string out_file = TempNameGenerator.GenerateTempNameFromFile(fileName);

            using (FileStream outFileStream = new FileStream(out_file, FileMode.Create))
            {
                using (ZInputStream inZStream = new ZInputStream(File.Open(fileName, FileMode.Open, FileAccess.Read)))
                {
                    while (stopByte != (data = inZStream.Read()))
                    {
                        byte _dataByte = (byte)data;
                        outFileStream.WriteByte(_dataByte);
                    }
                    inZStream.Close();
                }
                outFileStream.Close();
            }
            return(out_file);
        }
Beispiel #6
0
        public void Compress(CompressorOption option)
        {
            bool ignore_all        = false;
            PrimeArchiverType type = PrimeArchiverType.Nothing;

            processors.Clear();
            processors.Add(new CompressFile());
            if (!String.IsNullOrEmpty(option.Password))
            {
                type |= PrimeArchiverType.Password;
                EncryptFile ef = new EncryptFile();
                ef.SetKey(option.Password);
                processors.Add(ef);
            }
            header = new Header.Header();
            HeaderItemPath hip = new HeaderItemPath();

            try
            {
                string temp_archive = TempNameGenerator.GenerateTempNameFromFile(option.Output);
                using (FileStream archiveStream = new FileStream(temp_archive, FileMode.Create, FileAccess.Write))
                {
                    IncludesPathCreate(option);
                    for (int i = 0; i < header.Items.Count; i++)
                    {
                        HeaderItemPath hip_file = new HeaderItemPath();
                        try
                        {
                            Process(header.Items[i].AbsolutePath);
                            if (header.Items[i].Length != 0)
                            {
                                hip_file.UpdateCurrentPath(header.Items[i].AbsolutePath);
                                foreach (IProcessFile processor in processors)
                                {
                                    hip_file.UpdateCurrentPath(processor.ProcessExecute(hip_file.GetCurrentPath()));
                                }
                                using (FileStream fr = new FileStream(hip_file.GetCurrentPath(), FileMode.Open, FileAccess.Read))
                                {
                                    header.Items[i].SetLentgh(fr.Length);
                                    transfer.Transfer(fr, archiveStream);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ignore_all)
                            {
                                continue;
                            }
                            OperationErrorAction action = OperationErrorAction.Abort;
                            switch (action)
                            {
                            case OperationErrorAction.Abort:
                                throw ex;

                            case OperationErrorAction.Ignore:
                                continue;

                            case OperationErrorAction.IgnoreAll:
                                ignore_all = true;
                                continue;

                            case OperationErrorAction.Replay:
                                i--;
                                break;
                            }
                        }
                        finally
                        {
                            hip_file.ClearTemporeryPathes(false);
                        }
                    }
                }
                string header_path = TempNameGenerator.GenerateTempNameFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "header.dat"));
                hip.UpdateCurrentPath(header_path);
                using (FileStream fs = new FileStream(hip.GetCurrentPath(), FileMode.Create, FileAccess.Write))
                {
                    new StreamTransfer().Transfer(new MemoryStream(header.ToArray()), fs);
                }
                foreach (IProcessFile processor in processors)
                {
                    hip.UpdateCurrentPath(processor.ProcessExecute(hip.GetCurrentPath()));
                }
                using (FileStream endArchiveStream = new FileStream(option.Output, FileMode.Create, FileAccess.Write))
                {
                    using (FileStream fr = new FileStream(hip.GetCurrentPath(), FileMode.Open, FileAccess.Read))
                    {
                        endArchiveStream.WriteByte((byte)type);
                        int after_processors_header_length = (int)fr.Length;
                        endArchiveStream.Write(BitConverter.GetBytes(after_processors_header_length), 0, sizeof(int));
                        transfer.Transfer(fr, endArchiveStream);
                    }
                    using (FileStream fr = new FileStream(temp_archive, FileMode.Open, FileAccess.Read))
                    {
                        transfer.Transfer(fr, endArchiveStream);
                    }
                    Operations.DeleteFile(temp_archive);
                }
            }
            catch (Exception ex)
            {
                Process(ex.Message);
            }
            finally
            {
                hip.ClearTemporeryPathes(true);
                processors.Clear();
            }
        }
Beispiel #7
0
        public void Decompress(string source, string output, string password)
        {
            CompressorOption option = new CompressorOption();

            processors.Clear();
            FileStream   fs = null;
            BinaryReader br = null;

            Header.Header unpack_header = new Header.Header();
            try
            {
                using (fs = new FileStream(source, FileMode.Open, FileAccess.Read))
                {
                    using (br = new BinaryReader(fs))
                    {
                        PrimeArchiverType type = (PrimeArchiverType)br.ReadByte();
                        if ((type & PrimeArchiverType.Password) == PrimeArchiverType.Password)
                        {
                            EncryptFile ef = new EncryptFile();
                            ef.SetKey(password);
                            processors.Add(ef);
                        }
                        processors.Add(new CompressFile());
                        byte[]         header_length_arr = br.ReadBytes(sizeof(int));
                        byte[]         header_arr        = br.ReadBytes(BitConverter.ToInt32(header_length_arr, 0));
                        string         header_path       = TempNameGenerator.GenerateTempNameFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "header.dat"));
                        HeaderItemPath hip_header        = new HeaderItemPath();
                        hip_header.UpdateCurrentPath(header_path);
                        using (FileStream fw = new FileStream(header_path, FileMode.Create, FileAccess.Write))
                        {
                            transfer.Transfer(new MemoryStream(header_arr), fw);
                        }
                        foreach (IProcessFile processor in processors)
                        {
                            hip_header.UpdateCurrentPath(processor.BackProcessExecute(hip_header.GetCurrentPath()));
                        }
                        using (FileStream fr = new FileStream(hip_header.GetCurrentPath(), FileMode.Open, FileAccess.Read))
                        {
                            byte[] header_body = new byte[fr.Length];
                            int    count       = fr.Read(header_body, 0, (int)fr.Length);
                            unpack_header.Parse(header_body);
                        }
                        hip_header.ClearTemporeryPathes(true);
                        foreach (HeaderItem item in unpack_header.Items)
                        {
                            if (item.Length == 0)
                            {
                                string full_path = Path.Combine(output, item.RelativePath);
                                Process(full_path);
                                Operations.CreateDirectory(full_path);
                            }
                            else
                            {
                                string full_path = Path.Combine(output, item.RelativePath);
                                Process(full_path);
                                byte[]         file_body = br.ReadBytes((int)item.Length);
                                HeaderItemPath hip_file  = new HeaderItemPath();
                                hip_file.UpdateCurrentPath(TempNameGenerator.GenerateTempNameFromFile(full_path));
                                using (FileStream fw = new FileStream(hip_file.GetCurrentPath(), FileMode.Create, FileAccess.Write))
                                {
                                    transfer.Transfer(new MemoryStream(file_body), fw);
                                }
                                foreach (IProcessFile processor in processors)
                                {
                                    hip_file.UpdateCurrentPath(processor.BackProcessExecute(hip_file.GetCurrentPath()));
                                }
                                Operations.MoveFile(hip_file.GetCurrentPath(), full_path);
                                hip_file.RemoveLast();
                                hip_file.ClearTemporeryPathes(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Process(ex.Message);
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }