Exemplo n.º 1
0
        DFCareer ReadCareer(BinaryReader reader)
        {
            ClassFile classFile = new ClassFile();
            classFile.Load(reader);

            return classFile.Career;
        }
Exemplo n.º 2
0
        /// <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);
        }
        void RestoreOldClassSpecials(SaveTree saveTree, Races classicTransformedRace)
        {
            try
            {
                // Get old class record
                SaveTreeBaseRecord oldClassRecord = saveTree.FindRecord(RecordTypes.OldClass);
                if (oldClassRecord == null)
                {
                    return;
                }

                // Read old class data
                System.IO.MemoryStream stream = new System.IO.MemoryStream(oldClassRecord.RecordData);
                System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
                ClassFile classFile           = new ClassFile();
                classFile.Load(reader);
                reader.Close();

                // Restore any specials set by transformed race
                if (classicTransformedRace == Races.Vampire)
                {
                    // Restore pre-vampire specials
                    characterDocument.career.DamageFromSunlight   = classFile.Career.DamageFromSunlight;
                    characterDocument.career.DamageFromHolyPlaces = classFile.Career.DamageFromHolyPlaces;
                    characterDocument.career.Paralysis            = classFile.Career.Paralysis;
                    characterDocument.career.Disease = classFile.Career.Disease;
                }
                else if (classicTransformedRace == Races.Werewolf)
                {
                    // TODO: Restore pre-werewolf specials
                }
                else if (classicTransformedRace == Races.Wereboar)
                {
                    // TODO: Restore pre-wereboar specials
                }
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat("Could not restore old class specials for vamp/were import. Error: '{0}'", ex.Message);
            }
        }
Exemplo n.º 4
0
        //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);
        }