03-25-2019, 07:26 PM (This post was last modified: 09-02-2024, 10:35 PM by DerVVulfman.)
Prevent Deactivation by KK20 Version: 1.1
* and Minor F12 fix added by DerVVulfman
Introduction
When the game window is no longer the active window, it normally freezes the game from updating. This script will allow games to still run in the background.
This feature makes it so your game stays active and continues to run, even if you bring up another window or program.
Features
Keeps the game running, even if you're running another program
Has options to turn on/off the prevention feature
Versions for Ruby 1.8 and newer Ruby 2.0+
Script
The version for Ruby 1.9.2+
Code:
=begin
================================================================================
Prevent Deactivation
Author: KK20
Version: 1.1
--------------------------------------------------------------------------------
[ Description ]
When the game window is no longer the active window, it normally freezes the
game from updating. This script will allow games to still run in the background.
[ Instructions ]
You can enable / disable this feature in-game using the script call:
$game_system.keep_game_active = true / false
This is useful for custom menu options so that the player can choose their
preference of whether the game runs in the background or not.
Script should be placed as low as possible in your script list, but still
above Main.
It is highly advised to not modify this script unless you know what you are
doing.
================================================================================
=end
module Input
class << self
if @intercept_f12_stack.nil?
alias update_if_game_in_focus update
@intercept_f12_stack = true
end
end
# Only accept player input if the game window is in focus
def self.update
update_if_game_in_focus if MessageIntercept::Flag_Deactivate.getbyte(0) == 1
end
end
class Game_System
attr_reader :keep_game_active
alias init_for_no_deactivate initialize
def initialize
@keep_game_active = true
init_for_no_deactivate
end
# When loading a save, need to make DLL call to enable/disable keeping the
# game active
alias original_update_no_deactivate update
def self.modify_update(revert = false)
if revert
alias update original_update_no_deactivate
else
alias update no_deactivate_update
end
end
def no_deactivate_update
MessageIntercept::Toggle.call(@keep_game_active ? 1 : 0)
original_update_no_deactivate
Game_System.modify_update(true)
end
def keep_game_active=(bool)
@keep_game_active = bool
MessageIntercept::Toggle.call(@keep_game_active ? 1 : 0)
end
end
class Game_Temp
alias change_gamesystem_update_init initialize
def initialize
change_gamesystem_update_init
Game_System.modify_update
end
end
if MessageIntercept::Start.call('.\\Game.ini', MessageIntercept::Flag_Deactivate) == -1
raise 'ERROR: Prevent Deactivation failed to set new window procedure!'
end
--or--
The version for RPGMaker VXAce
Code:
=begin
================================================================================
Prevent Deactivation
Author: KK20
Version: 1.1
--------------------------------------------------------------------------------
[ Description ]
When the game window is no longer the active window, it normally freezes the
game from updating. This script will allow games to still run in the background.
[ Instructions ]
You can enable / disable this feature in-game using the script call:
$game_system.keep_game_active = true / false
This is useful for custom menu options so that the player can choose their
preference of whether the game runs in the background or not.
Script should be placed as low as possible in your script list, but still
above Main.
It is highly advised to not modify this script unless you know what you are
doing.
================================================================================
=end
module Input
class << self
if @intercept_f12_stack.nil?
alias update_if_game_in_focus update
@intercept_f12_stack = true
end
end
# Only accept player input if the game window is in focus
def self.update
update_if_game_in_focus if MessageIntercept::Flag_Deactivate.getbyte(0) == 1
end
end
class Game_System
attr_reader :keep_game_active
alias init_for_no_deactivate initialize
def initialize
@keep_game_active = true
init_for_no_deactivate
end
def keep_game_active=(bool)
@keep_game_active = bool
MessageIntercept::Toggle.call(@keep_game_active ? 1 : 0)
end
end
module DataManager
class << self
alias load_no_deactivate_settings extract_save_contents
alias init_no_deactivate_settings setup_new_game
end
def self.setup_new_game
$game_system.keep_game_active = true
init_no_deactivate_settings
end
def self.extract_save_contents(contents)
load_no_deactivate_settings(contents)
Scene_Base.modify_update
end
end
class Scene_Base
# When loading a save, need to make DLL call to enable/disable keeping the
# game active
alias original_update_no_deactivate update
def self.modify_update(revert = false)
if revert
alias update original_update_no_deactivate
else
alias update no_deactivate_update
end
end
def no_deactivate_update
MessageIntercept::Toggle.call($game_system.keep_game_active ? 1 : 0)
original_update_no_deactivate
Scene_Base.modify_update(true)
end
end
if MessageIntercept::Start.call('.\\Game.ini', MessageIntercept::Flag_Deactivate) == -1
raise 'ERROR: Prevent Deactivation failed to set new window procedure!'
end
Instructions
Mainly, place the .DLL attached in your project's root directory and paste the script just above main after all other custom scripts. Other instructions are in the script.
FAQ
This was searched for by DerVVulfman, the request at RPGMakerWeb.Com posted and found right (>HERE<)
Compatibility
Designed for the RPGMaker engines, with two versions based on which version of Ruby/RGSS your engine is using.
Credits and Thanks
This script was designed by KK20, and with thanks to Jaiden for the toggle on/off feature request.
Terms and Conditions
Due credit for both KK20 and Jaiden is required. Free for use in commercial projects.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)