Example #1
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
        };
    }