Exemple #1
0
        void RunEntryScript()
        {
            if (VariableEntryScript.HasValue && _variables[VariableEntryScript.Value] != 0)
            {
                RunScript(_variables[VariableEntryScript.Value], false, false, new int[0]);
            }

            if (!_ignoreEntryExitScript && roomData != null && roomData.EntryScript.Data != null)
            {
                int slot = GetScriptSlotIndex();
                _slots[slot] = new ScriptSlot
                {
                    Status = ScriptStatus.Running,
                    Number = 10002,
                    Where  = WhereIsObject.Room,
                };
                _currentScriptData = roomData.EntryScript.Data;
                RunScriptNested(slot);
            }

            if (VariableEntryScript2.HasValue && _variables[VariableEntryScript2.Value] != 0)
            {
                RunScript(_variables[VariableEntryScript2.Value], false, false, new int[0]);
            }
        }
Exemple #2
0
        public void RunScript(int scriptNum, bool freezeResistant, bool recursive, int[] data)
        {
            if (scriptNum == 0)
            {
                return;
            }

            if (!recursive)
            {
                StopScript(scriptNum);
            }

            WhereIsObject scriptType;

            if (scriptNum < _resManager.NumGlobalScripts)
            {
                ResourceManager.LoadScript(scriptNum);
                scriptType = WhereIsObject.Global;
            }
            else
            {
                scriptType = WhereIsObject.Local;
            }

            var slotIndex = GetScriptSlotIndex();

            _slots[slotIndex] = new ScriptSlot
            {
                Number          = (ushort)scriptNum,
                Status          = ScriptStatus.Running,
                FreezeResistant = freezeResistant,
                Recursive       = recursive,
                Where           = scriptType
            };

            UpdateScriptData(slotIndex);
            _slots[slotIndex].InitializeLocals(data);
            RunScriptNested(slotIndex);
        }
Exemple #3
0
        protected void RunObjectScript(int obj, byte entry, bool freezeResistant, bool recursive, int[] vars, int slot = -1)
        {
            if (obj == 0)
            {
                return;
            }

            if (!recursive && (Game.Version >= 3))
            {
                StopObjectScriptCore((ushort)obj);
            }

            var where = GetWhereIsObject(obj);

            if (where == WhereIsObject.NotFound)
            {
                //                Console.Error.WriteLine("warning: Code for object {0} not in room {1}", obj, _roomResource);
                return;
            }

            // Find a free object slot, unless one was specified
            if (slot == -1)
            {
                slot = GetScriptSlotIndex();
            }

            ObjectData objFound = null;

            if (roomData != null)
            {
                objFound = (from o in roomData.Objects.Concat(_invData)
                            where o != null
                            where o.Number == obj
                            where o.ScriptOffsets.ContainsKey(entry) || o.ScriptOffsets.ContainsKey(0xFF)
                            select o).FirstOrDefault();
            }

            if (objFound == null)
            {
                objFound = (from o in _objs
                            where o.Number == obj
                            where o.ScriptOffsets.ContainsKey(entry) || o.ScriptOffsets.ContainsKey(0xFF)
                            select o).FirstOrDefault();
            }

            if (objFound == null)
            {
                return;
            }

            _slots[slot] = new ScriptSlot
            {
                Number          = (ushort)obj,
                InventoryEntry  = entry,
                Offset          = (uint)((objFound.ScriptOffsets.ContainsKey(entry) ? objFound.ScriptOffsets[entry] : objFound.ScriptOffsets[0xFF]) - objFound.Script.Offset),
                Status          = ScriptStatus.Running,
                Where           = where,
                FreezeResistant = freezeResistant,
                Recursive       = recursive
            };

            _slots[slot].InitializeLocals(vars);

            // V0 Ensure we don't try and access objects via index inside the script
            //_v0ObjectIndex = false;
            UpdateScriptData((ushort)slot);
            RunScriptNested(slot);
        }
