예제 #1
0
    void LoadGame()
    {
        AuroraEngine.Resources.Load(null);

        if (AuroraPrefs.DeveloperMode())
        {
            modules = Directory.GetDirectories(AuroraPrefs.GetKotorLocation() + "\\modules", "*");
        }
        else
        {
            modules = Directory.GetFiles(AuroraPrefs.GetKotorLocation() + "\\modules", "*");
        }

        names = new List <string>();

        foreach (string mod in modules)
        {
            // Skip _s and DLG files
            if (mod.Contains("_s") || mod.Contains("dlg"))
            {
                continue;
            }
            string name = mod.ToUpper().Split('\\').Last().Replace(".RIM", "").Replace(".MOD", "");
            if (!names.Contains(name))
            {
                names.Add(name);
            }
        }
    }
예제 #2
0
    public void SaveDLGToFile()
    {
        string filename = EditorUtility.SaveFilePanel("Save File As...", "", "dialog.dlg", "");

        KModuleEditor.CreateGFFFile(AuroraPrefs.GetModuleOutLocation(), "dialog", dlg, "dlg");
        File.Move(AuroraPrefs.GetModuleOutLocation() + "/dialog.dlg", filename);
    }
예제 #3
0
    Dictionary <string, ClassDefinition> LoadBaseGameGFFs(Compatibility compat)
    {
        string loc = compat == Compatibility.KotOR ? AuroraPrefs.GetK1Location() : AuroraPrefs.GetTSLLocation();

        Dictionary <string, ClassDefinition> defs = new Dictionary <string, ClassDefinition>();

        // Read GFF objects from disk
        Debug.Log("Loading BIFs");
        LoadGFFsFromBIFs(loc + "\\data", defs, compat, ExistsIn.BASE);

        Debug.Log("Loading RIMs");
        LoadGFFsFromRIMs(loc + "\\modules", defs, compat, ExistsIn.BASE);

        if (compat == Compatibility.TSL)
        {
            // Load data from all .erf files (which are ERF files, and contain DLG files for the module)
            foreach (string erf in Directory.GetFiles(loc + "\\modules", "*.erf"))
            {
                LoadGFFsFromERF(erf, defs, compat, ExistsIn.BASE);
            }

            // Load data from all .mod files (which are ERF files)
            foreach (string mod in Directory.GetFiles(loc + "\\modules", "*.mod"))
            {
                LoadGFFsFromERF(mod, defs, compat, ExistsIn.BASE);
            }
        }

        return(defs);
    }
예제 #4
0
 public static bool DeveloperMode()
 {
     if (prefs == null)
     {
         prefs = GetOrCreateSettings();
     }
     return(prefs.devMode);
 }
예제 #5
0
    //public Game TargetGame ()
    //{
    //    return game;
    //}

    public static Game TargetGame()
    {
        if (prefs == null)
        {
            prefs = GetOrCreateSettings();
        }
        return(prefs.game);
    }
예제 #6
0
        public override int ReadAttribute(byte[] data, int offset, FieldInfo f, object target, Dictionary <string, byte[]> other)
        {
            if (AuroraPrefs.TargetGame() == Game.KotOR)
            {
                return(offset);
            }

            return(offset + 4);

            //// Read the attribute if we reach this point, by calling the base function
            //return base.ReadAttribute(data, offset, f, target, other);
        }
예제 #7
0
        public static AudioClip LoadAudio(string resref)
        {
            // using (FileStream stream = File.Open(AuroraPrefs.GetKotorLocation() + "\\streammusic\\" + resref + ".wav", FileMode.Open)) {
            using (FileStream stream = File.Open(AuroraPrefs.GetKotorLocation() + "/streammusic/" + resref + ".wav", FileMode.Open))
            {
                WAVObject wav = new WAVObject(stream);

                AudioClip clip = AudioClip.Create(resref, wav.data.Length / wav.channels, wav.channels, wav.sampleRate, false);
                clip.SetData(wav.data, 0);

                return(clip);
            }
        }
예제 #8
0
    public static string GetKotorLocation()
    {
        if (prefs == null)
        {
            prefs = GetOrCreateSettings();
        }
        if (prefs.game == Game.KotOR)
        {
            return(prefs.k1Location);
        }

        return(prefs.tslLocation);
    }
