rmxp_extractor 1.5 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,238 +1,244 @@
1
- def const_from_string(str)
2
- str.split("::").inject(Object) do |mod, class_name|
3
- mod.const_get(class_name)
4
- end
5
- end
6
-
7
- def create_from_rmxp_serialize(obj)
8
- if obj.is_a?(Hash)
9
- ret = {}
10
- # Hashes have no map method. Why? I dunno!
11
- obj.each do |key, value|
12
- if key.is_a?(String) && key.start_with?("class ")
13
- const = const_from_string(key.delete_prefix("class "))
14
- ret = const.new.from_rmxp_serialize(value)
15
- else
16
- if key.is_a?(String) && key =~ /\A[0-9]+\z/ # Key is an integer
17
- key = key.to_i
18
- end
19
- ret[key] = create_from_rmxp_serialize(value)
20
- end
21
- end
22
- return ret
23
- end
24
- if obj.is_a?(Array)
25
- obj.map! do |value|
26
- create_from_rmxp_serialize(value)
27
- end
28
- end
29
- ret = obj
30
- end
31
-
32
- class Object
33
- def rmxp_serialize
34
- hash = {}
35
- self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var).rmxp_serialize }
36
- { "class #{self.class.name}" => hash }
37
- end
38
-
39
- def from_rmxp_serialize(hash)
40
- hash.each { |key, value| self.instance_variable_set("@#{key}", create_from_rmxp_serialize(value)) }
41
- self
42
- end
43
- end
44
-
45
- class Numeric
46
- def rmxp_serialize
47
- self
48
- end
49
- end
50
-
51
- class String
52
- def rmxp_serialize
53
- self
54
- end
55
- end
56
-
57
- class Array
58
- def rmxp_serialize
59
- arr = []
60
- self.each { |e| arr << e.rmxp_serialize }
61
- arr
62
- end
63
- end
64
-
65
- class Hash
66
- def rmxp_serialize
67
- hash = {}
68
- self.each { |key, value| hash[key] = value.rmxp_serialize }
69
- hash
70
- end
71
- end
72
-
73
- class TrueClass
74
- def rmxp_serialize
75
- self
76
- end
77
- end
78
-
79
- class FalseClass
80
- def rmxp_serialize
81
- self
82
- end
83
- end
84
-
85
- class NilClass
86
- def rmxp_serialize
87
- self
88
- end
89
- end
90
-
91
- class Color
92
- attr_accessor :red, :green, :blue, :alpha
93
-
94
- def _dump(limit)
95
- [@red, @green, @blue, @alpha].pack("EEEE")
96
- end
97
-
98
- def self._load(obj)
99
- red, green, blue, alpha = *obj.unpack("EEEE")
100
- obj = Color.new
101
- obj.red = red; obj.green = green; obj.blue = blue; obj.alpha = alpha
102
- obj
103
- end
104
- end
105
-
106
- class Table
107
- attr_accessor :num_of_dimensions, :xsize, :ysize, :zsize, :num_of_elements, :elements
108
-
109
- def _dump(limit)
110
- [@num_of_dimensions, @xsize, @ysize, @zsize, @num_of_elements, *@elements.flatten].pack("VVVVVv*")
111
- end
112
-
113
- def self._load(obj)
114
- data = obj.unpack("VVVVVv*")
115
- obj = self.new
116
- num_of_dimensions, xsize, ysize, zsize, num_of_elements, *elements = *data
117
- if num_of_dimensions > 1
118
- if xsize > 1
119
- elements = elements.each_slice(xsize).to_a
120
- else
121
- elements = elements.map { |element| [element] }
122
- end
123
- end
124
- if num_of_dimensions > 2
125
- if ysize > 1
126
- elements = elements.each_slice(ysize).to_a
127
- else
128
- elements = elements.map { |element| [element] }
129
- end
130
- end
131
- obj.num_of_dimensions = num_of_dimensions; obj.xsize = xsize; obj.ysize = ysize; obj.zsize = zsize; obj.elements = elements
132
- obj
133
- end
134
- end
135
-
136
- class Tone
137
- attr_accessor :red, :green, :blue, :gray
138
-
139
- def _dump(limit)
140
- [@red, @green, @blue, @gray].pack("EEEE")
141
- end
142
-
143
- def self._load(obj)
144
- red, green, blue, gray = *obj.unpack("EEEE")
145
- obj = Tone.new
146
- obj.red = red; obj.green = green; obj.blue = blue; obj.gray = gray
147
- end
148
- end
149
-
150
- module RPG
151
- class Event
152
- class Page
153
- class Condition
154
- end
155
-
156
- class Graphic
157
- end
158
- end
159
- end
160
-
161
- class EventCommand
162
- end
163
-
164
- class MoveRoute
165
- end
166
-
167
- class MoveCommand
168
- end
169
-
170
- class Map
171
- end
172
-
173
- class MapInfo
174
- end
175
-
176
- class AudioFile
177
- end
178
-
179
- class System
180
- class Words
181
- end
182
-
183
- class TestBattler
184
- end
185
- end
186
-
187
- class CommonEvent
188
- end
189
-
190
- class Tileset
191
- end
192
-
193
- class State
194
- end
195
-
196
- class Animation
197
- class Frame
198
- end
199
-
200
- class Timing
201
- end
202
- end
203
-
204
- class Class
205
- class Learning
206
- end
207
- end
208
-
209
- class Actor
210
- end
211
-
212
- class Skill
213
- end
214
-
215
- class Item
216
- end
217
-
218
- class Weapon
219
- end
220
-
221
- class Armor
222
- end
223
-
224
- class Enemy
225
- class Action
226
- end
227
- end
228
-
229
- class Troop
230
- class Member
231
- end
232
-
233
- class Page
234
- class Condition
235
- end
236
- end
237
- end
238
- end
1
+ def const_from_string(str)
2
+ str.split("::").inject(Object) do |mod, class_name|
3
+ mod.const_get(class_name)
4
+ end
5
+ end
6
+
7
+ def create_from_rmxp_serialize(obj)
8
+ if obj.is_a?(Hash)
9
+ ret = {}
10
+ # Hashes have no map method. Why? I dunno!
11
+ obj.each do |key, value|
12
+ if key.is_a?(String) && key.start_with?("class ")
13
+ const = const_from_string(key.delete_prefix("class "))
14
+ ret = const.new.from_rmxp_serialize(value)
15
+ else
16
+ if key.is_a?(String) && key =~ /\A[0-9]+\z/ # Key is an integer
17
+ key = key.to_i
18
+ end
19
+ ret[key] = create_from_rmxp_serialize(value)
20
+ end
21
+ end
22
+ return ret
23
+ end
24
+ if obj.is_a?(Array)
25
+ obj.map! do |value|
26
+ create_from_rmxp_serialize(value)
27
+ end
28
+ end
29
+ ret = obj
30
+ end
31
+
32
+ class Object
33
+ def rmxp_serialize
34
+ hash = {}
35
+ self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var).rmxp_serialize }
36
+ { "class #{self.class.name}" => hash }
37
+ end
38
+
39
+ def from_rmxp_serialize(hash)
40
+ hash.each { |key, value| self.instance_variable_set("@#{key}", create_from_rmxp_serialize(value)) }
41
+ self
42
+ end
43
+ end
44
+
45
+ class Numeric
46
+ def rmxp_serialize
47
+ self
48
+ end
49
+ end
50
+
51
+ class String
52
+ def rmxp_serialize
53
+ self
54
+ end
55
+ end
56
+
57
+ class Array
58
+ def rmxp_serialize
59
+ arr = []
60
+ self.each { |e| arr << e.rmxp_serialize }
61
+ arr
62
+ end
63
+ end
64
+
65
+ class Hash
66
+ def rmxp_serialize
67
+ hash = {}
68
+ self.each { |key, value| hash[key] = value.rmxp_serialize }
69
+ hash
70
+ end
71
+ end
72
+
73
+ class TrueClass
74
+ def rmxp_serialize
75
+ self
76
+ end
77
+ end
78
+
79
+ class FalseClass
80
+ def rmxp_serialize
81
+ self
82
+ end
83
+ end
84
+
85
+ class NilClass
86
+ def rmxp_serialize
87
+ self
88
+ end
89
+ end
90
+
91
+ class Color
92
+ attr_accessor :red, :green, :blue, :alpha
93
+
94
+ def _dump(limit)
95
+ [@red, @green, @blue, @alpha].pack("EEEE")
96
+ end
97
+
98
+ def self._load(obj)
99
+ red, green, blue, alpha = *obj.unpack("EEEE")
100
+ obj = Color.new
101
+ obj.red = red; obj.green = green; obj.blue = blue; obj.alpha = alpha
102
+ obj
103
+ end
104
+ end
105
+
106
+ class Table
107
+ attr_accessor :num_of_dimensions, :xsize, :ysize, :zsize, :num_of_elements, :elements
108
+
109
+ def _dump(limit)
110
+ [@num_of_dimensions, @xsize, @ysize, @zsize, @num_of_elements, *@elements.flatten].pack("VVVVVv*")
111
+ end
112
+
113
+ def self._load(obj)
114
+ data = obj.unpack("VVVVVv*")
115
+ obj = self.new
116
+ num_of_dimensions, xsize, ysize, zsize, num_of_elements, *elements = *data
117
+ if num_of_dimensions > 1
118
+ if xsize > 1
119
+ elements = elements.each_slice(xsize).to_a
120
+ else
121
+ elements = elements.map { |element| [element] }
122
+ end
123
+ end
124
+ if num_of_dimensions > 2
125
+ if ysize > 1
126
+ elements = elements.each_slice(ysize).to_a
127
+ else
128
+ elements = elements.map { |element| [element] }
129
+ end
130
+ end
131
+ obj.num_of_dimensions = num_of_dimensions; obj.xsize = xsize; obj.ysize = ysize; obj.zsize = zsize; obj.elements = elements
132
+ obj
133
+ end
134
+ end
135
+
136
+ class Tone
137
+ attr_accessor :red, :green, :blue, :gray
138
+
139
+ def _dump(limit)
140
+ [@red, @green, @blue, @gray].pack("EEEE")
141
+ end
142
+
143
+ def self._load(obj)
144
+ red, green, blue, gray = *obj.unpack("EEEE")
145
+ obj = Tone.new
146
+ obj.red = red; obj.green = green; obj.blue = blue; obj.gray = gray
147
+ end
148
+ end
149
+
150
+ module RPG
151
+ class Event
152
+ class Page
153
+ class Condition
154
+ end
155
+
156
+ class Graphic
157
+ end
158
+ end
159
+ end
160
+
161
+ class EventCommand
162
+ end
163
+
164
+ class MoveRoute
165
+ end
166
+
167
+ class MoveCommand
168
+ end
169
+
170
+ class Map
171
+ end
172
+
173
+ class MapInfo
174
+ end
175
+
176
+ class AudioFile
177
+ end
178
+
179
+ class System
180
+ class Words
181
+ end
182
+
183
+ class TestBattler
184
+ end
185
+ end
186
+
187
+ class CommonEvent
188
+ end
189
+
190
+ class Tileset
191
+ end
192
+
193
+ class State
194
+ end
195
+
196
+ class Animation
197
+ class Frame
198
+ end
199
+
200
+ class Timing
201
+ end
202
+ end
203
+
204
+ class Class
205
+ class Learning
206
+ end
207
+ end
208
+
209
+ class Actor
210
+ end
211
+
212
+ class Skill
213
+ end
214
+
215
+ class Item
216
+ end
217
+
218
+ class Weapon
219
+ end
220
+
221
+ class Armor
222
+ end
223
+
224
+ class Enemy
225
+ class Action
226
+ end
227
+ end
228
+
229
+ class Troop
230
+ class Member
231
+ end
232
+
233
+ class Page
234
+ class Condition
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ class Script
241
+ attr_accessor :id
242
+ attr_accessor :name
243
+ attr_accessor :data
244
+ end
@@ -1,80 +1,82 @@
1
- module RMXPExtractor
2
- def self.export(format)
3
- format ||= "json"
4
- STDERR.puts "No Data Directory!" unless Dir.exists? "./Data"
5
- exit 1 unless Dir.exists? "./Data"
6
-
7
- require "json"
8
- require "yaml"
9
- require "amazing_print"
10
- require "ruby-progressbar"
11
- require "fileutils"
12
- require "pathname"
13
- require "readline"
14
- require_relative "classnames"
15
- require_relative "script_handler"
16
-
17
- if format == "ron"
18
- require_relative "ron"
19
- end
20
-
21
- window_size = 120
22
- progress_format = "%a /%e |%B| %p%% %c/%C %r files/sec %t, currently processing: "
23
- progress = ProgressBar.create(
24
- format: progress_format,
25
- starting_at: 0,
26
- total: nil,
27
- output: $stderr,
28
- length: window_size,
29
- title: "exported",
30
- remainder_mark: "\e[0;30m█\e[0m",
31
- progress_mark: "█",
32
- unknown_progress_animation_steps: ["==>", ">==", "=>="],
33
- )
34
- Dir.mkdir "./Data_#{format.upcase}" unless Dir.exists? "./Data_#{format.upcase}"
35
- paths = Pathname.glob(("./Data/" + ("*" + ".rxdata")))
36
- count = paths.size
37
- progress.total = count
38
- paths.each_with_index do |path, i|
39
- content = Hash.new
40
-
41
- name = path.basename(".rxdata")
42
- begin
43
- rxdata = Marshal.load(path.read(mode: "rb"))
44
- rescue TypeError => e # Failed to load
45
- puts "Failed to load file #{path}.\n"
46
- next
47
- end
48
-
49
- progress.format = progress_format + name.to_s
50
- case name.to_s
51
- when "xScripts", "Scripts"
52
- RMXPExtractor.rpgscript("./", "./Scripts", "#{name.to_s}.rxdata", true)
53
- content["data"] = rxdata.map do |a|
54
- a[2] = a[2].bytes
55
- a
56
- end.rmxp_serialize
57
- content["version"] = VERSION
58
- else
59
- content["data"] = rxdata.rmxp_serialize
60
- content["version"] = VERSION
61
- end
62
-
63
- file = File.open("./Data_#{format.upcase}/" + name.sub_ext(".#{format}").to_s, "wb")
64
- file.puts case format
65
- when "yaml"
66
- content.to_yaml
67
- when "json"
68
- JSON.pretty_generate(content)
69
- when "toml"
70
- TomlRB.dump(content)
71
- when "rb"
72
- content.ai(index: false, indent: 2, plain: true)
73
- when "ron"
74
- content["data"]
75
- end
76
-
77
- progress.increment
78
- end
79
- end
80
- end
1
+ module RMXPExtractor
2
+ def self.export(format)
3
+ format ||= "json"
4
+ STDERR.puts "No Data Directory!" unless Dir.exists? "./Data"
5
+ exit 1 unless Dir.exists? "./Data"
6
+
7
+ require "json"
8
+ require "yaml"
9
+ require "amazing_print"
10
+ require "ruby-progressbar"
11
+ require "fileutils"
12
+ require "pathname"
13
+ require "readline"
14
+ require_relative "classnames"
15
+ require_relative "script_handler"
16
+
17
+ if format == "ron"
18
+ require_relative "ron"
19
+ end
20
+
21
+ window_size = 120
22
+ progress_format = "%a /%e |%B| %p%% %c/%C %r files/sec %t, currently processing: "
23
+ progress = ProgressBar.create(
24
+ format: progress_format,
25
+ starting_at: 0,
26
+ total: nil,
27
+ output: $stderr,
28
+ length: window_size,
29
+ title: "exported",
30
+ remainder_mark: "\e[0;30m█\e[0m",
31
+ progress_mark: "█",
32
+ unknown_progress_animation_steps: ["==>", ">==", "=>="],
33
+ )
34
+ Dir.mkdir "./Data_#{format.upcase}" unless Dir.exists? "./Data_#{format.upcase}"
35
+ paths = Pathname.glob(("./Data/" + ("*" + ".rxdata")))
36
+ count = paths.size
37
+ progress.total = count
38
+ paths.each_with_index do |path, i|
39
+ content = Hash.new
40
+
41
+ name = path.basename(".rxdata")
42
+ begin
43
+ rxdata = Marshal.load(path.read(mode: "rb"))
44
+ rescue TypeError => e # Failed to load
45
+ puts "Failed to load file #{path}.\n"
46
+ next
47
+ end
48
+
49
+ progress.format = progress_format + name.to_s
50
+ case name.to_s
51
+ when "xScripts", "Scripts"
52
+ RMXPExtractor.rpgscript("./", "./Scripts", "#{name.to_s}.rxdata", true)
53
+ content["data"] = rxdata.map do |a|
54
+ s = Script.new
55
+ s.id, s.name, s.data = a
56
+ s.data = s.data.bytes
57
+ s
58
+ end.rmxp_serialize
59
+ content["version"] = VERSION
60
+ else
61
+ content["data"] = rxdata.rmxp_serialize
62
+ content["version"] = VERSION
63
+ end
64
+
65
+ file = File.open("./Data_#{format.upcase}/" + name.sub_ext(".#{format}").to_s, "wb")
66
+ file.puts case format
67
+ when "yaml"
68
+ content.to_yaml
69
+ when "json"
70
+ JSON.pretty_generate(content)
71
+ when "toml"
72
+ TomlRB.dump(content)
73
+ when "rb"
74
+ content.ai(index: false, indent: 2, plain: true)
75
+ when "ron"
76
+ content["data"]
77
+ end
78
+
79
+ progress.increment
80
+ end
81
+ end
82
+ end