ezmash

Override Save Location (VX Ace)

Nov 17th, 2013
706
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #============================================================================
  2. # Override Save Location
  3. # v1.0 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This script allows your game to put save files into the player's
  6. # AppData folder, in a subfolder with the same name as the game.
  7. #
  8. # So, if your game is called Dragon Conquerer, save files will go into
  9. # User/AppData/Roaming/Dragon Conquerer
  10. #
  11. # This means several people can use the same PC under their own profiles,
  12. # and have their own save files that can't be accidentally overwritten by
  13. # others; players can uninstall, reinstall and overwrite your game without
  14. # losing their save files; gets around file access issues if the game has
  15. # been installed into a folder with additional Windows security.
  16. #----------------------------------------------------------------------------
  17. # To Install:
  18. # Copy and paste into a new script slot in Materials.  This script aliases
  19. # existing methods, so can go below all other custom scripts.
  20. #----------------------------------------------------------------------------
  21. # To Use:
  22. # No steps necessary - it just works.
  23. #----------------------------------------------------------------------------
  24. # Terms:
  25. # Use in free or commercial games
  26. # Credit Shaz
  27. #============================================================================
  28.  
  29. module DataManager
  30.   class << self
  31.     alias shaz_custom_save_datamanager_init init
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # * Initialize Module
  35.   #--------------------------------------------------------------------------
  36.   def self.init
  37.     shaz_custom_save_datamanager_init
  38.     create_app_paths
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # * Create Custom Save Path
  42.   #--------------------------------------------------------------------------
  43.   def self.create_app_paths
  44.     title = "\0" * 256
  45.     readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  46.     readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
  47.     title.delete!("\0")
  48.     @savePath = ENV['APPDATA'] + "\\" + title
  49.     Dir.mkdir(@savePath) if !File.exists?(@savePath)
  50.     @savePath.gsub!(/\\/, '/')
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # * Determine Existence of Save File
  54.   #--------------------------------------------------------------------------
  55.   def self.save_file_exists?
  56.     !Dir.glob(@savePath + '/Save*.rvdata2').empty?
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # * Create Filename
  60.   #     index : File Index
  61.   #--------------------------------------------------------------------------
  62.   def self.make_filename(index)
  63.     sprintf(@savePath + "/Save%02d.rvdata2", index + 1)
  64.   end
  65. end
RAW Paste Data