예제 #9
0
    Dictionary <string, ClassDefinition> LoadSaveGFFs(Compatibility compat)
    {
        string loc = compat == Compatibility.KotOR ? AuroraPrefs.GetK1SaveLocation() : AuroraPrefs.GetTSLSaveLocation();

        Dictionary <string, ClassDefinition> defs = new Dictionary <string, ClassDefinition>();

        foreach (string saveFolder in Directory.GetDirectories(loc))
        {
            Debug.Log(saveFolder);

            string[] subFolders = Directory.GetDirectories(saveFolder);

            // Shuffle the subfolders and pick some
            //System.Random rnd = new System.Random();
            //subFolders = subFolders.OrderBy(c => rnd.Next()).ToArray();
            int i = 0;
            foreach (string subFolder in subFolders)
            {
                Debug.Log(subFolder);

                /* Saves consist of five files:
                 *   - GLOBALVARS.res: generic .res file
                 *   - PARTYTABLE.res: generic .res file
                 *   - SAVEGAME.sav: ERF file containing save information
                 *   - savenfo.res: generic .res file
                 *   - Screen.tga (can ignore this)
                 */
                // Load the GFFs
                LoadGFFFromFile(subFolder + "\\GLOBALVARS.res", defs, "AuroraGlobalVars", compat, ExistsIn.SAVE);
                LoadGFFFromFile(subFolder + "\\PARTYTABLE.res", defs, "AuroraPartyTable", compat, ExistsIn.SAVE);
                LoadGFFFromFile(subFolder + "\\savenfo.res", defs, "AuroraSaveNfo", compat, ExistsIn.SAVE);

                // Load the SAV (in ERF format)
                LoadGFFsFromERF(subFolder + "\\SAVEGAME.sav", defs, compat, ExistsIn.SAVE);
                //if (i >= 2)
                //{
                //    break;
                //}
                //break;
            }
        }

        return(defs);
    }
예제 #10
0
    public static AuroraPrefs GetOrCreateSettings()
    {
        var settings = AssetDatabase.LoadAssetAtPath <AuroraPrefs>(k_MyCustomSettingsPath);

        if (settings == null)
        {
            Debug.LogWarning("Creating settings file");
            settings             = ScriptableObject.CreateInstance <AuroraPrefs>();
            settings.k1Location  = "D:\\SteamLibrary\\steamapps\\common\\swkotor";
            settings.tslLocation = "D:\\SteamLibrary\\steamapps\\common\\Knights of the Old Republic II";
            settings.game        = Game.KotOR;
            settings.devMode     = false;
            AssetDatabase.CreateAsset(settings, k_MyCustomSettingsPath);
            AssetDatabase.SaveAssets();
        }

        prefs = settings;
        return(settings);
    }
예제 #11
0
        //public static TLKObject LoadTLK()
        //{
        //    string xml = RunXoreosTools(AuroraPrefs.GetKotorLocation() + "/dialog.tlk", "tlk2xml", "--kotor");
        //    return new TLKObject(xml);
        //}

        public static TLK LoadTLK()
        {
            string tlk_location = AuroraPrefs.GetKotorLocation() + "/dialog.tlk";

            TLK tlk = new TLK();

            using (Stream stream = File.OpenRead(tlk_location))
            {
                tlk.Load(stream, new Dictionary <string, Stream>(), skip: 0);
            }

            UnityEngine.Debug.Log("Loaded " + tlk.stringCount + " strings");

            return(tlk);
            // UnityEngine.Debug.Log("Dictionary is of size " + tlk.strings.Count);

            // TLKObject tlkObject = new TLKObject(tlk);

            // return tlkObject;
        }
