npgrt 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ module NPGRT
2
+ module Find
3
+ extend self
4
+ private
5
+ def each_path
6
+ ENV['path'].split(";").each{|x|
7
+ yield x
8
+ }
9
+ end
10
+ public
11
+
12
+ def binary(name)
13
+ each_path do |path|
14
+ v = File.join(path, name)
15
+ return NPGRT.normalize_pathsep_os(v) if FileTest.file?(v)
16
+ end
17
+ Gem.find_files(name) do |v|
18
+ return NPGRT.normalize_pathsep_os(v) if FileTest.file?(v)
19
+ end
20
+
21
+ nil
22
+ end
23
+ def hostruby
24
+ binary("ruby.exe")
25
+ end
26
+
27
+
28
+ end
29
+
30
+
31
+ end
data/lib/npgrt/message.rb CHANGED
@@ -4,5 +4,4 @@ module NPGRT
4
4
  defined?(msgbox) ? msgbox(*a) : print(*a)
5
5
  end
6
6
  end
7
- extend Message
8
7
  end
@@ -1,7 +1,7 @@
1
1
  module NPGRT
2
2
  module Message
3
3
  def message(*a)
4
- defined?(:msgbox) ? msgbox(*a) : p(*a)
4
+ defined?(msgbox) ? msgbox(*a) : print(*a)
5
5
  end
6
6
  end
7
7
  extend Message
