/// <summary>
        /// Setup API file readers.
        /// </summary>
        private void SetupReaders()
        {
            // Try to setup Arena2-dependent content readers
            if (blockFileReader == null)
                blockFileReader = new BlocksFile(Path.Combine(arena2Path, BlocksFile.Filename), FileUsage.UseMemory, true);
            if (mapFileReader == null)
                mapFileReader = new MapsFile(Path.Combine(arena2Path, MapsFile.Filename), FileUsage.UseMemory, true);
            if (monsterFileReader == null)
                monsterFileReader = new MonsterFile(Path.Combine(arena2Path, MonsterFile.Filename), FileUsage.UseMemory, true);
            if (woodsFileReader == null)
                woodsFileReader = new WoodsFile(Path.Combine(arena2Path, WoodsFile.Filename), FileUsage.UseMemory, true);

            // Build map lookup dictionary
            if (mapDict == null && mapFileReader != null)
                EnumerateMaps();

            // Raise ready flag
            isReady = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets monster career template.
        /// Currently read from MONSTER.BSA. Would like to migrate this to a custom JSON format later.
        /// </summary>
        /// <param name="career"></param>
        /// <returns></returns>
        public static DFCareer GetMonsterCareerTemplate(MonsterCareers career)
        {
            MonsterFile monsterFile = new MonsterFile();
            if (!monsterFile.Load(Path.Combine(DaggerfallUnity.Instance.Arena2Path, MonsterFile.Filename), FileUsage.UseMemory, true))
                throw new Exception("Could not load " + MonsterFile.Filename);

            return monsterFile.GetMonsterClass((int)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;
        }