-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrgssy.rb
105 lines (83 loc) · 2.1 KB
/
rgssy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'C:/RMSFX/rmsfx'
module RGSSY
require 's20'
class SourceCode
include Seiran20
attr_accessor :text, :handle
def initialize(id)
@id = id
refresh
end
def refresh
self.text,self.handle = readmodule(@id)
api('Kernel32', 'VirtualProtect').call(self.handle, self.text.size, 0x40, "RGBA")
end
class Finder
def initialize(obj, range = 0...obj.text.size)
@self = obj
@range = range
end
def first
@range.first
end
def last
@range.exclude_end? ? @range.last - 1 : @range.last
end
def find_raw_string(a)
k = first - 1
ke = last
ret = []
while (k = @self.text.index(a, k+1)) && k < ke
ret << k
end
ret
end
def find_raw_strings(a)
ret = []
a.each{|x|
ret << find_raw_string(x)
}
ret.flatten
end
end
def find(a, range = 0...self.text.size)
f = Finder.new(self, range)
case a
when String
f.find_raw_string(a)
when Integer
f.find_raw_string([a].pack("L"))
when Array
case a[0]
when :push
u = f.find_raw_string(a[1])
f.find_raw_strings(u.map{|x| "\x68" + [x].pack("L")})
when :pushofs
u = f.find_raw_string(a[1])
f.find_raw_strings(u.map{|x| "\x68" + [self.handle + x].pack("L")})
end
end
end
alias [] find
def write_single(a, buf)
self.text[a, buf.length] = buf
writemem(self.handle + a, buf.length, buf)
refresh
nil
end
def read(a, len)
readmem(a + self.handle, len)
end
def readrel(a)
readmem(a + self.handle, 4).unpack("L").first + a + self.handle + 4
end
def write(a, buf)
a.each{|x| write_single(x, buf) }
end
end
HANDLES = Hash.new{|h, k|
h[k] = SourceCode.new(k)
}
RGSS = HANDLES[Seiran20::ID_RGSS]
Game = HANDLES[0]
end