注册会员 登录
Project1 返回首页

243387971的个人空间 https://rpg.blue/?84275 [收藏] [复制] [分享] [RSS]

日志

截图存档脚本

已有 389 次阅读2012-1-22 20:32 |个人分类:脚本区| 存档脚本

#==============================================================================
# 本脚本来自www.66RPG.com,转载和使用请保留此信息
#===============================================================================

BBS_66RPG_DIR = "Save/"

#==============================================================================
# 作者:未知
# 优化修改:243387971
# 版本:1.0
# 注释:研究Win32 API汇编一段时间后,又想碰一下RGSS脚本,这也算是本人的处女作
#       吧。以下#后面的注释均为243387971重新编写。
#==============================================================================

#·······································
#· 这个排版的内容比较繁复,注意看脚本里用【】框起来的内容,这些大致是可以动 ·
#·存档数量也可以改,不过不推荐改太多,因为你还得回Scene_Title也改一次……   ·
#·总之就是除了黑框注释过的东西能不动就别动……                              ·
#·······································

#===============================================================================
module Screen 
  #@screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), ''
 
  #调用名为screenshot的动态链接库中的Screenshot函数
 
  #@readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
 
  #为初始化文件中指定的条目取得字串
  #对Ini文件进行读操作
 
  #@findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
  #查找窗口并返回Long句柄
 
  #列出在VB中调用API的方式进行对比。
  #Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  #双P均为指针,指向参数地址。
 
module_function
  #def shot(file = "shot", typ = 1)
    # 设定支持图片类型...
    # 0为BMP位图
    # 1为JPEG压缩图片
    # 2为网络格式PNG图片
    #if typ == 0
      #typname = ".bmp"
    #elsif typ == 1
      #typname = ".jpg"
    #elsif typ == 2
      #typname = ".png"
    #end   
    #file_index = 0   
    #dir = "Save/"   
    # 创建文件名称....
    #file_name = dir + file + typname   
    #file_name=Save/+file转换为字符串+typename
      #$to_s([base])
      #将整数变为十进制字符串形式。
    # 调用Screenshot函数....
    #@screen.call(0,0,640,480,file_name,handel,typ)
   
    #解析:
    #0,0应该是图片坐标
    #640,480应该是图片的宽度和高度
    #file_name应该是图片路径
    #handel是图像句柄
    #typ是类型
   
    #用PE分析器得出该dll中应该只有一个函数
    #分析数据:
   
   
    #模块名称:PureBasic.dll
   #TimeDateStamp: 41AE4E96
   #版本: 0.00
   #Ordinal base: 00000001
   #函数个数: 00000001
   #名称个数: 00000001
    #Screenshot rva: 00001083 ord:   1
   
    #这应该是调用的Screenshot中的函数,作用应该是读取图片文件并且返回图像数据。
   
  #end
  # 这一对象的组合,其目的是获取游戏执行时的窗口句柄
  #def handel
    #game_name = "\0" * 256
    #@readini.call('Game','Title','',game_name,255,".\\Game.ini")
  #利用readini函数从Game.ini当中获取游戏的标题
    #game_name.delete!("\0")
    #return @findwindow.call('RGSS Player',game_name)
  #带入函数,findwindow返回句柄到Handel(句柄)并给予Screenshot函数调用
  #end
end

class Window_File < Window_Base #集成的是Window_Base类方法
  attr_accessor :index
  def initialize(index = 0)
    #window_file类进行初始化操作
   
    @backsp = Sprite.new
    @backsp.bitmap = Bitmap.new("Graphics/Pictures/ui_save.jpg")
    @backsp.z = 99
    #建立一个backsp实量为精灵对象
    #位图图像为Graphics/Pictures/ui_save.jpg(此处路径可自定义)
    #定义z轴次序
   
    super(160,50,460,460)
   
    #调用父类Window_Base的initialize同类方法,将160,50,460,460参数实际上是
    #赋值给父类的同名方法
   
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    #self设定自身对象即windows_file类的实例属性opacity=0
    #        contents=Bitmap.new(width - 32, height - 32)
   
    @index = index
    #·························
    #·这里我要说明一句,之所以用sprite是为了放缩图片·
    #·························
   
    @sprite = Sprite.new
    #新建一个Sprite对象
    @sprite.visible = false
    #设定精灵的可见性为false
   
    @sprite.z = 100
    #Z轴次序为100
    @sp_ch = []
    #定义一个空的sp_ch数组
    @sp_ch[0] = Sprite.new
    refresh
    #调用refresh函数
    #意思就是在创建实例时刷新一下,要不要无所谓
end
def refresh
    self.contents.clear
    #self设定自身对象即windows_file类的实例方法clear清除
    for i in @sp_ch
      i.visible = false
    end
    #for循环,由i开始到@sp_ch结束
    @sprite.visible = false
    if FileTest.exist?(BBS_66RPG_DIR+"Save#{@index}.rxdata")
      @sprite.visible = true
      #如果该文件存档存在=true就使@sprite的可见性为true
     
      if FileTest.exist?(BBS_66RPG_DIR+"Save#{@index}.jpg")
        @sprite.bitmap = Bitmap.new(BBS_66RPG_DIR+"Save#{@index}.jpg")
      #如果该存档文件的图片文件存在=true的话就创建图片了
      else
        self.contents.draw_text(32,64,400,32,"截图似乎有点问题……您搞什么了您?")
      end
      @sprite.x = 195 #【截图的X坐标,可以调】
      @sprite.y = 74  #【截图的Y坐标,可以调】
      @sprite.zoom_x = 0.6  #【截图的水平缩放比例,可以调】
      @sprite.zoom_y = 0.6  #【截图的垂直缩放比例,可以调】
      file = File.open(BBS_66RPG_DIR+"Save#{@index}.rxdata", "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
      for i in [email protected]
        @sp_ch[i] = Sprite.new
        @sp_ch[i].visible = true
        @sp_ch[i].bitmap = RPG::Cache.picture(@characters[i][3])
        @sp_ch[i].x = 180 + i*100      
        @sp_ch[i].y = 360 - @sp_ch[i].bitmap.height
        @sp_ch[i].z = 101
      end
      self.contents.font.color = Color.new(0,0,0)
      # 描绘游戏时间
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.font.color = normal_color
      self.contents.draw_text(12, 316, 360, 32, time_string, 0)
                            #【↑前两个数字是坐标可以调】
      @Rtun = Win32API.new 'A1','RturnC', %w(),'p'
      $CT = @Rtun.call()
      p($CT)
      # 描绘时间标记
      self.contents.font.color = normal_color
      time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
      self.contents.draw_text(12, 316, 400, 32, time_string, 2)
                           #【↑前两个数字是坐标可以调】
    else
      self.contents.draw_text(32,32,360,32,"这个存档是空的")
                              #【↑前两个数字是坐标可以调】
    end
  end
  def dispose
    super
    @sprite.dispose
    @backsp.dispose
    for i in @sp_ch
      i.dispose
    end
  end
end


class Scene_Save
  def main
    @command_window = Window_Command.new(160,["进度1","进度2","进度3","进度4",
    "进度5","进度6","进度7","进度8","进度9","进度10","进度11","进度12","进度13",
    "进度14","进度15","进度16","进度17","进度18","进度19","进度20"])
    @command_window.y = 50
    #【存档列表的Y坐标,可以调,所有的@command_window.y要保持一致。】
    @command_window.height = 384
    #【存档列表的高度,可以调,所有的@command_window.height要保持一致。】
    @command_window.opacity = 0
    @command_window.index = $game_temp.last_file_index
    @content_window = Window_File.new($game_temp.last_file_index)
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面被切换的话就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    @command_window.dispose
    @content_window.dispose
  end
  def update
    @command_window.update   
    if @command_window.index != @content_window.index
      @content_window.index = @command_window.index
      @content_window.refresh
    end   
    #——————下面这一部分是原装脚本——————#
    if Input.trigger?(Input::B) 
      $game_system.se_play($data_system.cancel_se)
      if $game_temp.save_calling
        $game_temp.save_calling = false
        $scene = Scene_Map.new
        return
      end
      $scene = Scene_Menu.new
    end   
    #———————————————————————#   
    if Input.trigger?(Input::C)
      # 演奏存档 SE
      $game_system.se_play($data_system.save_se)
      # 写入存档数据
      file = File.open(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata", "wb")
      write_save_data(file)
      if FileTest.exist?(BBS_66RPG_DIR+"shot.jpg")
        File.rename(BBS_66RPG_DIR+"shot.jpg", BBS_66RPG_DIR+"Save#{@command_window.index}.jpg")
      end
      file.close
      $game_temp.last_file_index = @command_window.index
      # 如果被事件调用
      if $game_temp.save_calling
        # 清除存档调用标志
        $game_temp.save_calling = false
        # 切换到地图画面
        $scene = Scene_Map.new
        return
      end
      # 切换到菜单画面
      $scene = Scene_Menu.new
    end
    #———————————————————————#
  end
  #--------------------------------------------------------------------------
  # ● 写入存档数据
  #     file : 写入用文件对像 (已经打开)
  #--------------------------------------------------------------------------
  def write_save_data(file)
    # 生成描绘存档文件用的角色图形
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue, actor.id, actor.battler_name, actor.battler_hue])
    end
    # 写入描绘存档文件用的角色数据
    Marshal.dump(characters, file)
    # 写入测量游戏时间用画面计数
    Marshal.dump(Graphics.frame_count, file)
    # 增加 1 次存档次数
    $game_system.save_count += 1
    # 保存魔法编号
    # (将编辑器保存的值以随机值替换)
    $game_system.magic_number = $data_system.magic_number
    # 写入各种游戏对像
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
  end
end


class Scene_Load
  def initialize
    # 再生成临时对像
    $game_temp = Game_Temp.new
    # 选择存档时间最新的文件
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..13
      filename = BBS_66RPG_DIR+"Save#{i}.rxdata"
      if FileTest.exist?(filename)
        file = File.open(filename, "r")
        if file.mtime > latest_time
          latest_time = file.mtime
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
  end 
  def main
    @command_window = Window_Command.new(160,["进度1","进度2","进度3","进度4",
    "进度5","进度6","进度7","进度8","进度9","进度10","进度11","进度12","进度13",
    "进度14","进度15","进度16","进度17","进度18","进度19","进度20"])
    @command_window.y = 50
    #【存档列表的Y坐标,可以调,所有的@command_window.y要保持一致。】
    @command_window.height = 384
    #【存档列表的高度,可以调,所有的@command_window.height要保持一致。】
    @command_window.opacity = 0
    @command_window.index = $game_temp.last_file_index
    @content_window = Window_File.new($game_temp.last_file_index)
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面被切换的话就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    @command_window.dispose
    @content_window.dispose
  end
  def update
    @command_window.update   
    if @command_window.index != @content_window.index
      @content_window.index = @command_window.index
      @content_window.refresh
    end   
    #——————下面这一部分是原装脚本——————#
    if Input.trigger?(Input::B) 
    # 演奏取消 SE
    $game_system.se_play($data_system.cancel_se)
    # 切换到标题画面
    $scene = Scene_Title.new
    end   
    #———————————————————————#   
    if Input.trigger?(Input::C)
      # 文件不存在的情况下
      unless FileTest.exist?(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata")
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 演奏读档 SE
      $game_system.se_play($data_system.load_se)
      # 写入存档数据
      file = File.open(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata", "rb")
      read_save_data(file)
      file.close
      # 还原 BGM、BGS
      $game_system.bgm_play($game_system.playing_bgm)
      $game_system.bgs_play($game_system.playing_bgs)
      # 刷新地图 (执行并行事件)
      $game_map.update
      # 切换到地图画面
      $scene = Scene_Map.new
    end
    #———————————————————————#
  end
  #--------------------------------------------------------------------------
  # ● 写入存档数据
  #     file : 写入用文件对像 (已经打开)
  #--------------------------------------------------------------------------
  def read_save_data(file)
    # 读取描绘存档文件用的角色数据
    characters = Marshal.load(file)
    # 读取测量游戏时间用画面计数
    Graphics.frame_count = Marshal.load(file)
    # 读取各种游戏对像
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    # 魔法编号与保存时有差异的情况下
    # (加入编辑器的编辑过的数据)
    if $game_system.magic_number != $data_system.magic_number
      # 重新装载地图
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # 刷新同伴成员
    $game_party.refresh
  end
end

class Scene_Load2
  def initialize
    # 再生成临时对像
    $game_temp = Game_Temp.new
    # 选择存档时间最新的文件
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..13
      filename = BBS_66RPG_DIR+"Save#{i}.rxdata"
      if FileTest.exist?(filename)
        file = File.open(filename, "r")
        if file.mtime > latest_time
          latest_time = file.mtime
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
  end 
  def main
    @command_window = Window_Command.new(160,["进度1","进度2","进度3","进度4",
    "进度5","进度6","进度7","进度8","进度9","进度10","进度11","进度12","进度13",
    "进度14","进度15","进度16","进度17","进度18","进度19","进度20"])
    @command_window.y = 50
    #【存档列表的Y坐标,可以调,所有的@command_window.y要保持一致。】
    @command_window.height = 384
    #【存档列表的高度,可以调,所有的@command_window.height要保持一致。】
    @command_window.opacity = 0
    @command_window.index = $game_temp.last_file_index
    @content_window = Window_File.new($game_temp.last_file_index)
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面被切换的话就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    @command_window.dispose
    @content_window.dispose
  end
  def update
    @command_window.update   
    if @command_window.index != @content_window.index
      @content_window.index = @command_window.index
      @content_window.refresh
    end   
    #——————下面这一部分是原装脚本——————#
    if Input.trigger?(Input::B) 
    # 演奏取消 SE
    $game_system.se_play($data_system.cancel_se)
    # 切换到标题画面
    $scene = Scene_Menu.new(1)
    end   
    #———————————————————————#   
    if Input.trigger?(Input::C)
      # 文件不存在的情况下
      unless FileTest.exist?(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata")
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 演奏读档 SE
      $game_system.se_play($data_system.load_se)
      # 写入存档数据
      file = File.open(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata", "rb")
      read_save_data(file)
      file.close
      # 还原 BGM、BGS
      $game_system.bgm_play($game_system.playing_bgm)
      $game_system.bgs_play($game_system.playing_bgs)
      # 刷新地图 (执行并行事件)
      $game_map.update
      # 切换到地图画面
      $scene = Scene_Map.new
    end
    #———————————————————————#
  end
  #--------------------------------------------------------------------------
  # ● 写入存档数据
  #     file : 写入用文件对像 (已经打开)
  #--------------------------------------------------------------------------
  def read_save_data(file)
    # 读取描绘存档文件用的角色数据
    characters = Marshal.load(file)
    # 读取测量游戏时间用画面计数
    Graphics.frame_count = Marshal.load(file)
    # 读取各种游戏对像
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    # 魔法编号与保存时有差异的情况下
    # (加入编辑器的编辑过的数据)
    if $game_system.magic_number != $data_system.magic_number
      # 重新装载地图
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # 刷新同伴成员
    $game_party.refresh
  end
end

 

class Interpreter
  #--------------------------------------------------------------------------
  # ● 调用存档画面
  #--------------------------------------------------------------------------
  def command_352
    # 设置战斗中断标志
    $game_temp.battle_abort = true
    # 设置调用存档标志
    $game_temp.save_calling = true
    # 推进索引
    @index += 1
    # 结束
    Screen::shot
    return false
  end
end


鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-2 15:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部