@@ -0,0 +1,6 @@
1
+ module NPGRT
2
+ module Query
3
+
4
+
5
+ end
6
+ end
@@ -0,0 +1,182 @@
1
+ module NPGRT
2
+ class Report
3
+
4
+
5
+ def initialize(io, &b)
6
+ @io = io
7
+ @binding = b.binding
8
+ end
9
+
10
+ private
11
+ def title(str)
12
+ "#{str} ----------\n"
13
+ end
14
+
15
+ def tail
16
+ "\n\n\n"
17
+ end
18
+
19
+ def form(io, title)
20
+ io << title(title)
21
+ yield io
22
+ io << tail
23
+ io
24
+ end
25
+ public
26
+ def inifile(io)
27
+ return unless FileTest.file?("Game.ini")
28
+ form io, "Game.ini" do |io|
29
+ io << File.read("Game.ini")
30
+ end
31
+ end
32
+
33
+ def scripts(io)
34
+ return unless defined?($RGSS_SCRIPTS)
35
+ form io, "Scripts" do |io|
36
+ io << $RGSS_SCRIPTS.map{|x| " [%s] " % x[1]}.join("\n")
37
+ end
38
+ end
39
+
40
+ def basic(io)
41
+ form io, "Basic Information" do |io|
42
+ io << "path:" << Dir.getwd << "\n"
43
+ io << "Ruby Version:" << RUBY_VERSION << "\n"
44
+ io << "NPGRT Version:" << NPGRT::VERSION << "\n"
45
+ io << "Platform:" << NPGRT::PlatformWidth << "\n"
46
+ begin
47
+ str = "" << "FPS:" << Graphics.frame_rate.to_s << "\n"
48
+ str << "Frame Count:" << Graphics.frame_count.to_s << "\n"
49
+ io << str
50
+ rescue
51
+ end
52
+ io << "Command Line:" << NPGRT.wstrread(NPGRT.api('kernel32', 'GetCommandLineW').call) << "\n"
53
+
54
+ end
55
+ end
56
+
57
+ def position(io)
58
+ form io, "Position" do |io|
59
+ io << "__FILE__:" << eval('__FILE__', @binding) << "\n"
60
+ if eval('__FILE__', @binding) =~ /\d+/ && $RGSS_SCRIPTS
61
+ io << "Section name :[" << $RGSS_SCRIPTS[$1.to_i][1] << "]\n"
62
+ end
63
+ io << "__LINE__:" <<eval('__LINE__', @binding) << "\n"
64
+ io << "Nesting:" << eval('Module.nesting', @binding) << "\n"
65
+ io << "caller:" << eval('caller', @binding).join("\n") << "\n"
66
+ end
67
+ end
68
+
69
+ def exception(io)
70
+ form io, "Exceptions" do
71
+ if $!
72
+ io << $!.to_s << "\n"
73
+ io << $!.backtrace.join("\n") << "\n"
74
+ else
75
+ io << "No exception." << "\n"
76
+ end
77
+ end
78
+ end
79
+
80
+ def rubyobjects(io)
81
+ form io, "Global Variables" do
82
+ (global_variables - [:$RGSS_SCRIPTS]).each{|g|
83
+ begin
84
+ v = eval(g.to_s, @binding)
85
+ io << (" #{g}:" << v.inspect << "\n")
86
+ rescue
87
+ end
88
+ }
89
+ io << " $RGSS_SCRIPTS: [#{$RGSS_SCRIPTS.size} scripts]" << "\n" if defined?($RGSS_SCRIPTS)
90
+ end
91
+ form io, "Local Variables" do
92
+ eval('local_variables', @binding).each{|g|
93
+ begin
94
+ v = eval(g.to_s, @binding)
95
+ io << (" #{g}:" << v.inspect << "\n")
96
+ rescue
97
+ end
98
+ }
99
+ end
100
+ form io, "Modules" do
101
+ ret = []
102
+ ObjectSpace.each_object(Module) do |m|
103
+ ret << m
104
+ end
105
+ ret.sort_by{|x| x.to_s}.each do |m|
106
+ io << " " << (m.is_a?(Class) ? "C " : "M ") << m << (m.is_a?(Class) ? "(class)" : "(module)") << ObjectSpace.each_object(m){} << "\n"
107
+ end
108
+
109
+
110
+ end
111
+ end
112
+ def plugins(io)
113
+ form io, "LOADED_FEATURES" do
114
+ io << $LOADED_FEATURES.join("\n") << "\n"
115
+ end
116
+ form io, "PATH" do
117
+ io << ENV['PATH'] << "\n"
118
+ end
119
+ end
120
+
121
+ def minidump(io)
122
+ x = NPGRT.api('Kernel32', 'CreateFileW').call(
123
+ NPGRT.to_unicode("minidump.dmp\0\0")+"\0\0",
124
+ 0x40000000, 0, 0, 2, 0x80, 0
125
+ )
126
+ NPGRT.api('DbgHelp.dll', 'MiniDumpWriteDump').call(
127
+ NPGRT.api('kernel32', 'GetCurrentProcess').call,
128
+ NPGRT.api('kernel32', 'GetCurrentProcessId').call,
129
+ x,
130
+ 0,
131
+ 0,
132
+ 0,
133
+ 0
134
+ )
135
+ NPGRT.api('kernel32', 'CloseHandle').call x
136
+ form io, "Core Dump" do
137
+ io << "Dump file written to minidump.dmp.\n"
138
+ end
139
+ end
140
+
141
+ MAX_MODULE_NAME_LEN = 1024
142
+ def sysmodules(io)
143
+ ph = NPGRT.api('kernel32', 'GetCurrentProcess').call
144
+ num = [0].pack("L")
145
+ NPGRT.api('psapi', 'EnumProcessModules').call ph, 0, 0, num
146
+ num = num.unpack("L").first
147
+ arr = [0].pack("L")*num
148
+ lnum = [0].pack("L")
149
+ NPGRT.api('psapi', 'EnumProcessModules').call ph, arr, num, lnum
150
+ ret = []
151
+ lnum = lnum.unpack("L").first
152
+ arr.unpack(NPGRT::PtrType + "*")[0, lnum].each{|ptr|
153
+ break if ptr == 0 && !ret.empty?
154
+ buf = [0].pack("S")*MAX_MODULE_NAME_LEN
155
+ NPGRT.api('kernel32', 'GetModuleFileNameW').call ptr, buf, MAX_MODULE_NAME_LEN
156
+
157
+ ret << NPGRT.wstrread(buf)
158
+ }
159
+ form io, "System Modules" do |io|
160
+ ret.each{|x|
161
+ io << " - " << x << "\n"
162
+ }
163
+ end
164
+ end
165
+
166
+
167
+
168
+
169
+ def normal
170
+ basic(@io)
171
+ inifile(@io)
172
+ exception(@io)
173
+ plugins(@io)
174
+ sysmodules(@io)
175
+ rubyobjects(@io)
176
+ position(@io)
177
+
178
+ scripts(@io)
179
+ minidump(@io)
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,183 @@
1
+ module NPGRT
2
+ class Report
3
+
4
+
5
+ def initialize(io, &b)
6
+ @io = io
7
+ @binding = b.binding
8
+ end
9
+
10
+ private
11
+ def title(str)
12
+ "#{str} ----------\n"
13
+ end
14
+
15
+ def tail
16
+ "\n\n\n"
17
+ end
18
+
19
+ def form(io, title)
20
+ io << title(title)
21
+ yield io
22
+ io << tail
23
+ io
24
+ end
25
+ public
26
+ def inifile(io)
27
+ return unless FileTest.file?("Game.ini")
28
+ form io, "Game.ini" do |io|
29
+ io << File.read("Game.ini")
30
+ end
31
+ end
32
+
33
+ def scripts(io)
34
+ return unless defined?($RGSS_SCRIPTS)
35
+ form io, "Scripts" do |io|
36
+ io << $RGSS_SCRIPTS.map{|x| " [%s] " % x[1]}.join("\n")
37
+ end
38
+ end
39
+
40
+ def basic(io)
41
+ form io, "Basic Information" do |io|
42
+ io << "path:" << Dir.getwd << "\n"
43
+ io << "Ruby Version:" << RUBY_VERSION << "\n"
44
+ io << "NPGRT Version:" << NPGRT::VERSION << "\n"
45
+ io << "Platform:" << NPGRT::PlatformWidth << "\n"
46
+ begin
47
+ str = "" << "FPS:" << Graphics.frame_rate.to_s << "\n"
48
+ str << "Frame Count:" << Graphics.frame_count.to_s << "\n"
49
+ io << str
50
+ rescue
51
+ end
52
+ io << "Command Line:" << NPGRT.wstrread(NPGRT.api('kernel32', 'GetCommandLineW').call) << "\n"
53
+
54
+ end
55
+ end
56
+
57
+ def position(io)
58
+ form io, "Position" do |io|
59
+ io << "__FILE__:" << eval('__FILE__', @binding) << "\n"
60
+ if eval('__FILE__', @binding) =~ /\d+/ && $RGSS_SCRIPTS
61
+ io << "Section name :[" << $RGSS_SCRIPTS[$1.to_i][1] << "]\n"
62
+ end
63
+ io << "__LINE__:" <<eval('__LINE__', @binding) << "\n"
64
+ io << "Nesting:" << eval('Module.nesting', @binding) << "\n"
65
+ io << "caller:" << eval('caller', @binding).join("\n") << "\n"
66
+ end
67
+ end
68
+
69
+ def exception(io)
70
+ form io, "Exceptions" do
71
+ if $!
72
+ io << $!.to_s << "\n"
73
+ io << $!.backtrace.join("\n") << "\n"
74
+ else
75
+ io << "No exception." << "\n"
76
+ end
77
+ end
78
+ end
79
+
80
+ def rubyobjects(io)
81
+ form io, "Global Variables" do
82
+ (global_variables - [:$RGSS_SCRIPTS]).each{|g|
83
+ begin
84
+ v = eval(g.to_s, @binding)
85
+ io << (" #{g}:" << v.inspect << "\n")
86
+ rescue
87
+ end
88
+ }
89
+ io << " $RGSS_SCRIPTS: [#{$RGSS_SCRIPTS.size} scripts]" << "\n" if defined?($RGSS_SCRIPTS)
90
+ end
91
+ form io, "Local Variables" do
92
+ eval('local_variables', @binding).each{|g|
93
+ begin
94
+ v = eval(g.to_s, @binding)
95
+ io << (" #{g}:" << v.inspect << "\n")
96
+ rescue
97
+ end
98
+ }
99
+ end
100
+ form io, "Modules" do
101
+ ret = []
102
+ ObjectSpace.each_object(Module) do |m|
103
+ ret << m
104
+ end
105
+ ret.sort_by{|x| x.to_s}.each do |m|
106
+ io << " " << (m.is_a?(Class) ? "C " : "M ") << m << (m.is_a?(Class) ? "(class)" : "(module)") << ObjectSpace.each_object(m){} << "\n"
107
+ end
108
+
109
+
110
+ end
111
+ end
112
+ def plugins(io)
113
+ form io, "LOADED_FEATURES" do
114
+ io << $LOADED_FEATURES.join("\n") << "\n"
115
+ end
116
+ form io, "PATH" do
117
+ io << ENV['PATH'] << "\n"
118
+ end
119
+ end
120
+
121
+ def minidump(io)
122
+ x = NPGRT.api('Kernel32', 'CreateFileW').call(
123
+ NPGRT.to_unicode("minidump.dmp\0\0")+"\0\0",
124
+ 0x40000000, 0, 0, 2, 0x80, 0
125
+ )
126
+ NPGRT.api('DbgHelp.dll', 'MiniDumpWriteDump').call(
127
+ NPGRT.api('kernel32', 'GetCurrentProcess').call,
128
+ NPGRT.api('kernel32', 'GetCurrentProcessId').call,
129
+ x,
130
+ 0,
131
+ 0,
132
+ 0,
133
+ 0
134
+ )
135
+ NPGRT.api('kernel32', 'CloseHandle').call x
136
+ form io, "Core Dump" do
137
+ io << "Dump file written to minidump.dmp.\n"
138
+ en
139
+
140
+ end
141
+
142
+ MAX_MODULE_NAME_LEN = 1024
143
+ def sysmodules(io)
144
+ ph = NPGRT.api('kernel32', 'GetCurrentProcess').call
145
+ num = [0].pack("L")
146
+ NPGRT.api('psapi', 'EnumProcessModules').call ph, 0, 0, num
147
+ num = num.unpack("L").first
148
+ arr = [0].pack("L")*num
149
+ lnum = [0].pack("L")
150
+ NPGRT.api('psapi', 'EnumProcessModules').call ph, arr, num, lnum
151
+ ret = []
152
+ lnum = lnum.unpack("L").first
153
+ arr.unpack(NPGRT::PtrType + "*")[0, lnum].each{|ptr|
154
+ break if ptr == 0 && !ret.empty?
155
+ buf = [0].pack("S")*MAX_MODULE_NAME_LEN
156
+ NPGRT.api('kernel32', 'GetModuleFileNameW').call ptr, buf, MAX_MODULE_NAME_LEN
157
+
158
+ ret << NPGRT.wstrread(buf)
159
+ }
160
+ form io, "System Modules" do |io|
161
+ ret.each{|x|
162
+ io << " - " << x << "\n"
163
+ }
164
+ end
165
+ end
166
+
167
+
168
+
169
+
170
+ def normal
171
+ basic(@io)
172
+ inifile(@io)
173
+ exception(@io)
174
+ plugins(@io)
175
+ sysmodules(@io)
176
+ rubyobjects(@io)
177
+ position(@io)
178
+
179
+ scripts(@io)
180
+ minidump(@io)
181
+ end
182
+ end
183
+ end
data/lib/npgrt/require.rb CHANGED
@@ -6,6 +6,28 @@ module NPGRT
6
6
  super a
