F12 Reset Fix

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A

F12 Reset Fix


 
Introduction
F12 reset can sometimes be a pain in the arse. This script fixes that by spawning a new Game.exe. It can also be used if you want to use the editor whilst play-testing it. You can also configure to show the console on test play.


Features
- Saves an RM user from death by F12 reset.

Screenshots
Not needed.

Script

Code:
#==============================================================================
#   ** F12 Reset Fix
#   Author: Acezon
#   Date: 2 June 2013
#------------------------------------------------------------------------------
#   Version 2.1
#   - Fixed issue where game window is not in focus
#     when Console_on is set to false
#   - Now compatible with Tsuki's Test Edit script
#   Version 2.0
#   - Console option added
#   - Automatically focuses window after pressing F12
#   Version 1.1
#   - Respawning the exe was better
#   Version 1.0
#   - Initial Release
#------------------------------------------------------------------------------
#   Just credit me. Free to use for commercial/non-commercial games.
#   Thanks to Tsukihime and Cidiomar for the console scriptlet
#==============================================================================

$imported = {} if $imported.nil?
$imported["Acezon-F12ResetFix"] = true

#==============================================================================
# ** START Configuration
#==============================================================================
module Config
  Console_on = false       # duh
end
#==============================================================================
# ** END Configuration
#==============================================================================

alias f12_reset_fix rgss_main
def rgss_main(*args, &block)
  f12_reset_fix(*args) do
    if $run_once_f12
      pid = spawn ($TEST ? 'Game.exe test' : 'Game')
      # Tell OS to ignore exit status
      Process.detach(pid)
      sleep(0.01)
      exit
    end
    $run_once_f12 = true
    # Run default rgss_main
    block.call
  end
end

module SceneManager
  class << self
    alias :acezon_f12_first :first_scene_class
  end

  def self.first_scene_class
    focus_game_window
    acezon_f12_first
  end

  def self.focus_game_window
    # Just to prevent re-spawning the console since
    # Tsuki uses this same part in his Test Edit script
    if !$imported["TH_TestEdit"]
      # Get game window text
      console_w = Win32API.new('user32','GetForegroundWindow', 'V', 'L').call
      buf_len = Win32API.new('user32','GetWindowTextLength', 'L', 'I').call(console_w)
      str = ' ' * (buf_len + 1)
      Win32API.new('user32', 'GetWindowText', 'LPI', 'I').call(console_w , str, str.length)

      if Config::Console_on
        # Initiate console
        Win32API.new('kernel32.dll', 'AllocConsole', '', '').call
        Win32API.new('kernel32.dll', 'SetConsoleTitle', 'P', '').call('RGSS3 Console')
        $stdout.reopen('CONOUT$')
      end

      # Sometimes pressing F12 will put the editor in focus first,
      # so we have to remove the program's name
      game_title = str.strip
      game_title.sub! ' - RPG Maker VX Ace', ''

      # Set game window to be foreground
      hwnd = Win32API.new('user32.dll', 'FindWindow', 'PP','N').call(0, game_title)
      Win32API.new('user32.dll', 'SetForegroundWindow', 'P', '').call(hwnd)
    end
  end
end



Log


Version 2.1


- Fixed issue where game window is not in focus
when Console_on is set to false
- Now compatible with Tsuki's Test Edit script
Version 2.0
- Console option added
- Automatically focuses window after pressing F12
Version 1.1
- Respawning the exe was better
Version 1.0
- Initial Release


Credit and Thanks


- Read the script header
 
Last edited by a moderator:

ShinGamix

DS Style 4Ever!
Veteran
Joined
Mar 18, 2012
Messages
3,905
Reaction score
451
First Language
April Fools
Primarily Uses
N/A
i needed this badly!
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
UPDATE:

It appears that it doesn't work on some events, so I decided to execute a new Game.exe and removed the former.
 

Rafael_Sol_Maker

Almighty God Jabu
Veteran
Joined
May 8, 2012
Messages
129
Reaction score
56
First Language
Portuguese
Primarily Uses
RMMV
It might be useful to correct some bugs related to F12 that are irritating me at this moment. Thanks!