예제 #12
0
    public static SettingsProvider CreateMyCustomSettingsProvider()
    {
        // First parameter is the path in the Settings window.
        // Second parameter is the scope of this setting: it only appears in the Project Settings window.
        var provider = new SettingsProvider("Project/Aurora Preferences", SettingsScope.Project)
        {
            //// By default the last token of the path is used as display name if no label is provided.
            //label = "Aurora Preferences",
            // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
            guiHandler = (searchContext) =>
            {
                SerializedObject settings = AuroraPrefs.GetSerializedSettings();
                EditorGUILayout.PropertyField(settings.FindProperty("game"), new GUIContent("Target Game"));

                EditorGUILayout.Space();

                EditorGUILayout.PropertyField(settings.FindProperty("k1Location"), new GUIContent("KotOR Location"));
                EditorGUILayout.PropertyField(settings.FindProperty("tslLocation"), new GUIContent("TSL Location"));

                EditorGUILayout.Space();

                EditorGUILayout.PropertyField(settings.FindProperty("k1SaveLocation"), new GUIContent("KotOR Save Location"));
                EditorGUILayout.PropertyField(settings.FindProperty("tslSaveLocation"), new GUIContent("TSL Save Location"));

                EditorGUILayout.Space();

                EditorGUILayout.LabelField("NOTE: The 'Module Out Location' directory is used for temp storage, and its contents WILL OFTEN be fully and non-reversibly deleted!");
                EditorGUILayout.PropertyField(settings.FindProperty("moduleOutLocation"), new GUIContent("Module Out Location"));

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(settings.FindProperty("devMode"), new GUIContent("Developer Mode"));

                settings.ApplyModifiedProperties();
            },

            //// Populate the search keywords to enable smart search filtering and label highlighting:
            //keywords = new HashSet<string>(new[] { "Number", "Some String" })
        };

        return(provider);
    }
예제 #13
0
        static AudioClip LoadVOAlternative(string resref)
        {
            // Check if the resref is long enough
            if (resref.Length <= 11)
            {
                return(null);
            }
            resref = resref.Replace("_", "") + "_";

            // Firstly, check if it's in the top-level


            // The first five characters are the top-level folder
            string topFolder = resref.Substring(1, 5);
            // Next six characters are the subfolder
            string subFolder = resref.Substring(6, 6);

            string fullname = AuroraPrefs.GetKotorLocation() + "/streamwaves/" + topFolder + "/" + subFolder + "/" + resref + ".wav";

            // string fullname = AuroraPrefs.GetKotorLocation() + "\\streamwaves\\" + topFolder + "\\" + subFolder + "\\" + resref + ".wav";

            if (!File.Exists(fullname))
            {
                UnityEngine.Debug.Log("Did not find resref " + resref + " with filename " + fullname);
                return(null);
            }

            using (FileStream stream = File.Open(fullname, FileMode.Open))
            {
                WAVObject wav = new WAVObject(stream);

                AudioClip clip = AudioClip.Create(resref, wav.data.Length / wav.channels, wav.channels, wav.sampleRate, false);
                clip.SetData(wav.data, 0);

                return(clip);
            }
        }
