Example #1
0
        public static Texture2D LoadTexture2D(string resref)
        {
            if (!loadedTextures.ContainsKey(resref))
            {
                Texture2D tex;
                Stream    stream;
                if (null != (stream = data.GetStream(resref, ResourceType.TPC)))
                {
                    TPCObject tpc = new TPCObject(stream);

                    tex = new Texture2D(tpc.Width, tpc.Height, tpc.Format, false);

                    tex.LoadRawTextureData(tpc.RawData);
                    tex.Apply();

                    tex.anisoLevel = ANISO_LEVEL;
                }
                else if (null != (stream = data.GetStream(resref, ResourceType.TGA)))
                {
                    tex            = TGALoader.LoadTGA(stream);
                    tex.anisoLevel = ANISO_LEVEL;
                }
                else
                {
                    //Debug.Log("Missing texture: " + resref);
                    return(new Texture2D(1, 1));
                }
                //loadedTextures[resref + "_base"] = tex;
                //tex = ImageFilter.Upscale(tex);

                loadedTextures[resref] = tex;
            }

            //return NormalGeneration.Diff2Normal(loadedTextures[resref]);
            return(loadedTextures[resref]);
        }
Example #2
0
        public static Dictionary <string, Vector3> LoadLayout(string resref, AuroraData data)
        {
            // Debug.Log("Loading layout " + resref);
            Stream stream = data.GetStream(resref, ResourceType.LYT);
            // Debug.Log("Loaded stream " + stream);
            StreamReader reader = new StreamReader(stream, Encoding.ASCII);
            // string text = reader.ReadToEnd();
            // Debug.Log(text);
            // Reset the reader back to the start
            // reader.BaseStream.Seek(0, SeekOrigin.Begin);

            Dictionary <string, Vector3> roomVectors = new Dictionary <string, Vector3>();
            bool   doingLayout = false;
            int    parseType   = 0;
            string line;

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                Debug.Log(line);

                if (line.Contains("beginlayout"))
                {
                    doingLayout = true;
                }
                else if (line.Contains("donelayout"))
                {
                    doingLayout = false;
                }

                if (doingLayout)
                {
                    if (line.Contains("roomcount"))
                    {
                        parseType = 1;
                        continue;
                    }
                    else if (line.Contains("trackcount"))
                    {
                        parseType = 2;
                        continue;
                    }
                    else if (line.Contains("obstaclecount"))
                    {
                        parseType = 3;
                        continue;
                    }
                    else if (line.Contains("doorhookcount"))
                    {
                        parseType = 4;
                        continue;
                    }

                    switch (parseType)
                    {
                    case 1:         //rooms
                        string[] arr = line.Trim().Split(' ');
                        if (roomVectors != null)
                        {
                            roomVectors.Add(arr[0], new Vector3(float.Parse(arr[1]), float.Parse(arr[3]), float.Parse(arr[2])));
                        }
                        break;

                    default:        //TODO: tracks, obstacles, door hooks
                        break;
                    }
                }
            }

            return(roomVectors);
        }
Example #3
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
        };
    }