Save-Point
F12 Reset Fix - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: F12 Reset Fix (/thread-4512.html)



F12 Reset Fix - itsacezon - 01-27-2013

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.

Script
Code:
#==============================================================
#   ** F12 Reset Fix
#   Author: Acezon
#   Date: 12 Feb 2013
#--------------------------------------------------------------
#   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
#--------------------------------------------------------------
#   Credits are optional.
#     Although doing so will make me happy.
#   Thanks to Tsukihime and Cidiomar for the console scriptlet
#==============================================================

module Config
# START EDITING HERE
  Console_on = true       # Sets the console
# END EDITING HERE
end

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
  def self.first_scene_class
    if Config::Console_on
      # 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
  end
end

Credits and Thanks
- Read the script header.


RE: F12 Reset Fix - DarkSpartan - 01-27-2013

Where does this go now?


RE: F12 Reset Fix - yamina-chan - 01-27-2013

Hag on, so the Ace has actually the same problem (as in a "F12 error that is likely to happen") as the XP? Really? XD'
This is a usefull script in that case, I suppose =) Beeing able to edit while testing is always a huge plus as well =D


RE: F12 Reset Fix - DerVVulfman - 01-28-2013

Good ol' Zeriab made one of the best for RMXP and made one for VX. He first thought that the VX one would work for VXAce once it was found to have an F12 bug of it's own, but found it was caused by a totally different bit of code. Thankies for submitting a workaround. Happy


RE: F12 Reset Fix - itsacezon - 02-12-2013

UPDATED to version 2. Read the first post for changes.