Save-Point
UserPath for Linux OS - 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)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: UserPath for Linux OS (/thread-7581.html)



UserPath for Linux OS - kyonides - 11-16-2019

UserPath for Linux OS

UPFLOS Version 0.3.1

Add-On by Kyonides Arkanthes

Based on DerVVulfman's Commercial System Script Pack


Introduction

This scriptlet allows you to ignore a few errors that might show up if you try to run a gamethat includes DerVVulfman's Commercial System script pack on any Linux distro. Most of them are caused by any call to the Win32API that does not exist in other OS's like Linux. Besides they use different symbols as separators for path names. Now that should not be a problem anymore!

First Step

Ignore this step if using Commercial System version 1.2 or later.

Copy and paste this snippet in a section before the Commercial System scripts. This will let the system ignore all calls to the non existing Win32API on Linux distros.

Code:
# * Void Win32API

# Use this scriptlet if you want to let Linux users run your games.
# It will ignore all script calls meant to be executed on any Windows OS.

class Win32API
 def initialize(*args) end
 def call(*args) end
end

Second Step

Mandatory Step!

Now just follow the instructions included in the scriptlet to let it run on your favorite Linux OS.

NOTE If you're using HiddenChest, you can also set the starting values for fullscreen and F12 options.

XP Script

Code:
# * UserPath For Linux OS ** UPFLOS **
#   Scripter : Kyonides Arkanthes
#   v. 0.3.1 - 2019-11-17

# On a Linux distro it is a common thing to find a game's save files in the
# $HOME directory aka /home/username plus a custom directory where the game
# developer usually hide it. This preserves encapsulation and prevents you from
# invoking the sudo command and entering the corresponding password just to
# create or save any given data.

# Paste this scriptlet in any section below DerVVulfman's UserPath script and
# above the Main script.

# Input Fix for both MKXP and HiddenChest - disables Wulfo's code blocking it.

module ThisOS
  IS_LINUX = OS_Detect.version == 3
end

if $HIDDENCHEST
  Graphics.block_fullscreen = false # Blocks Alt+Enter?
  Graphics.block_f12 = true # Blocks F12 aka Game Reset?
  Graphics.block_f1 = true # Blocks F1 aka Input Menu?
end

module UserPath
  SEPARATOR = ThisOS::IS_LINUX ? '/' : ' \\' # Do Not Touch This!
  HIDE_DIR = true # Hide Save Games Directory?
  def self.save_filename(save_index)
    return "Save#{save_index + 1}.rxdata" if @path == nil
    @path + SEPARATOR + "Save#{save_index + 1}.rxdata"
  end

  def self.join_file(fn) @path + SEPARATOR + fn end

  def self.on_linux
    @path = ENV['HOME'] + '/'
    @path += '.' if HIDE_DIR # If hiding directory add a dot
    @path += ProSettings::GAME_FOLDER_NAME
    Dir.mkdir(@path) unless Dir.exists?(@path)
    p @path if ProSettings::DEBUG_FOLDER_NAME
  end
  on_linux if ThisOS::IS_LINUX
end

module MessageIntercept
  Flag_Deactivate = [1] if ThisOS::IS_LINUX
end

# Redefining Path for Saved Files
class Scene_File
  def make_filename(file_index) UserPath.save_filename(file_index + 1) end
end

class Scene_Map
  def update_title_window
    # Continue enabled determinant
    # Check if at least one save file exists
    # If enabled, make @continue_enabled true; if disabled, make it false
    @continue_enabled = false
    for i in 0..3
      @continue_enabled = FileTest.exist?(UserPath.save_filename(i+1))
      break if @continue_enabled
    end
    # Make command window
    count = ProSettings::OPTIONS.size
    window_array = []
    for i in 0...count
      window_array.push(ProSettings::OPTIONS[i][0])
    end
    @command_window = Window_Command.new(192, window_array)
    # Choose between Image or Text options
    show_img = ProSettings::IMAGE_ENABLED
    show_img ? update_title_window_image : update_title_window_text
    # Make title options window active
    @command_window.z       = 1000
    @command_window.active  = true
    # Hide Command Window if Chose to Display Images Instead
    @command_window.visible = !show_img
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      ProSettings::NOSAVE_DISABLE.each{|i| @command_window.disable_item(i) }
    end
  end
end