Exemple #4
0
        protected ScummEngine(GameSettings settings, IGraphicsManager gfxManager, IInputManager inputManager, IMixer mixer)
        {
            Settings = settings;
            var game = (GameInfo)settings.Game;
            _resManager = ResourceManager.Load(game);

            _game = game;
            InvalidBox = _game.Version < 5 ? (byte)255 : (byte)0;
            _gameMD5 = ToMd5Bytes(game.MD5);
            _gfxManager = gfxManager;
            _inputManager = inputManager;
            _inputState = inputManager.GetState();
            _strings = new byte[_resManager.NumArray][];
            _inventory = new ushort[_resManager.NumInventory];
            _invData = new ObjectData[_resManager.NumInventory];
            CurrentScript = 0xFF;
            Mixer = mixer;
            ScreenWidth = Game.Width;
            ScreenHeight = Game.Height;

            AudioCDManager = new DefaultAudioCDManager(this, mixer);
            Sound = new Sound(this, mixer);

            SetupMusic();

            _variables = new int[_resManager.NumVariables];
            _bitVars = new BitArray(_resManager.NumBitVariables);
            _slots = new ScriptSlot[NumScriptSlot];
            for (int i = 0; i < NumScriptSlot; i++)
            {
                _slots[i] = new ScriptSlot();
            }
            for (int i = 0; i < 200; i++)
            {
                _objs[i] = new ObjectData();
            }
            for (int i = 0; i < 6; i++)
            {
                _string[i] = new TextSlot();
                if (game.Version != 3)
                {
                    _string[i].Default.Position = new Point(2, 5);
                }
            }
            _colorCycle = new ColorCycle[16];
            for (int i = 0; i < _colorCycle.Length; i++)
            {
                _colorCycle[i] = new ColorCycle();
            }
            _nest = new NestedScript[MaxScriptNesting + 1];
            for (int i = 0; i < _nest.Length; i++)
            {
                _nest[i] = new NestedScript();
            }
            _scaleSlots = new ScaleSlot[20];
            for (int i = 0; i < _scaleSlots.Length; i++)
            {
                _scaleSlots[i] = new ScaleSlot();
            }

            Gdi = Gdi.Create(this, game);
            switch (game.Version)
            {
                case 0:
                    _costumeLoader = new CostumeLoader0(this);
                    _costumeRenderer = new CostumeRenderer0(this);
                    break;
                case 7:
                case 8:
                    _costumeLoader = new AkosCostumeLoader(this);
                    _costumeRenderer = new AkosRenderer(this);
                    break;
                default:
                    _costumeLoader = new ClassicCostumeLoader(this);
                    _costumeRenderer = new ClassicCostumeRenderer(this);
                    break;
            }

            CreateCharset();
            ResetCursors();

            // Create the text surface
            var pixelFormat = _game.Features.HasFlag(GameFeatures.Is16BitColor) ? PixelFormat.Rgb16 : PixelFormat.Indexed8;
            _textSurface = new Surface(ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, PixelFormat.Indexed8, false);
            ClearTextSurface();

            if (Game.Platform == Platform.FMTowns)
            {
                _townsScreen = new TownsScreen(_gfxManager, ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, PixelFormat.Rgb16);
                _townsScreen.SetupLayer(0, ScreenWidth, ScreenHeight, 32767);
                _townsScreen.SetupLayer(1, ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, 16, _textPalette);
            }

            if (Game.Version == 0)
            {
                InitScreens(8, 144);
            }
            else if ((Game.GameId == GameId.Maniac) && (_game.Version <= 1) && _game.Platform != Platform.NES)
            {
                InitScreens(16, 152);
            }
            else if (Game.Version >= 7)
            {
                InitScreens(0, ScreenHeight);
            }
            else
            {
                InitScreens(16, 144);
            }
            // Allocate gfx compositing buffer (not needed for V7/V8 games).
            if (Game.Version < 7)
            {
                _composite = new Surface(ScreenWidth, ScreenHeight, pixelFormat, false);
            }
            InitActors();
            OwnerRoom = Game.Version >= 7 ? 0x0FF : 0x0F;

            if (Game.Version < 7)
            {
                Camera.LeftTrigger = 10;
                Camera.RightTrigger = 30;
            }

            InitPalettes();
            InitializeVerbs();

            // WORKAROUND for bug in boot script of Loom (CD)
            // The boot script sets the characters of string 21,
            // before creating the string.resource.
            if (_game.GameId == GameId.Loom)
            {
                _strings[21] = new byte[13];
            }
        }