예제 #14
0
    public string ToXML(string gffType, bool isRecursive = false, string structLabel = "")
    {
        // Writes this object in GFF format

        // Convert the object to XML
        string xml         = !isRecursive ? "<gff3 type=\"" + gffType + "\">" : "";
        bool   hasStructID = false;
        uint   structid    = 0;

        List <string> values = new List <string>();

        foreach (FieldInfo f in GetType().GetFields())
        {
            GFFAttribute attr = f.GetCustomAttribute <GFFAttribute>();

            string        label    = attr.name;
            Compatibility compat   = attr.compatibility;
            ExistsIn      existsIn = attr.existsIn;

            //Debug.Log("Compat: " + compat + "; exists: " + existsIn);

            // Make sure we only write fields compatible with the target game
            if (compat == Compatibility.KotOR && AuroraPrefs.TargetGame() == Game.TSL)
            {
                continue;
            }
            if (compat == Compatibility.TSL && AuroraPrefs.TargetGame() == Game.KotOR)
            {
                continue;
            }

            // Don't write save-only fields when writing modules
            // TODO: Allow an override for this in case mods need it?
            if (existsIn == ExistsIn.SAVE)
            {
                continue;
            }

            object value = f.GetValue(this);
            if (value == null)
            {
                continue;
            }

            if (label == "structid")
            {
                // The struct ID should be dealt with separately
                structid    = (uint)f.GetValue(this);
                hasStructID = true;
                continue;
            }

            if (f.FieldType.IsSubclassOf(typeof(AuroraStruct)))
            {
                AuroraStruct structVal = (AuroraStruct)value;
                // This is a nested AuroraStruct
                values.Add(structVal.ToXML(gffType, true, label));
            }
            else if (f.FieldType.IsGenericType && (f.FieldType.GetGenericTypeDefinition() == typeof(List <>)))
            {
                // This is a list
                string listXML = "<list label=\"" + label + "\"";
                IList  list    = (IList)value;

                if (list == null)
                {
                    continue;
                }

                if (list.Count == 0)
                {
                    listXML += "/>";
                }
                else
                {
                    listXML += ">";

                    foreach (AuroraStruct item in list)
                    {
                        listXML += item.ToXML(gffType, true);
                    }

                    listXML += "</list>";
                }

                values.Add(listXML);
            }
            else if (f.FieldType == typeof(GFFObject.CExoLocString))
            {
                values.Add(((GFFObject.CExoLocString)value).ToXML(f.Name));
            }
            else if (f.FieldType == typeof(GFFObject.CExoString))
            {
                values.Add(((GFFObject.CExoString)value).ToXML(f.Name));
            }
            else if (f.FieldType == typeof(Quaternion))
            {
                Quaternion q       = (Quaternion)value;
                string     quatXML = "<orientation label=\"" + f.Name + "\">";

                quatXML += "<double>" + q.x + "</double>";
                quatXML += "<double>" + q.y + "</double>";
                quatXML += "<double>" + q.z + "</double>";
                quatXML += "<double>" + q.w + "</double>";

                quatXML += "</orientation>";
                values.Add(quatXML);
            }
            else if (f.FieldType == typeof(Vector3))
            {
                Vector3 v      = (Vector3)value;
                string  vecXML = "<vector label=\"" + f.Name + "\">";

                vecXML += "<double>" + v.x + "</double>";
                vecXML += "<double>" + v.y + "</double>";
                vecXML += "<double>" + v.z + "</double>";

                vecXML += "</vector>";
                values.Add(vecXML);
            }
            else if (f.FieldType == typeof(Byte[]))
            {
                // Source: https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa
                string b64 = Convert.ToBase64String((byte[])value, Base64FormattingOptions.InsertLineBreaks);

                values.Add("<data label=\"" + label + "\">" + b64 + "</data>");
            }
            else if (f.FieldType == typeof(Byte))
            {
                byte   b       = (byte)f.GetValue(this);
                string byteXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    byteXML += " label=\"" + label + "\"";
                }
                byteXML += ">" + b.ToString() + "</" + TypeNames[f.FieldType] + ">";

                values.Add(byteXML);
            }
            else if (f.FieldType == typeof(Char))
            {
                char   c       = (char)f.GetValue(this);
                string charXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    charXML += " label=\"" + label + "\"";
                }

                if ((int)c == 0)
                {
                    charXML += "/>";
                }
                else
                {
                    charXML += ">" + c.ToString() + "</" + TypeNames[f.FieldType] + ">";
                }

                values.Add(charXML);
            }
            else
            {
                if (!TypeNames.ContainsKey(f.FieldType))
                {
                    Debug.Log("Could not find field type" + f.FieldType);
                }

                string valXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    valXML += " label=\"" + label + "\"";
                }

                valXML += ">" + value.ToString() + "</" + TypeNames[f.FieldType] + ">";

                values.Add(valXML);
            }
        }

        string structLabelXML = "";

        if (structLabel != null && structLabel != "")
        {
            structLabelXML = " label=\"" + structLabel + "\"";
        }

        if (!isRecursive)
        {
            xml += "<struct id=\"4294967295\"" + structLabelXML + ">";
        }
        else if (hasStructID)
        {
            xml += "<struct id=\"" + structid + "\"" + structLabelXML + ">";
        }
        else
        {
            xml += "<struct id = \"0\"" + structLabelXML + ">";
        }

        foreach (string s in values)
        {
            xml += s;
        }

        xml += "</struct>";

        if (!isRecursive)
        {
            xml += "</gff3>";
        }

        return(xml);
    }