# Modifying DerVVulfman's Scene
class Scene_VVulfSplash
  def main
    load_config
    # IF F12 not been pressed, check config
    unless $f12_jump
      # Added for config start
      if $HIDDENCHEST or $MKXP
        Graphics.fullscreen = $data_config.fullscreen
      else
        button_combo = "System/F1AltEnterF12"
        if $data_config.fullscreen
          kb = ProSettings::DISABLE_F1
          kb = 1 if $DEBUG != true
          Win32API.new(button_combo, "hook", "III", "").call(kb,1,0)
          $showm = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
          $showm.call(18,0,0,0)
          $showm.call(13,0,0,0)
          $showm.call(13,0,2,0)
          $showm.call(18,0,2,0)
          Graphics.update
          kb = ProSettings::DISABLE_F1
          kb = 1 if $DEBUG != true
          Win32API.new(button_combo, "hook", "III", "").call(kb,1,1)
        else
          kb = ProSettings::DISABLE_F1
          kb = 1 if $DEBUG != true
          Win32API.new(button_combo, "hook", "III", "").call(kb,1,1)
        end
      end
    end
    if $DEBUG && ProSettings::PLAYTEST == false    # If Debug and Playtest off
      $scene = Scene_Title.new                     # Go to Title Screen
    end
    Audio.me_stop                                  # Stop playing ME
    Audio.bgs_stop                                 # Stop playing BGS
    main_variables                                 # Instance Variables
    if $data_config.fullscreen                     # If Fullscreen, add delay
      # Delay for fullscreen trans. Update game screen
      80.times{ Graphics.update }
    end
    Graphics.transition                            # Execute transition
    loop do                                        # Main loop
      Graphics.update                              # Update game screen
      Input.update                                 # Update input information
      update                                       # Frame update
      break if $scene != self                      # Abort loop if changed
    end
    Graphics.freeze                                # Prepare for transition
    @splash.dispose                                # Dispose of Sprites
  end

  def load_config
    # Establish default config values
    $data_config.bgm_volume = ProSettings::MUSIC
    $data_config.se_volume  = ProSettings::SOUND
    $data_config.fullscreen = ProSettings::FULLSCREEN
    # Create config filename for test
    path = ProSettings::SCS_FILE
    path = UserPath.join_file(path) if UserPath.folder
    # Load Config if config file exists # MKXP and HiddenChest Modification
    if FileTest.exist?(path)
      $data_config = File.open(path, "rb"){|f| Marshal.load(f) }
    else
      # Write config data
      File.open(path, "wb"){|f| Marshal.dump($data_config, f) }
    end
  end
end

module SCS_Options
  def command_toggle_fullscreen
    # Disable Fullscreen feature or call HiddenChest's method
    Graphics.fullscreen = !Graphics.fullscreen if $HIDDENCHEST
    return jump2index2 if $HIDDENCHEST or $MKXP or ThisOS::IS_LINUX
    kb = ProSettings::DISABLE_F1
    kb = 1 if $DEBUG != true
    Win32API.new("System/F1AltEnterF12", "hook", "III", "").call(kb,1,0)
    $showm = Win32API.new 'user32', 'keybd_event', %w(l l l l), ''
    $showm.call(18,0,0,0)
    $showm.call(13,0,0,0)
    $showm.call(13,0,2,0)
    $showm.call(18,0,2,0)
    Graphics.update
    kb = ProSettings::DISABLE_F1
    kb = 1 if $DEBUG != true
    Win32API.new("System/F1AltEnterF12", "hook", "III", "").call(kb,1,1)
    # Set the fullscreen flag in the config data
    jump2index2
  end

  def jump2index2
    $data_config.fullscreen = !$data_config.fullscreen
    call_options_window
    @options_window.index = 2
  end
end

Terms & Conditions

They are the same as in the Commercial System script pack.


RE: UserPath for Linux OS - kyonides - 11-16-2019

A Minor But Still Important Update

After playtesting Wulfo's demo I noticed that both mkxp and HiddenChest were unable to go past the first message he set in the first map. The fix he included to prevent some button from changing stuff disabled all Input while on a map. To fix it it was necessary to change the value of one of his constants, meaning Input will always be activated. This improvement also includes an easy way to set other values like the fullscreen and the F12 blocks a la HiddenChest. They will not make mkxp to crash, I have confirmed that already!


RE: UserPath for Linux OS - kyonides - 11-17-2019

Minor Update

After reviewing Wulfo's update of his Commercial Package script pack, I noticed that it doesn't handle anything concerning Linux so I determined that all Linux users still need my script after all. Laughing I've also made minor changes to my code to remove redundant code or fix some bug that let a window cursor show up in a ghostly fashion. Confused