7
7
  end
8
8
 
9
+ ADDPATH = []
10
+
11
+ def binary_forms(a)
12
+ w = NPGRT::PlatformWidth.to_s
13
+ [ a, a+".dll", a+".so",
14
+ File.basename(a) + "_" + w + File.extname(a),
15
+ File.basename(a) + "_" + w + ".dll",
16
+ File.basename(a) + "_" + w + ".so"
17
+ ]
18
+ end
19
+
20
+ def require_binary(a)
21
+ path = binary_forms(a).inject([]){|ret, v|
22
+ ret.concat Gem.find_files v
23
+ }
24
+ v = path.map{|x|
25
+ FileTest.file?(x) ? NPGRT.normalize_pathsep_os(File.dirname(x)) : nil
26
+ }.compact - ADDPATH
27
+ ENV['path'] += ";" + v.join(";")
28
+ ADDPATH.concat v
29
+ end
30
+
9
31
  alias primitive_require require
10
32
  private :primitive_require
11
33
 
@@ -21,7 +43,7 @@ module NPGRT
21
43
  dir = File.dirname dir if FileTest.file?(dir)
22
44
  system "cmd /c \"cd /d #{dir} & rake npgrt:build\""
23
45
  end
46
+
24
47
  end
25
48
 
26
- extend Require
27
49
  end