(These problems are related to the RGSS3 "reinitializing" the game window without reloading the scripts, I'm sure).
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
EDIT: I just changed the thread's title since the script can be a general-purpose F12 reset fix.
 

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,311
Reaction score
485
First Language
French
Thank you, it helped me a lot! :D
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Really nice. Would it perhaps be possible to also recreate  the console window? Right now you lose the console after pressing [F12].
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
@Napoleon:

I think you can add this below the script. This is from Tsukihime's Test Play Script. Just set the Console_on to false if you want to export your project.

Code:
module Config  Console_on = trueendmodule SceneManager  def self.first_scene_class    if Config::Console_on      Win32API.new('kernel32.dll', 'AllocConsole', '', '').call      Win32API.new('kernel32.dll', 'SetConsoleTitle', 'P', '').call('RGSS3 Console')      $stdout.reopen('CONOUT$')    end    $BTEST ? Scene_Battle : Scene_Title  endend
 
Last edited by a moderator:

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Great that works. I use $TEST instead of Console_on but that's more or less the same.

But the console does steal the focus from the main window. Can a winapi or something set the focus back to the game window?
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
I don't think so. The Game.exe must execute first before initializing the console, as indicated in the script. I think the reason why it's in the back is the editor launches it first before the Game.exe 
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
But we have the process id (can be used to retrieve the hwnd (window handle)) and I saw that you also knew how to use the win32api. This api has the setfocus() function http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx so it should be possible in theory I think. But I'm new to Ruby so I don't yet know how to call these things.

I couldn't find a full working solution via Google to set the focus for a window through Ruby.
 
Last edited by a moderator:

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,311
Reaction score
485
First Language
French
Is it normal that the screen is reduced ?

I mean like if I : ALT+TAB.
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
@Napoleon - Here's your fix:
 

module SceneManager def self.first_scene_class if $TEST # Get game window text console_w = Win32API.new('user32','GetForegroundWindow', 'V', 'L').call buf_len = Win32API.new('user32','GetWindowTextLength', 'L', 'I').call(console_w) str = ' ' * (buf_len + 1) Win32API.new('user32', 'GetWindowText', 'LPI', 'I').call(console_w , str, str.length) # Initiate console Win32API.new('kernel32.dll', 'AllocConsole', '', '').call Win32API.new('kernel32.dll', 'SetConsoleTitle', 'P', '').call('RGSS3 Console') $stdout.reopen('CONOUT$') # Sometimes pressing F12 will put the editor in focus first, # so we have to remove the program's name game_title = str.strip game_title.sub! ' - RPG Maker VX Ace', '' # Set game window to be foreground hwnd = Win32API.new('user32.dll', 'FindWindow', 'PP','N').call(0, game_title) Win32API.new('user32.dll', 'SetForegroundWindow', 'P', '').call(hwnd) end $BTEST ? Scene_Battle : Scene_Title endend@Chaos17 - It doesn't happen to me. Maybe you have a script that changes the resolution.
 
Last edited by a moderator:

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
UPDATED to version 2.0. Read the first post for changes.
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Can we use these in commercial projects?
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
Sure. But some credit would be great. :D
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
UPDATE

 Version 2.1

 - Fixed issue where game window is not in focus

   when Console_on is set to false

 - Now compatible with Tsuki's Test Edit script
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Your latest version crashes right away for me. Tries to call new on nil class line 22 in SceneManager.run
 

Acezon

Om Nom Nom
Veteran
Joined
Apr 22, 2012
Messages
131
Reaction score
25
First Language
English
Primarily Uses
N/A
I misplaced a line in the script; my bad. It's fixed now, thank you for pointing that out.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,309
Reaction score
531
First Language
indonesian
i manage to fix the return to title command (it have the same bugs as f12 reset fix on some scripts).

by installing this script then changing this line in the SceneEnd:

SceneManager.goto(SceneTitle)to

      pid = spawn ($TEST ? 'Game.exe test' : 'Game')      # Tell OS to ignore exit status      Process.detach(pid)      sleep(0.01)      exit      SceneManager.run
but i have a problem. i have a script that can launch Scene_Load in game. but when loading the script break some other script (it's new jet mouse system.. because it's old exe. same problem with f12 and return to title).

is there a way to make child class of Scene_Load that when loading... close the game exe. made new game.exe. then loading the game?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:

Forum statistics

Threads
105,854
Messages
1,017,004
Members
137,562
Latest member
tamedeathman
Top