rebf-gaiden/Scripts/_.55.rb
2025-04-26 17:06:34 -05:00

242 lines
8.6 KiB
Ruby
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

=begin
トリス 名前入力ウィンドウ-改造 ver1
2015/12/30
元スクリプト作者oage(piroshi)
元スクリプトURL http://www.nicovideo.jp/watch/sm25849424
=end
module STR_INPUT
# このスクリプトの変更点
# ・「スタートマップ」なしで、F12リセット時にボックスを自動消去
# ・入力結果の終端の"\0"を消去
# ・入力終了キーの変更
# ・不正操作への対応
# ・入力結果の終端の"\0"を消去
# NO_NULL が 1 の時、"\0"を消す 結果 == "もっも"
# NO_NULL が 2 の時、"\0"を消さない(元スクリプトと同じ) 結果 == "もっも\0"
NO_NULL = 2
# ・入力終了キーの変更
# 入力を終了するキー 元スクリプトでは :F8
# CTRLキーは不正とみなされるので「:CTRL 以外の入力に不要なキー」を指定すること
# :A Shiftキー
# :R Qキー
END_KEY = :F8
# ・不正操作への対応
# TRAP_LIST 内に入っている場合のみ不正とみなす
# ウィンドウがアクティブの時に以下を検出した場合、不正
# ① :A フレーム更新までに0.1秒経過通常なら、約0.016秒で更新される)
# ・「ゲームウィンドウのタイトルバーで左クリックか右クリック」
# ・「メッセージボックスのタイトルバー(無名)で右クリック」
# している間もフレーム更新が止まって不正になるため、オフを推奨
# ② :C CTRLキーの入力
# ③ :R 右クリック
TRAP_LIST = [:C, :R, :D]
# 1なら「不正検出時にボックス入力終了」
# 2なら「不正検出時は何もせず、不正回数を変数に保存」
TRAP_MODE = 1
# TRAP_MODE が 2 の場合のみ
# 不正検出時に加算する変数ID
# クイズの開始前に、イベントコマンドで 0 を代入しておくこと
TRAP_VAR = 1
# TRAP_MODE が 2 の場合、不正検出時に入力結果として以下の値が返される
# ① :A
# ② :C
# ③ :R
# これらは「文字列 ":A"」ではなく「シンボル :A」である
# 入力結果がシンボルになるのは不正検出時のみ それ以外は文字列が返される
#
# 一致判定は
# $game_variables[1] == ":A" ではなく
# $game_variables[1] == :A
# また、「シンボルであるかどうか=不正が行われたかどうか」を判定したいなら
# $game_variables[1].is_a?(Symbol)
end
module Kernel
#
#ウィンドウネームを引数に持つ
#
def stinput(wn)
#ウィンドウのタイトルかエディットなどの入力文字の取得
text = Win32API.new('user32', 'GetWindowTextA',%w(i p i),'i')
#GetWindowTextで取得できる文字数の判定
gwtl = Win32API.new('user32', 'GetWindowTextLength','i','i')
#ウィンドウタイトルからウィンドウを検索してハンドルを返す
fw = Win32API.new('user32', 'FindWindow',%w(p p),'i')
#ウィンドウを作成する
cw= Win32API.new('user32', 'CreateWindowEx' , 'ippiiiiiiiii', 'i')
#作成したウィンドウを表示する
sw = Win32API.new('user32','ShowWindow','ii','i')
#指定したハンドルのウィンドウを消す
dw = Win32API.new('user32','DestroyWindow','i','i')
#iniからゲームタイトルを取得するのに使う
readini = Win32API.new('kernel32', 'GetPrivateProfileString', %w(p p p p l p), 'l')
#ゲームウィンドウの位置とサイズを調べるのに使う
gwr = Win32API.new('User32', 'GetWindowRect', %w(l p), 'i')
#入力ウィンドウをアクティブにする
setfw = Win32API.new('User32', 'SetForegroundWindow', 'l', 'i')
#キー判定
getk = Win32API.new('User32', 'GetKeyState', 'i', 'i') #toris
#win32apiのロード終わり
#引数の文字列を変換する
wn = wn.encode("Shift_JIS")
###
# ウィンドウハンドルを取得するためのAPIをロードする
# ゲーム名を取得する
game_name = "\0" * 256
readini.call("Game","Title","",game_name,255,".\\Game.ini")
#終端の位置を確認してそれより右をスライスする
leng = game_name.index("\0")
game_name = game_name.slice(0..leng)
# ウィンドウハンドルを取得
hwnd = fw.call("RGSS Player",game_name)
#p hwnd
###
#ウィンドウの座標を調べる
y = [0,0,0,0].pack('l4')
n = gwr.call(hwnd,y)
a1,a2,a3,a4=y.unpack('l4')
#
#a1・・・画面左上隅を(0,0)とした時のウインドウ上辺のy座標
#a2・・・//ウインドウ左辺のx座標
#a3・・・//ウインドウ下辺のy座標
#a4・・・//ウインドウ右辺のx座標
#入力ウィンドウの設定
xs = a1 + (a3 - a1 - 250) / 2
ys = a2 + (a4 - a2 - 100) / 2
aa = cw.call(0x00000088,'static',"", 0x00C00000,xs,ys, 250, 100,0,0, 0, 0)
a = cw.call(0x00000008,'EDIT', wn, 0x50800000,50, 20, 150, 25,aa, 1, 0, 0)
sw.call(aa, 5)
#F12リセットされたときにウィンドウが残ったままなので、
#その対策としてハンドルを外部のテキストファイルに残しておく
fn = "System/win.txt"
f1 = FileTest.exist?(fn)
f2 = FileTest.file?(fn)
if !(f1 == true && f2 == true) then
fw = open(fn,"w+")
fw.puts("0")
fw.close
end
fw = open(fn,"w+")
fw.puts("#{aa}")
fw.close
#F8キーが入力されるまで名前入力を終了させない
setfw.call(aa)
time_last = Time.now
ctrl_last = nil
rcli_last = nil
ins_last = nil
while true ##無限ループ始まり
time_new = Time.now
if STR_INPUT::TRAP_LIST.include?(:A) and time_new - time_last > 0.1
p ["不正検出:非アクティブ時間", time_new - time_last]
break buf = :A if STR_INPUT::TRAP_MODE == 1
$game_variables[STR_INPUT::TRAP_VAR] += 1 if STR_INPUT::TRAP_MODE == 2
end
time_last = time_new
ctrl_new = getk.call(0x11)[15]
if STR_INPUT::TRAP_LIST.include?(:C) and [ctrl_last, ctrl_new] == [0, 1]
p ["不正検出CTRLキー"]
break buf = :C if STR_INPUT::TRAP_MODE == 1
$game_variables[STR_INPUT::TRAP_VAR] += 1 if STR_INPUT::TRAP_MODE == 2
end
ctrl_last = ctrl_new
ins_new = getk.call(0x2D)[15]
if STR_INPUT::TRAP_LIST.include?(:D) and [ins_last, ins_new] == [0, 1]
p ["不正検出insキー"]
break buf = :D if STR_INPUT::TRAP_MODE == 1
$game_variables[STR_INPUT::TRAP_VAR] += 1 if STR_INPUT::TRAP_MODE == 2
end
ins_last = ins_new
time_last = time_new
rcli_new = getk.call(0x02)[15]
if STR_INPUT::TRAP_LIST.include?(:R) and [rcli_last, rcli_new] == [0, 1]
p ["不正検出:右クリック"]
break buf = :R if STR_INPUT::TRAP_MODE == 1
$game_variables[STR_INPUT::TRAP_VAR] += 1 if STR_INPUT::TRAP_MODE == 2
end
rcli_last = rcli_new
# キー判定の引数は下記URLより
# https://github.com/erinata/auto_click/blob/f893629ecc8105d50cff3a240bedabac9e1b2bb5/lib/auto_click/virtual_key.rb
if Input.trigger?(STR_INPUT::END_KEY) == true
#入力文字の処理
moji = gwtl.call(a)
buf = ("\0" * (moji + 1))
strl = text.call(a, buf, buf.size)
buf.encode!("UTF-8", "Shift_JIS")
if buf != "\0" then
buf.delete!("\u0000") if STR_INPUT::NO_NULL == 1
break
end
end
wait(1)
end ##無限ループ終わり
loop{
n = dw.call(aa)
if n != 0
break
end
}
#テキストを初期化
fw = open(fn,"w+")
fw.puts("0")
fw.close
p "inputbox end"
return buf
end
end
module SceneManager
#--------------------------------------------------------------------------
# ○ 実行
#--------------------------------------------------------------------------
@@executed = false
def self.run
if !@@executed then
@@executed = true
fn = "System/win.txt"
fw = open(fn,"w+")
fw.puts("0")
fw.close
else
p "二回目以降の起動"
delwin
end
DataManager.init
Audio.setup_midi if use_midi?
@scene = first_scene_class.new
@scene.main while @scene
end
end