string ReadCharacterName(BinaryReader reader) { return(FileProxy.ReadCString(reader, 32)); }
public BiogFile(CharacterDocument characterDocument) { // Store reference to character document this.characterDocument = characterDocument; // Load text file string fileName = "BIOG" + characterDocument.classIndex.ToString("D" + 2) + "T0.TXT"; FileProxy txtFile = new FileProxy(Path.Combine(DaggerfallUnity.Instance.Arena2Path, fileName), FileUsage.UseDisk, true); questionsStr = System.Text.Encoding.UTF8.GetString(txtFile.GetBytes()); // Parse text into questions StringReader reader = new StringReader(questionsStr); string curLine = reader.ReadLine(); for (int i = 0; i < questionCount; i++) { questions[i] = new Question(); // Skip through any blank lines while (curLine.Length <= 1) { curLine = reader.ReadLine(); } // Parse question text for (int j = 0; j < Question.lines; j++) { // Check if the next line is part of the question if (j == 0) // first question line should lead with a number followed by a '.' { questions[i].Text[j] = curLine.Split(new[] { '.' }, 2)[1].Trim(); } else if (j > 0 && curLine.IndexOf(".") != 1 && curLine.IndexOf(".") != 2) { questions[i].Text[j] = curLine.Trim(); } else { break; } curLine = reader.ReadLine(); } // Parse answers to the current question while (curLine.IndexOf(".") == 1 && char.IsLetter(curLine[0])) // Line without 2-char preamble including letter = end of answers { Answer ans = new Answer(); // Get Answer text ans.Text = curLine.Split('.')[1].Trim(); curLine = reader.ReadLine(); // Add answer effects while (curLine.IndexOf(".") != 1 && curLine.Length > 1) { ans.Effects.Add(curLine.Trim()); curLine = reader.ReadLine(); } questions[i].Answers.Add(ans); } } reader.Close(); // Initialize reputation changes for (int i = 0; i < changedReputations.Length; i++) { changedReputations[i] = 0; } // Initialize question token lists Q1Tokens = new List <int>(); Q2Tokens = new List <int>(); Q3Tokens = new List <int>(); Q4Tokens = new List <int>(); Q5Tokens = new List <int>(); Q6Tokens = new List <int>(); Q7Tokens = new List <int>(); Q8Tokens = new List <int>(); Q9Tokens = new List <int>(); Q10Tokens = new List <int>(); Q11Tokens = new List <int>(); Q12Tokens = new List <int>(); }
static void CreateStartingSpellsJSON(string fallExePath, string outputPath) { const int recordLength = 6; // Length of starting spells record per career const int casterRecordCount = 7; // Number of caster career spell records const long startingSpellsOffset = 0x1B064F; // Offset into FALL.EXE for starting spell data (can be different based on .EXE version) /* * Alternate offset: 0x1B513F * Offset data in FALL.EXE should start like so (credit to Allofich for information) * 01 25 02 61 08 FF // Mage * 08 2C 25 FF FF FF // Spellsword / Custom class (if any of the primary or major skills is a magic skill) * 08 02 25 FF FF FF // Battlemage * 01 25 02 61 08 FF // Sorcerer * 61 02 01 25 FF FF // Healer * 2C 02 FF FF FF FF // Nightblade * 25 FF FF FF FF FF // Bard * ... */ // Read all CLASS*.CFG files List <DFCareer> classList = new List <DFCareer>(); string[] files = Directory.GetFiles(DaggerfallUnity.Instance.Arena2Path, "CLASS*.CFG"); if (files != null && files.Length > 0) { for (int i = 0; i < files.Length - 1; i++) { ClassFile classFile = new ClassFile(files[i]); classList.Add(classFile.Career); } } // Get list of spells List <SpellRecord.SpellRecordData> standardSpells = DaggerfallSpellReader.ReadSpellsFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, spellsStd)); // Read starting spell records for these classes byte[] record; FileProxy exeFile = new FileProxy(fallExePath, FileUsage.UseDisk, true); BinaryReader reader = exeFile.GetReader(startingSpellsOffset); List <CareerStartingSpells> careerList = new List <CareerStartingSpells>(); for (int i = 0; i < casterRecordCount; i++) { CareerStartingSpells careerItem = new CareerStartingSpells() { CareerIndex = i, CareerName = classList[i].Name, }; List <StartingSpell> spellsList = new List <StartingSpell>(); record = reader.ReadBytes(recordLength); for (int j = 0; j < recordLength; j++) { if (record[j] == 0xff) { continue; } // Get spell record data // Some careers reference spells that don't exist in SPELLS.STD - skipping over these SpellRecord.SpellRecordData spellRecordData; if (!FindSpellByID(record[j], standardSpells, out spellRecordData)) { //Debug.LogErrorFormat("Spell ID {0} not found while reading career '{1}'", record[j], careerItem.CareerName); continue; } // Barbarian has !Nux Vomica (a poison) in their starting spell list? - skipping for now if (spellRecordData.spellName.StartsWith("!")) { continue; } StartingSpell spellItem = new StartingSpell() { SpellID = record[j], SpellName = spellRecordData.spellName, }; spellsList.Add(spellItem); } careerItem.SpellsList = spellsList.ToArray(); careerList.Add(careerItem); } // Output JSON file string json = SaveLoadManager.Serialize(careerList.GetType(), careerList); File.WriteAllText(outputPath, json); }
public BiogFile(CharacterDocument characterDocument) { // Store reference to character document this.characterDocument = characterDocument; // Load text file string fileName = $"BIOG{characterDocument.classIndex:D2}T{characterDocument.biographyIndex}.TXT"; FileProxy txtFile = new FileProxy(Path.Combine(BiogFile.BIOGSourceFolder, fileName), FileUsage.UseDisk, true); questionsStr = System.Text.Encoding.UTF8.GetString(txtFile.GetBytes()); // Parse text into questions StringReader reader = new StringReader(questionsStr); string curLine = reader.ReadLine(); for (int i = 0; i < questionCount; i++) { questions[i] = new Question(); // Skip through any blank lines while (curLine.Length <= 1) { curLine = reader.ReadLine(); } // If we haven't parsed the first question yet, allow users to specify a custom backstory string id if (i == 0) { if (curLine[0] == '#') { string value = curLine.Substring(1); if (!int.TryParse(value, out backstoryId)) { Debug.LogError($"{fileName}: Invalid string id '{value}'"); backstoryId = defaultBackstoriesStart + characterDocument.classIndex; } // Find the next non-empty line, which should be question 1 do { curLine = reader.ReadLine(); } while (curLine.Length <= 1); } else { backstoryId = defaultBackstoriesStart + characterDocument.classIndex; } } // Parse question text for (int j = 0; j < Question.lines; j++) { // Check if the next line is part of the question if (j == 0) // first question line should lead with a number followed by a '.' { questions[i].Text[j] = curLine.Split(new[] { '.' }, 2)[1].Trim(); } else if (j > 0 && curLine.IndexOf(".") != 1 && curLine.IndexOf(".") != 2) { questions[i].Text[j] = curLine.Trim(); } else { break; } curLine = reader.ReadLine(); } // Parse answers to the current question while (curLine.IndexOf(".") == 1 && char.IsLetter(curLine[0])) // Line without 2-char preamble including letter = end of answers { Answer ans = new Answer(); // Get Answer text ans.Text = curLine.Split('.')[1].Trim(); curLine = reader.ReadLine(); // Add answer effects while (curLine.IndexOf(".") != 1 && curLine.Length > 1) { ans.Effects.Add(curLine.Trim()); curLine = reader.ReadLine(); } questions[i].Answers.Add(ans); } } reader.Close(); // Initialize reputation changes for (int i = 0; i < changedReputations.Length; i++) { changedReputations[i] = 0; } // Initialize question token lists Q1Tokens = new List <int>(); Q2Tokens = new List <int>(); Q3Tokens = new List <int>(); Q4Tokens = new List <int>(); Q5Tokens = new List <int>(); Q6Tokens = new List <int>(); Q7Tokens = new List <int>(); Q8Tokens = new List <int>(); Q9Tokens = new List <int>(); Q10Tokens = new List <int>(); Q11Tokens = new List <int>(); Q12Tokens = new List <int>(); }
public void FileExistsThrowsArgumentNullExceptionIfFilenameIsNull() { IFileProxy proxy = new FileProxy(); proxy.FileExists(null); }
public void SaveThrowsArgumentNullExceptionIfDataToSaveIsNull() { IFileProxy proxy = new FileProxy(); proxy.Save("file.txt", null); }
public void SaveThrowsArgumentNullExceptionIfFilenameIsNull() { IFileProxy proxy = new FileProxy(); proxy.Save(null, null); }
public void LoadThrowsArgumentNullExceptionIfFilenameIsNull() { IFileProxy proxy = new FileProxy(); proxy.Load(null); }