Beispiel #1
0
    void BIFItems()
    {
        List <string> objects = new List <string>();
        ResourceType  curType = TypeMap[curItemType];

        foreach (AuroraArchive archive in AuroraEngine.Resources.data.bifObjects)
        {
            if (archive.GetType() == typeof(RIMObject))
            {
                RIMObject rim = (RIMObject)archive;

                foreach ((string name, ResourceType rt) in rim.resources.Keys)
                {
                    if (rt != curType)
                    {
                        continue;
                    }
                    using (Stream stream = rim.GetResource(name, rt))
                    {
                        GFFObject obj = new GFFLoader(stream).GetObject();
                        objects.Add((string)obj["TemplateResRef"].Value);
                    }
                }
            }
            else if (archive.GetType() == typeof(FolderObject))
            {
                FolderObject folder = (FolderObject)archive;

                foreach ((string name, ResourceType rt) in folder.resources.Keys)
                {
                    if (rt != curType)
                    {
                        continue;
                    }
                    using (Stream stream = folder.GetResource(name, rt))
                    {
                        GFFObject obj = new GFFLoader(stream).GetObject();
                        objects.Add((string)obj["TemplateResRef"].Value);
                    }
                }
            }
        }

        bifItems = objects.ToArray();
    }
    void LoadGFFsFromRIMs(string moduleDir, Dictionary <string, ClassDefinition> defs, Compatibility compat, ExistsIn existsIn)
    {
        // We load every module in the game files

        // Find the list of module names
        // TODO: Implement this for KOTOR 2, which uses a different file structure

        foreach (string filename in Directory.GetFiles(moduleDir))
        {
            //Debug.Log("Loading " + filename);
            RIMObject obj = new RIMObject(filename);
            List <RIMObject.Resource> resources = new List <RIMObject.Resource>(obj.resources.Values);

            //Debug.Log(resources.Count());

            for (int i = 0; i < resources.Count(); i++)
            {
                RIMObject.Resource resource = resources[i];
                LoadRIM(obj, resource, defs, compat, existsIn);
            }
        }
    }
    void LoadRIM(RIMObject obj, RIMObject.Resource resource, Dictionary <string, ClassDefinition> defs, Compatibility compat, ExistsIn existsIn)
    {
        if (!gffTypes.Contains(resource.ResType))
        {
            return;
        }

        try
        {
            //Debug.Log("Loading resource " + resource.ResRef);
            string className = "Aurora" + resource.ResType.ToString().ToUpper().Replace(" ", "");

            // Load the resource from the RIM
            Stream    stream    = obj.GetResource(resource.ResRef, resource.ResType);
            GFFObject gffObject = new GFFLoader(stream).GetObject();
            LoadGFF(gffObject, defs, className, compat, existsIn);
        }
        catch
        {
            // Just keep going
            Debug.LogWarning("Failed to load " + resource.ResRef);
        }
    }
Beispiel #4
0
    void GetAllNCSFiles()
    {
        // Gets every NCS file in the game, including from all
        // modules
        files = new List <NCSFile>();

        // Load base game files
        AuroraData data = new AuroraData(
            Game.KotOR,
            null
            );

        Dictionary <string, int> baseGameActions = new Dictionary <string, int>();

        foreach ((string resref, ResourceType key) in data.keyObject.resourceKeys.Keys)
        {
            // Type code for NCS scripts is 2010
            if (key == ResourceType.NCS)
            {
                Debug.Log(resref);
                using (Stream stream = data.GetStream(resref, key))
                {
                    NCSFile file = new NCSFile(stream);
                    foreach (NCSOperation op in file.operations)
                    {
                        if (op.opcode == 0x05)
                        {
                            // This operation is an action, so we have to find the type and
                            // add it to the list
                            string action = NWScript_Actions.ACTIONS[int.Parse(op.args[1])];
                            if (!baseGameActions.ContainsKey(action))
                            {
                                baseGameActions.Add(action, 0);
                            }
                            baseGameActions[action]++;
                        }
                    }
                }
            }
        }

        Dictionary <string, Dictionary <string, int> > moduleActions = new Dictionary <string, Dictionary <string, int> >();

        Debug.Log("Found " + baseGameActions.Count + " actions in base game");

        // For each module, load the module data and get all the NCS files
        // First, get the list of modules
        string[] modules = Directory.GetFiles(
            AuroraData.GetPath("modules")
            );

        HashSet <string> moduleNames = new HashSet <string>();

        foreach (string module in modules)
        {
            string basename = Path.GetFileNameWithoutExtension(module.Replace("_s.rim", ""));
            moduleNames.Add(basename);
        }

        foreach (string module in moduleNames)
        {
            if (module != "end_m01aa")
            {
                // This is just for testing
                continue;
            }
            data.moduleName = module;
            data.LoadModuleFromGameFiles(false);
            Debug.Log("Loaded module " + module);

            // Now, get all the NCS files
            Dictionary <string, int> moduleCounts = new Dictionary <string, int>();

            // Get all items from the rim, srim, dlg, and mod files
            // rim file
            if (data.srim != null)
            {
                RIMObject rim = (RIMObject)data.srim;
                foreach ((string resref, ResourceType key) in rim.resources.Keys)
                {
                    // Type code for NCS scripts is 2010
                    if (key == ResourceType.NCS)
                    {
                        Debug.Log(resref);
                        using (Stream stream = data.GetStream(resref, key))
                        {
                            NCSFile file;
                            try
                            {
                                file = new NCSFile(stream);
                            }
                            catch (Exception e)
                            {
                                Debug.LogWarning("Failed to load script '" + resref + "' from module " + module + ": " + e.Message);
                                continue;
                            }
                            foreach (NCSOperation op in file.operations)
                            {
                                if (op.opcode == 0x05)
                                {
                                    // This operation is an action, so we have to find the type and
                                    // add it to the list
                                    string action = NWScript_Actions.ACTIONS[int.Parse(op.args[1])];
                                    if (!moduleCounts.ContainsKey(action))
                                    {
                                        moduleCounts.Add(action, 0);
                                    }
                                    moduleCounts[action]++;
                                }
                            }
                        }
                    }
                }
            }

            // Save the counts
            moduleActions.Add(module, moduleCounts);
        }

        foreach (string module in moduleNames)
        {
            if (!moduleActions.ContainsKey(module))
            {
                continue;
            }
            Debug.Log("Module " + module + " has " + moduleActions[module].Count + " actions");
        }

        status = new ProjectStatus()
        {
            baseGameActions = baseGameActions,
            moduleActions   = moduleActions
        };
    }