Exemple #5
0
        protected ScummEngine(GameSettings settings, IGraphicsManager gfxManager, IInputManager inputManager, IMixer mixer)
        {
            Settings = settings;
            var game = (GameInfo)settings.Game;

            _resManager = ResourceManager.Load(game);

            _game         = game;
            InvalidBox    = _game.Version < 5 ? (byte)255 : (byte)0;
            _gameMD5      = ToMd5Bytes(game.MD5);
            _gfxManager   = gfxManager;
            _inputManager = inputManager;
            _inputState   = inputManager.GetState();
            _strings      = new byte[_resManager.NumArray][];
            _inventory    = new ushort[_resManager.NumInventory];
            _invData      = new ObjectData[_resManager.NumInventory];
            CurrentScript = 0xFF;
            Mixer         = mixer;
            ScreenWidth   = Game.Width;
            ScreenHeight  = Game.Height;

            AudioCDManager = new DefaultAudioCDManager(this, mixer);
            Sound          = new Sound(this, mixer);

            SetupMusic();

            _variables = new int[_resManager.NumVariables];
            _bitVars   = new BitArray(_resManager.NumBitVariables);
            _slots     = new ScriptSlot[NumScriptSlot];
            for (int i = 0; i < NumScriptSlot; i++)
            {
                _slots[i] = new ScriptSlot();
            }
            for (int i = 0; i < 200; i++)
            {
                _objs[i] = new ObjectData();
            }
            for (int i = 0; i < 6; i++)
            {
                _string[i] = new TextSlot();
                if (game.Version != 3)
                {
                    _string[i].Default.Position = new Point(2, 5);
                }
            }
            _colorCycle = new ColorCycle[16];
            for (int i = 0; i < _colorCycle.Length; i++)
            {
                _colorCycle[i] = new ColorCycle();
            }
            _nest = new NestedScript[MaxScriptNesting + 1];
            for (int i = 0; i < _nest.Length; i++)
            {
                _nest[i] = new NestedScript();
            }
            _scaleSlots = new ScaleSlot[20];
            for (int i = 0; i < _scaleSlots.Length; i++)
            {
                _scaleSlots[i] = new ScaleSlot();
            }

            Gdi = Gdi.Create(this, game);
            switch (game.Version)
            {
            case 0:
                _costumeLoader   = new CostumeLoader0(this);
                _costumeRenderer = new CostumeRenderer0(this);
                break;

            case 7:
            case 8:
                _costumeLoader   = new AkosCostumeLoader(this);
                _costumeRenderer = new AkosRenderer(this);
                break;

            default:
                _costumeLoader   = new ClassicCostumeLoader(this);
                _costumeRenderer = new ClassicCostumeRenderer(this);
                break;
            }

            CreateCharset();
            ResetCursors();

            // Create the text surface
            var pixelFormat = _game.Features.HasFlag(GameFeatures.Is16BitColor) ? PixelFormat.Rgb16 : PixelFormat.Indexed8;

            _textSurface = new Surface(ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, PixelFormat.Indexed8, false);
            ClearTextSurface();

            if (Game.Platform == Platform.FMTowns)
            {
                _townsScreen = new TownsScreen(_gfxManager, ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, PixelFormat.Rgb16);
                _townsScreen.SetupLayer(0, ScreenWidth, ScreenHeight, 32767);
                _townsScreen.SetupLayer(1, ScreenWidth * _textSurfaceMultiplier, ScreenHeight * _textSurfaceMultiplier, 16, _textPalette);
            }

            if (Game.Version == 0)
            {
                InitScreens(8, 144);
            }
            else if ((Game.GameId == GameId.Maniac) && (_game.Version <= 1) && _game.Platform != Platform.NES)
            {
                InitScreens(16, 152);
            }
            else if (Game.Version >= 7)
            {
                InitScreens(0, ScreenHeight);
            }
            else
            {
                InitScreens(16, 144);
            }
            // Allocate gfx compositing buffer (not needed for V7/V8 games).
            if (Game.Version < 7)
            {
                _composite = new Surface(ScreenWidth, ScreenHeight, pixelFormat, false);
            }
            InitActors();
            OwnerRoom = Game.Version >= 7 ? 0x0FF : 0x0F;

            if (Game.Version < 7)
            {
                Camera.LeftTrigger  = 10;
                Camera.RightTrigger = 30;
            }

            InitPalettes();
            InitializeVerbs();

            // WORKAROUND for bug in boot script of Loom (CD)
            // The boot script sets the characters of string 21,
            // before creating the string.resource.
            if (_game.GameId == GameId.Loom)
            {
                _strings[21] = new byte[13];
            }
        }
