示例#1
0
        private bool ReadScripts()
        {
            LevelScriptCatalog.LoadCatalog();

            _languageFiles  = new List <string>();
            _levels         = new List <LevelScript>();
            _strings        = new List <LanguageScript>();
            _levelFileNames = new List <string>();

            try
            {
                using (var stream = File.OpenRead(_srcPath + "\\Script.txt"))
                    using (var reader = new StreamReader(stream))
                    {
                        var         lastBlock = Enumerations.None;
                        LevelScript lastLevel = null;

                        while (reader.EndOfStream == false)
                        {
                            string line = reader.ReadLine().Trim();

                            // Comment or empty line?
                            if (line.StartsWith(";") || line == "")
                            {
                                continue;
                            }

                            // Inline comment?
                            var tokensLine = line.Split(';');
                            line = tokensLine[0];

                            // Block header?
                            if (line.StartsWith("["))
                            {
                                if (line == "[PSXExtensions]")
                                {
                                    lastBlock = Enumerations.PsxExtensions;
                                    continue;
                                }

                                if (line == "[PCExtensions]")
                                {
                                    lastBlock = Enumerations.PcExtensions;
                                    continue;
                                }

                                if (line == "[Language]")
                                {
                                    lastBlock = Enumerations.Language;
                                    continue;
                                }

                                if (line == "[Options]")
                                {
                                    lastBlock = Enumerations.Options;
                                    continue;
                                }

                                if (line == "[Title]")
                                {
                                    lastBlock = Enumerations.Title;
                                    lastLevel = new LevelScript(true);
                                    _levels.Add(lastLevel);
                                    continue;
                                }

                                if (line == "[Level]")
                                {
                                    lastBlock = Enumerations.Level;
                                    lastLevel = new LevelScript(false);
                                    _levels.Add(lastLevel);
                                    continue;
                                }
                            }

                            // Block content?
                            var tokens = line.Split('=');
                            if (tokens.Length < 2)
                            {
                                continue;
                            }

                            string command = tokens[0].Trim();
                            string value   = tokens[1].Trim();

                            if (lastBlock == Enumerations.PsxExtensions)
                            {
                                if (command == "Level")
                                {
                                    _psxLevel = value;
                                }
                                else if (command == "Cut")
                                {
                                    _psxCut = value;
                                }
                                else if (command == "FMV")
                                {
                                    _psxFmv = value;
                                }
                            }

                            if (lastBlock == Enumerations.PcExtensions)
                            {
                                if (command == "Level")
                                {
                                    _pcLevel = value;
                                }
                                else if (command == "Cut")
                                {
                                    _pcCut = value;
                                }
                                else if (command == "FMV")
                                {
                                    _pcFmv = value;
                                }
                            }

                            if (lastBlock == Enumerations.Language)
                            {
                                if (command == "File")
                                {
                                    var tokensFile = value.Split(',');
                                    if (tokensFile.Length < 2 || !File.Exists(_srcPath + "\\" + tokensFile[1].Trim()))
                                    {
                                        continue;
                                    }
                                    _languageFiles.Add(tokensFile[1].Trim());
                                }
                            }

                            if (lastBlock == Enumerations.Options)
                            {
                                if (command == "LoadSave")
                                {
                                    _loadSave = (value == "ENABLED");
                                }
                                else if (command == "Title")
                                {
                                    _title = (value == "ENABLED");
                                }
                                else if (command == "PlayAnyLevel")
                                {
                                    _playAnyLevel = (value == "ENABLED");
                                }
                                else if (command == "FlyCheat")
                                {
                                    _flyCheat = (value == "ENABLED");
                                }
                                else if (command == "DemoDisc")
                                {
                                    _demoDisc = (value == "ENABLED");
                                }
                                else if (command == "InputTimeout")
                                {
                                    _inputTimeout = int.Parse(value);
                                }
                                else if (command == "Security")
                                {
                                    _security = Convert.ToByte(value.Replace("$", ""), 16);
                                }
                            }

                            if (lastBlock == Enumerations.Title || lastBlock == Enumerations.Level)
                            {
                                if (LevelScriptCatalog.Commands.ContainsKey(command))
                                {
                                    var cmd          = LevelScriptCatalog.Commands[command];
                                    var tokensParams = value.Split(',');
                                    if (tokensParams.Length != cmd.Parameters.Count)
                                    {
                                        continue;
                                    }

                                    var entry = new LevelScriptEntry(cmd);

                                    for (int j = 0; j < tokensParams.Length; j++)
                                    {
                                        string paramValue = tokensParams[j].Trim();

                                        switch (cmd.Parameters[j])
                                        {
                                        case LevelScriptCatalogParameterType.Boolean:
                                            entry.Parameters.Add(paramValue == "ENABLED");
                                            break;

                                        case LevelScriptCatalogParameterType.Hex:
                                            short val     = 0;
                                            bool  success = short.TryParse(paramValue.Replace("$", ""), NumberStyles.HexNumber, null, out val);
                                            entry.Parameters.Add(val);
                                            break;

                                        case LevelScriptCatalogParameterType.Int8:
                                            entry.Parameters.Add(byte.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.SInt8:
                                            entry.Parameters.Add(sbyte.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.Int16:
                                            entry.Parameters.Add(short.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.Int32:
                                            entry.Parameters.Add(int.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.String:
                                            entry.Parameters.Add(paramValue);
                                            break;
                                        }
                                    }

                                    if (entry.Command.Name == "Name")
                                    {
                                        lastLevel.Name = (string)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "Level")
                                    {
                                        lastLevel.FileName   = (string)entry.Parameters[0];
                                        lastLevel.AudioTrack = (byte)entry.Parameters[1];
                                    }

                                    lastLevel.Entries.Add(entry);
                                }
                            }
                        }
                    }

                foreach (var languageFile in _languageFiles)
                {
                    string languageFilePath = _srcPath + "\\" + languageFile;
                    if (!File.Exists(languageFilePath))
                    {
                        continue;
                    }
                    using (var reader = new StreamReader(File.OpenRead(languageFilePath)))
                    {
                        var    strings   = new LanguageScript();
                        string lastBlock = "";
                        while (reader.EndOfStream == false)
                        {
                            var line = reader.ReadLine().Trim();

                            if (line.StartsWith(";") || line == "")
                            {
                                continue;
                            }

                            if (line.StartsWith("["))
                            {
                                lastBlock = line;
                                continue;
                            }

                            if (lastBlock == "[Strings]")
                            {
                                strings.GeneralStrings.Add(line);
                            }
                            else if (lastBlock == "[PSXStrings]")
                            {
                                strings.PsxStrings.Add(line);
                            }
                            else if (lastBlock == "[PCStrings]")
                            {
                                strings.PcStrings.Add(line);
                            }
                        }
                        _strings.Add(strings);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        private bool ReadScripts()
        {
            LevelScriptCatalog.LoadCatalog();

            _languageStrings = new List <LanguageStrings>();
            _levels          = new List <LevelScript>();
            _levelFileNames  = new List <string>();

            try
            {
                using (var stream = File.OpenRead(_srcPath + "\\Script.txt"))
                    using (var reader = new StreamReader(stream))
                    {
                        var         lastBlock = Enumerations.None;
                        LevelScript lastLevel = null;

                        while (reader.EndOfStream == false)
                        {
                            string line = reader.ReadLine().Trim();

                            // Comment or empty line?
                            if (line.StartsWith(";") || line == "")
                            {
                                continue;
                            }

                            // Inline comment?
                            var tokensLine = line.Split(';');
                            line = tokensLine[0];

                            // Block header?
                            if (line.StartsWith("["))
                            {
                                if (line == "[Language]")
                                {
                                    lastBlock = Enumerations.Language;
                                    continue;
                                }

                                if (line == "[Options]")
                                {
                                    lastBlock = Enumerations.Options;
                                    continue;
                                }

                                if (line == "[Title]")
                                {
                                    lastBlock = Enumerations.Title;
                                    lastLevel = new LevelScript(true);
                                    _levels.Add(lastLevel);
                                    continue;
                                }

                                if (line == "[Level]")
                                {
                                    lastBlock = Enumerations.Level;
                                    lastLevel = new LevelScript(false);
                                    _levels.Add(lastLevel);
                                    continue;
                                }
                            }

                            // Block content?
                            var tokens = line.Split('=');
                            if (tokens.Length < 2)
                            {
                                continue;
                            }

                            string command = tokens[0].Trim();
                            string value   = tokens[1].Trim();

                            if (lastBlock == Enumerations.Language)
                            {
                                if (command == "File")
                                {
                                    var tokensFile = value.Split(',');
                                    if (tokensFile.Length < 2)
                                    {
                                        continue;
                                    }
                                    _languageStrings.Add(new LanguageStrings(tokensFile[2], tokensFile[1]));
                                }
                            }

                            if (lastBlock == Enumerations.Options)
                            {
                                if (command == "LoadSave")
                                {
                                    _loadSave = (value == "ENABLED");
                                }
                                else if (command == "Title")
                                {
                                    _title = (value == "ENABLED");
                                }
                                else if (command == "PlayAnyLevel")
                                {
                                    _playAnyLevel = (value == "ENABLED");
                                }
                                else if (command == "FlyCheat")
                                {
                                    _flyCheat = (value == "ENABLED");
                                }
                                else if (command == "Diagnostics")
                                {
                                    _diagnostics = (value == "ENABLED");
                                }
                                else if (command == "LevelFarView")
                                {
                                    _levelFarView = int.Parse(value);
                                }
                                else if (command == "Intro")
                                {
                                    _intro = value;
                                }
                            }

                            if (lastBlock == Enumerations.Title || lastBlock == Enumerations.Level)
                            {
                                if (LevelScriptCatalog.Commands.ContainsKey(command))
                                {
                                    var cmd          = LevelScriptCatalog.Commands[command];
                                    var tokensParams = value.Split(',');
                                    if (tokensParams.Length != cmd.Parameters.Count)
                                    {
                                        continue;
                                    }

                                    var entry = new LevelScriptEntry(cmd);

                                    for (int j = 0; j < tokensParams.Length; j++)
                                    {
                                        string paramValue = tokensParams[j].Trim();

                                        switch (cmd.Parameters[j])
                                        {
                                        case LevelScriptCatalogParameterType.Boolean:
                                            entry.Parameters.Add(paramValue == "ENABLED");
                                            break;

                                        case LevelScriptCatalogParameterType.Hex:
                                            short val     = 0;
                                            bool  success = short.TryParse(paramValue.Replace("$", ""), NumberStyles.HexNumber, null, out val);
                                            entry.Parameters.Add(val);
                                            break;

                                        case LevelScriptCatalogParameterType.Int8:
                                            entry.Parameters.Add(byte.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.SInt8:
                                            entry.Parameters.Add(sbyte.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.Int16:
                                            entry.Parameters.Add(short.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.Int32:
                                            entry.Parameters.Add(int.Parse(paramValue));
                                            break;

                                        case LevelScriptCatalogParameterType.String:
                                            entry.Parameters.Add(paramValue);
                                            break;
                                        }
                                    }

                                    if (entry.Command.Name == "Name")
                                    {
                                        lastLevel.Name = (string)entry.Parameters[0];
                                    }
                                    if (entry.Command.Name == "Background")
                                    {
                                        lastLevel.Background = (string)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "AmbientTrack")
                                    {
                                        lastLevel.AudioTrack = byte.Parse(entry.Parameters[0].ToString());
                                    }
                                    else if (entry.Command.Name == "LaraType")
                                    {
                                        lastLevel.LaraType = GetLaraType((string)entry.Parameters[0]);
                                    }
                                    else if (entry.Command.Name == "Horizon")
                                    {
                                        lastLevel.Horizon = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "ResetInventory")
                                    {
                                        lastLevel.ResetInventory = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "Sky")
                                    {
                                        lastLevel.Sky = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "ColAddHorizon")
                                    {
                                        lastLevel.ColAddHorizon = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "Lightning")
                                    {
                                        lastLevel.Lightning = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "UVRotate")
                                    {
                                        lastLevel.UVRotate = (byte)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "LevelFarView")
                                    {
                                        lastLevel.LevelFarView = (int)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "LoadScreen")
                                    {
                                        lastLevel.LoadScreen = (string)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "LevelFile")
                                    {
                                        lastLevel.FileName = (string)entry.Parameters[0];
                                    }
                                    else if (entry.Command.Name == "Rumble")
                                    {
                                        lastLevel.Rumble = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "UnlimitedAir")
                                    {
                                        lastLevel.UnlimitedAir = (entry.Parameters[0].ToString() == "True");
                                    }
                                    else if (entry.Command.Name == "Weather")
                                    {
                                        if (entry.Parameters[0].ToString() == "RAIN")
                                        {
                                            lastLevel.Weather = Weather.Rain;
                                        }
                                        else if (entry.Parameters[0].ToString() == "SNOW")
                                        {
                                            lastLevel.Weather = Weather.Snow;
                                        }
                                    }
                                    else if (entry.Command.Name == "Level")
                                    {
                                        lastLevel.FileName   = (string)entry.Parameters[0];
                                        lastLevel.AudioTrack = (byte)entry.Parameters[1];
                                    }

                                    lastLevel.Entries.Add(entry);
                                }
                            }
                        }
                    }

                for (int i = 0; i < _languageStrings.Count; i++)
                {
                    string languageFilePath = _srcPath + "\\" + _languageStrings[i].FileName;
                    if (!File.Exists(languageFilePath))
                    {
                        continue;
                    }

                    using (var reader = new StreamReader(File.OpenRead(languageFilePath)))
                    {
                        var    strings   = new LanguageScript();
                        string lastBlock = "";
                        while (reader.EndOfStream == false)
                        {
                            var line = reader.ReadLine().Trim();

                            if (line.StartsWith(";") || line == "")
                            {
                                continue;
                            }

                            if (line.StartsWith("["))
                            {
                                lastBlock = line;
                                continue;
                            }

                            _languageStrings[i].Strings.Add(line);
                        }
                    }
                }

                _tracks = new List <string>();
                using (var reader = new StreamReader(File.OpenRead(_srcPath + "\\" + "Tracks.txt")))
                {
                    while (reader.EndOfStream == false)
                    {
                        _tracks.Add(reader.ReadLine());
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }