class Scene_Bridge EnumClipboardFormats = Win32API.new("user32", "EnumClipboardFormats", "i", "i") OpenClipboard = Win32API.new("user32", "OpenClipboard", "i", "i") CloseClipboard = Win32API.new("user32", "CloseClipboard", "", "") GetClipboardData = Win32API.new("user32", "GetClipboardData", "i", "i") SetClipboardData = Win32API.new("user32", "SetClipboardData", "ip", "i") EmptyClipboard = Win32API.new("user32", "EmptyClipboard", "", "i") GlobalLock = Win32API.new("kernel32", "GlobalLock", "i", "i") GlobalLockP = Win32API.new("kernel32", "GlobalLock", "i", "p") GlobalUnlock = Win32API.new("kernel32", "GlobalUnlock", "i", "") GlobalAlloc = Win32API.new("kernel32", "GlobalAlloc", "ii", "i") GlobalFree = Win32API.new("kernel32", "GlobalFree", "i", "i") MoveMemoryPI = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i") MoveMemoryIP = Win32API.new("kernel32", "RtlMoveMemory", "ipi", "i") WideCharToMultiByte = Win32API.new("kernel32", "WideCharToMultiByte", "iiiipiii", "i") MultiByteToWideChar = Win32API.new("kernel32", "MultiByteToWideChar", "iipipiii", "i") CODE_TEXT_TABLE = { 0 => "#", 101 => "文章の表示", 401 => "文章の表示続き", 102 => "選択肢の表示", 402 => "[**] の場合", 403 => "キャンセルの場合", 103 => "数値入力の処理", 104 => "文章オプション変更", 105 => "ボタン入力の処理", 106 => "ウェイト", 108 => "注釈", 408 => "注釈続き", 111 => "条件分岐", 411 => "それ以外の場合", 412 => "分岐終了", 112 => "ループ", 413 => "以上繰り返し", 113 => "ループの中断", 115 => "イベント処理の中断", 116 => "イベントの一時消去", 117 => "コモンイベント", 118 => "ラベル", 119 => "ラベルジャンプ", 121 => "スイッチの操作", 122 => "変数の操作", 123 => "セルフスイッチの操作", 124 => "タイマーの操作", 125 => "ゴールドの増減", 126 => "アイテムの増減", 127 => "武器の増減", 128 => "防具の増減", 129 => "アクターの入れ替え", 131 => "ウィンドウスキンの変更", 132 => "バトル BGM の変更", 133 => "バトル終了 ME の変更", 134 => "セーブ禁止の変更", 135 => "メニュー禁止の変更", 136 => "エンカウント禁止の変更", 201 => "場所移動", 202 => "イベントの位置設定", 203 => "マップのスクロール", 204 => "マップの設定変更", 205 => "フォグの色調変更", 206 => "フォグの不透明度変更", 207 => "アニメーションの表示", 208 => "透明状態の変更", 209 => "移動ルートの設定", 509 => "移動ルートの設定詳細", 210 => "移動完了までウェイト", 221 => "トランジション準備", 222 => "トランジション実行", 223 => "画面の色調変更", 224 => "画面のフラッシュ", 225 => "画面のシェイク", 231 => "ピクチャの表示", 232 => "ピクチャの移動", 233 => "ピクチャの回転", 234 => "ピクチャの色調変更", 235 => "ピクチャの消去", 236 => "天候の設定", 241 => "BGM の演奏", 242 => "BGM のフェードアウト", 245 => "BGS の演奏", 246 => "BGS のフェードアウト", 247 => "BGM / BGS の記憶", 248 => "BGM / BGS の復帰", 249 => "ME の演奏", 250 => "SE の演奏", 251 => "SE の停止", 301 => "バトルの処理", 601 => "勝った場合", 602 => "逃げた場合", 603 => "負けた場合", 302 => "ショップの処理", 303 => "名前入力の処理", 311 => "HP の増減", 312 => "SP の増減", 313 => "ステートの変更", 314 => "全回復", 315 => "EXP の増減", 316 => "レベルの増減", 317 => "パラメータの増減", 318 => "スキルの増減", 319 => "装備の変更", 320 => "アクターの名前変更", 321 => "アクターのクラス変更", 322 => "アクターのグラフィック変更", 331 => "エネミーの HP 増減", 332 => "エネミーの SP 増減", 333 => "エネミーのステート変更", 334 => "エネミーの出現", 335 => "エネミーの変身", 336 => "エネミーの全回復", 337 => "アニメーションの表示", 338 => "ダメージの処理", 339 => "アクションの強制", 340 => "バトルの中断", 351 => "メニュー画面の呼び出し", 352 => "セーブ画面の呼び出し", 353 => "ゲームオーバー", 354 => "タイトル画面に戻す", 355 => "スクリプト", 655 => "スクリプト続き", } TEXT_CODE_TABLE = {} CODE_TEXT_TABLE.each do |num, text| TEXT_CODE_TABLE[num.to_s] = num TEXT_CODE_TABLE[text] = num end def main $data_system ||= load_data("Data/System.rxdata") $game_system ||= Game_System.new Graphics.transition(0) @command_window = Window_Command.new(400, [ "イベントコマンド→日本語表記", "イベントコマンド→コマンドID表記", "テキスト表記→イベントコマンド", ]) @command_window.back_opacity = 160 @command_window.x = 320 - @command_window.width / 2 @command_window.y = 240 - @command_window.height / 2 loop do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update # 画面が切り替わったらループを中断 if $scene != self break end end Graphics.freeze @command_window.dispose end def update @command_window.update # C ボタンが押された場合 if Input.trigger?(Input::C) # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # イベントコマンド→日本語 event_command_to_text(false) when 1 # イベントコマンド→コマンドID event_command_to_text(true) when 2 # テキスト→イベントコマンド text_to_event_command end elsif Input.trigger?(Input::B) exit end end def event_command_to_text(to_code) text = "" err = "イベントコマンドではないものがコピーされているようです" read_clipboard(49000...50000, err) do |clip_format, ptr| @clip_format = clip_format buf = "x" * 4 MoveMemoryPI.call(buf, ptr, 4) length = buf.unpack("i")[0] buf = "x" * length MoveMemoryPI.call(buf, ptr + 4, length) command_list = Marshal.load(buf) #p command_list command_list.each do |command| if to_code line = command.code.to_s else unless CODE_TEXT_TABLE[command.code] raise "範囲外のイベントコード #{command.code} です" end line = CODE_TEXT_TABLE[command.code].dup end first = true line.concat "(" command.parameters.each do |parameter| if first first = false else line.concat ", " end case parameter when Integer line.concat parameter.to_s when String parameter.gsub!(/,/, ",!") parameter.gsub!(/,/, ",_") line.concat "\"#{parameter}\"" else parameter = [Marshal.dump(parameter)].pack("m") parameter.gsub!(/,/, ",") parameter.gsub!(/\n/, "") line.concat "dump==#{parameter}" end end line.concat ")\n" text.concat " " * command.indent text.concat line end end unless text.empty? write_clipboard(13, text) do |handle| SetClipboardData.call(13, handle) end print "テキストをクリップボードにコピーしました" end end def text_to_event_command err = "テキストではないものがコピーされているようです" list = [] read_clipboard(13, err) do |clip_format, text| text.each_line do |line| command = RPG::EventCommand.new line =~ /^( *)([^(]+)\((.*)\)\s*$/ command.indent = $1 ? $1.length / 2 : 0 tag = $2 parameter_str = $3 command.code = TEXT_CODE_TABLE[tag] || tag.to_i parameters = [] if parameter_str parameter_str.split(", ").each do |parameter| case parameter[0, 1] when "0".."9", "-" parameters.push parameter.to_i when '"' parameter.gsub!(/,_/, ",") parameter.gsub!(/,!/, ",") parameters.push parameter when "d" parameter.gsub!(/,/, ",") #p parameter parameters.push Marshal.load(parameter[6..-1].unpack("m")[0]) end end end command.parameters = parameters #p command list.push command end #p list end unless list.empty? dump_str = Marshal.dump(list) buf = [dump_str.length].pack("i") + dump_str write_clipboard(@clip_format || 49699, buf) do |handle| SetClipboardData.call(49699, buf) end print "イベントコマンドをクリップボードにコピーしました" end end def read_clipboard(valid_format, error_msg) OpenClipboard.call(0) begin clip_format = 0 until valid_format === clip_format clip_format = EnumClipboardFormats.call(clip_format) #p clip_format if clip_format == 0 print error_msg return end end handle = GetClipboardData.call(clip_format) if clip_format == 1 ptr = GlobalLockP.call(handle) else ptr = GlobalLock.call(handle) end begin if clip_format == 13 length = WideCharToMultiByte.call(65001, 0, ptr, -1, "", 0, 0, 0) #p :len, length new_ptr = "x" * (length - 1) WideCharToMultiByte.call(65001, 0, ptr, -1, new_ptr, length, 0, 0) ptr = new_ptr end yield clip_format, ptr ensure GlobalUnlock.call(handle) end ensure CloseClipboard.call end end def write_clipboard(format, buf) OpenClipboard.call(0) begin buf.concat "\0" if format == 1 if format == 13 length = MultiByteToWideChar.call(65001, 0, buf, -1, "", 0, 0, 0) new_buf = "xx" * length MultiByteToWideChar.call(65001, 0, buf, -1, new_buf, length, 0, 0) buf = new_buf #p new_buf[0..3], new_buf[-7..-1] end EmptyClipboard.call handle = GlobalAlloc.call(0x2000, buf.length) begin ptr = GlobalLock.call(handle) begin MoveMemoryIP.call(ptr, buf, buf.length) yield handle ensure GlobalUnlock.call(handle) end ensure GlobalFree.call(handle) end ensure CloseClipboard.call end end end Input.update if Input.press?(Input::F8) Graphics.freeze $scene = Scene_Bridge.new # $scene が有効な限り main メソッドを呼び出す while $scene != nil $scene.main end end