Exemple #6
0
        public void RunScript(int scriptNum, bool freezeResistant, bool recursive, int[] data)
        {
            if (scriptNum == 0)
                return;

            if (!recursive)
                StopScript(scriptNum);

            WhereIsObject scriptType;
            if (scriptNum < _resManager.NumGlobalScripts)
            {
                ResourceManager.LoadScript(scriptNum);
                scriptType = WhereIsObject.Global;
            }
            else
            {
                scriptType = WhereIsObject.Local;
            }

            var slotIndex = GetScriptSlotIndex();
            _slots[slotIndex] = new ScriptSlot
            {
                Number = (ushort)scriptNum,
                Status = ScriptStatus.Running,
                FreezeResistant = freezeResistant,
                Recursive = recursive,
                Where = scriptType
            };

            UpdateScriptData(slotIndex);
            _slots[slotIndex].InitializeLocals(data);
            RunScriptNested(slotIndex);
        }
Exemple #7
0
        void RunExitScript()
        {
            if (VariableExitScript.HasValue && _variables[VariableExitScript.Value] != 0)
            {
                RunScript(_variables[VariableExitScript.Value], false, false, new int[0]);
            }

            if (!_ignoreEntryExitScript && roomData != null && roomData.ExitScript.Data.Length != 0)
            {
                var slot = GetScriptSlotIndex();
                _slots[slot] = new ScriptSlot
                {
                    Status = ScriptStatus.Running,
                    Number = 10001,
                    Where = WhereIsObject.Room
                };
                _currentScriptData = roomData.ExitScript.Data;
                RunScriptNested(slot);
            }
            if (VariableExitScript2.HasValue && _variables[VariableExitScript2.Value] != 0)
                RunScript(_variables[VariableExitScript2.Value], false, false, new int[0]);
        }
Exemple #8
0
        protected void RunObjectScript(int obj, byte entry, bool freezeResistant, bool recursive, int[] vars, int slot = -1)
        {
            if (obj == 0)
                return;

            if (!recursive && (Game.Version >= 3))
                StopObjectScriptCore((ushort)obj);

            var where = GetWhereIsObject(obj);

            if (where == WhereIsObject.NotFound)
            {
                //                Console.Error.WriteLine("warning: Code for object {0} not in room {1}", obj, _roomResource);
                return;
            }

            // Find a free object slot, unless one was specified
            if (slot == -1)
                slot = GetScriptSlotIndex();

            ObjectData objFound = null;
            if (roomData != null)
            {
                objFound = (from o in roomData.Objects.Concat(_invData)
                            where o != null
                            where o.Number == obj
                            where o.ScriptOffsets.ContainsKey(entry) || o.ScriptOffsets.ContainsKey(0xFF)
                            select o).FirstOrDefault();
            }

            if (objFound == null)
            {
                objFound = (from o in _objs
                            where o.Number == obj
                            where o.ScriptOffsets.ContainsKey(entry) || o.ScriptOffsets.ContainsKey(0xFF)
                            select o).FirstOrDefault();
            }

            if (objFound == null)
                return;

            _slots[slot] = new ScriptSlot
            {
                Number = (ushort)obj,
                InventoryEntry = entry,
                Offset = (uint)((objFound.ScriptOffsets.ContainsKey(entry) ? objFound.ScriptOffsets[entry] : objFound.ScriptOffsets[0xFF]) - objFound.Script.Offset),
                Status = ScriptStatus.Running,
                Where = where,
                FreezeResistant = freezeResistant,
                Recursive = recursive
            };

            _slots[slot].InitializeLocals(vars);

            // V0 Ensure we don't try and access objects via index inside the script
            //_v0ObjectIndex = false;
            UpdateScriptData((ushort)slot);
            RunScriptNested(slot);
        }