protected override void Setup() { base.Setup(); // Read all CLASS*.CFG files and add to listbox 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); listBox.AddItem(classFile.Career.Name); } } OnItemPicked += DaggerfallClassSelectWindow_OnItemPicked; }
/// <summary> /// Gets class career template. /// Currently read from CLASS??.CFG. Would like to migrate this to a custom JSON format later. /// </summary> public static DFCareer GetClassCareerTemplate(ClassCareers career) { string filename = string.Format("CLASS{0:00}.CFG", (int)career); ClassFile file = new ClassFile(); if (!file.Load(Path.Combine(DaggerfallUnity.Instance.Arena2Path, filename))) return null; return file.Career; }
/// <summary> /// Load monster record into memory and decompose it for use. /// </summary> /// <param name="monster">Monster index.</param> /// <returns>True if successful.</returns> public bool LoadMonster(int monster, out DFCareer monsterClassOut) { monsterClassOut = new DFCareer(); // Generate name from index string name = string.Format("ENEMY{0:000}.CFG", monster); // Attempt to load record int index = bsaFile.GetRecordIndex(name); if (index == -1) return false; // Read monster class data ClassFile classFile = new ClassFile(); byte[] data = bsaFile.GetRecordBytes(index); MemoryStream stream = new MemoryStream(data); BinaryReader reader = new BinaryReader(stream); classFile.Load(reader); reader.Close(); // Set output class monsterClassOut = classFile.Career; return true; }
DFCareer ReadCareer(BinaryReader reader) { ClassFile classFile = new ClassFile(); classFile.Load(reader); return classFile.Career; }
//void ShowUnknownGUI() //{ // EditorGUILayout.Space(); // showUnknownFoldout = GUILayoutHelper.Foldout(showUnknownFoldout, new GUIContent("Unknown"), () => // { // EditorGUILayout.Space(); // GUILayoutHelper.Indent(() => // { // EditorGUILayout.LabelField("Unknown1 [1 Bytes]"); // EditorGUILayout.SelectableLabel(selectedCareer.RawData.Unknown1.ToString("X2"), EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); // }); // GUILayoutHelper.Indent(() => // { // EditorGUILayout.LabelField("Unknown2 [8 Bytes]"); // string valuesString = string.Empty; // for (int i = 0; i < selectedCareer.RawData.Unknown2.Length; i++) // { // valuesString += selectedCareer.RawData.Unknown2[i].ToString("X2") + " "; // } // EditorGUILayout.SelectableLabel(valuesString, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); // }); // }); //} bool IsReady() { dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady || string.IsNullOrEmpty(dfUnity.Arena2Path)) return false; // Read all CLASS*.CFG files if (classTemplates == null) { string[] files = Directory.GetFiles(dfUnity.Arena2Path, "class*.cfg"); if (files != null && files.Length > 0) { classTemplates = new DFCareer[files.Length - 1]; classNames = new GUIContent[files.Length - 1]; for (int i = 0; i < files.Length - 1; i++) { ClassFile classFile = new ClassFile(files[i]); classTemplates[i] = classFile.Career; classNames[i] = new GUIContent(classTemplates[i].Name); } } } // Read all ENEMY*.CFG files if (monsterTemplates == null) { MonsterFile monsterFile = new MonsterFile(); if (monsterFile.Load(Path.Combine(dfUnity.Arena2Path, MonsterFile.Filename), FileUsage.UseMemory, true)) { // First pass locates CFG record indices List<int> cfgIndices = new List<int>(); for (int i = 0; i < monsterFile.Count; i++) { string recordName = monsterFile.GetRecordName(i); if (recordName.EndsWith(".cfg", StringComparison.InvariantCultureIgnoreCase)) cfgIndices.Add(i); } // Second pass populates arrays monsterTemplates = new DFCareer[cfgIndices.Count]; monsterNames = new GUIContent[cfgIndices.Count]; for (int i = 0; i < cfgIndices.Count; i++) { // Read ENEMY.CFG class file from stream ClassFile classFile = new ClassFile(); byte[] data = monsterFile.GetRecordBytes(cfgIndices[i]); MemoryStream stream = new MemoryStream(data); BinaryReader reader = new BinaryReader(stream); classFile.Load(reader); reader.Close(); // Add to arrays monsterTemplates[i] = classFile.Career; monsterNames[i] = new GUIContent(monsterTemplates[i].Name); } } else { return false; } } return true; }