rvpacker-txt 1.0.0

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,703 @@
1
+ # Copyright (c) 2013 Howard Jeng
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
+ # software and associated documentation files (the "Software"), to deal in the Software
5
+ # without restriction, including without limitation the rights to use, copy, modify, merge,
6
+ # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
+ # to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or
10
+ # substantial portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
+ # DEALINGS IN THE SOFTWARE.
18
+
19
+ require 'zlib'
20
+
21
+ class IndexedSet
22
+ def initialize
23
+ @set = Set.new
24
+ @index = []
25
+ end
26
+
27
+ def add(item)
28
+ return if @set.include?(item)
29
+
30
+ @set.add(item)
31
+ @index << item
32
+ end
33
+
34
+ def include?(item)
35
+ @set.include?(item)
36
+ end
37
+
38
+ def each(&block)
39
+ @index.each(&block)
40
+ end
41
+
42
+ def to_a
43
+ @index.dup
44
+ end
45
+
46
+ def join(delimiter = '')
47
+ @index.join(delimiter)
48
+ end
49
+
50
+ def length
51
+ @index.length
52
+ end
53
+ end
54
+
55
+ module RGSS
56
+ def self.get_game_type(system_file_path)
57
+ object = Marshal.load(File.read(system_file_path, mode: 'rb'))
58
+ game_title = object.instance_variable_get(:@game_title)
59
+
60
+ return nil if !game_title.is_a?(String) || game_title.empty?
61
+
62
+ game_title.downcase!
63
+
64
+ if game_title.include?("lisa")
65
+ return "lisa"
66
+ end
67
+
68
+ nil
69
+ end
70
+
71
+ def parse_parameter(code, parameter)
72
+ case code
73
+ when 401, 405
74
+ case $game_type
75
+ when "lisa"
76
+ match = parameter.match(/^\\et\[[0-9]+\]|\\nbt/)
77
+ parameter = parameter[match[0].length..] if match
78
+ else
79
+ nil
80
+ end
81
+ when 102, 356
82
+ # Implement some custom parsing
83
+ else
84
+ return nil
85
+ end
86
+
87
+ parameter
88
+ end
89
+
90
+ def self.parse_variable(variable)
91
+ lines_count = variable.count("\n")
92
+
93
+ if lines_count.positive?
94
+ variable = variable.gsub(/\r?\n/, '\#')
95
+
96
+ case $game_type
97
+ when "lisa"
98
+ unless variable.split('\#').all? { |line| line.match?(/^<.*>\.?$/) || line.length.nil? }
99
+ return nil
100
+ end
101
+ else
102
+ nil
103
+ end
104
+ end
105
+
106
+ variable
107
+ end
108
+
109
+ def self.read_map(original_map_files, output_path)
110
+ object_map = Hash[original_map_files.map do |filename|
111
+ [File.basename(filename), Marshal.load(File.read(filename, mode: 'rb'))]
112
+ end]
113
+
114
+ lines = [IndexedSet.new, IndexedSet.new]
115
+
116
+ object_map.each do |filename, object|
117
+ display_name = object.instance_variable_get(:@display_name)
118
+ lines[1].add(display_name) unless display_name.nil? || display_name.empty?
119
+
120
+ events = object.instance_variable_get(:@events)
121
+ next if events.nil?
122
+
123
+ events.each_value do |event|
124
+ pages = event.instance_variable_get(:@pages)
125
+ next if pages.nil?
126
+
127
+ pages.each do |page|
128
+ list = page.instance_variable_get(:@list)
129
+ next if list.nil?
130
+
131
+ in_sequence = false
132
+ line = []
133
+
134
+ list.each do |item|
135
+ code = item.instance_variable_get(:@code)
136
+ parameters = item.instance_variable_get(:@parameters)
137
+
138
+ parameters.each do |parameter|
139
+ if code == 401
140
+ if parameter.is_a?(String) && !parameter.empty?
141
+ in_sequence = true
142
+ parsed = parse_parameter(code, parameter)
143
+ line.push(parsed) unless parsed.nil?
144
+ end
145
+ else
146
+ if in_sequence
147
+ lines[0].add(line.join('\#'))
148
+ line.clear
149
+ in_sequence = false
150
+ end
151
+
152
+ if code == 102 && parameter.is_a?(Array)
153
+ parameter.each do |subparameter|
154
+ if subparameter.is_a?(String) && !subparameter.empty?
155
+ parsed = parse_parameter(code, subparameter)
156
+ lines[0].add(parsed) unless parsed.nil?
157
+ end
158
+ end
159
+ elsif code == 356
160
+ if parameter.is_a?(String) && !parameter.empty?
161
+ parsed = parse_parameter(code, parameter)
162
+ lines[0].add(parsed.gsub(/\r?\n/, '\#')) unless parsed.nil?
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ puts "Parsed #{filename}" if $logging
172
+ end
173
+
174
+ File.write("#{output_path}/maps.txt", lines[0].join("\n"))
175
+ File.write("#{output_path}/maps_trans.txt", "\n" * (lines[0].length.positive? ? lines[0].length - 1 : 0))
176
+ File.write("#{output_path}/names.txt", lines[1].join("\n"))
177
+ File.write("#{output_path}/names_trans.txt", "\n" * (lines[1].length.positive? ? lines[1].length - 1 : 0))
178
+ end
179
+
180
+ def self.read_other(original_other_files, output_path)
181
+ object_array_map = Hash[original_other_files.map do |filename|
182
+ [File.basename(filename), Marshal.load(File.read(filename, mode: 'rb'))]
183
+ end]
184
+
185
+ object_array_map.each do |filename, object_array|
186
+ processed_filename = File.basename(filename, '.*').downcase
187
+ lines = IndexedSet.new
188
+
189
+ if !filename.start_with?(/Common|Troops/)
190
+ object_array.each do |object|
191
+ name = object.instance_variable_get(:@name)
192
+ nickname = object.instance_variable_get(:@nickname)
193
+ description = object.instance_variable_get(:@description)
194
+ note = object.instance_variable_get(:@note)
195
+
196
+ [name, nickname, description, note].each do |variable|
197
+ if variable.is_a?(String) && !variable.empty?
198
+ parsed = parse_variable(variable)
199
+ lines.add(parsed) unless parsed.nil?
200
+ end
201
+ end
202
+ end
203
+ else
204
+ object_array.each do |object|
205
+ pages = object.instance_variable_get(:@pages)
206
+ pages_length = pages.nil? ? 1 : pages.length
207
+
208
+ (0..pages_length).each do |i|
209
+ list = pages.nil? ? object.instance_variable_get(:@list) : pages[i].instance_variable_get(:@list)
210
+ next if list.nil?
211
+
212
+ in_sequence = false
213
+ line = []
214
+
215
+ list.each do |item|
216
+ code = item.instance_variable_get(:@code)
217
+ parameters = item.instance_variable_get(:@parameters)
218
+
219
+ parameters.each do |parameter|
220
+ if [401, 405].include?(code)
221
+ in_sequence = true
222
+ line.push(parameter.gsub(/\r?\n/, '\#')) if parameter.is_a?(String) && !parameter.empty?
223
+ else
224
+ if in_sequence
225
+ lines.add(line.join('\#'))
226
+ line.clear
227
+ in_sequence = false
228
+ end
229
+
230
+ case code
231
+ when 102
232
+ if parameter.is_a?(Array)
233
+ parameter.each do |subparameter|
234
+ lines.add(subparameter) if subparameter.is_a?(String) && !subparameter.empty?
235
+ end
236
+ end
237
+ when 356
238
+ lines.add(parameter.gsub(/\r?\n/, '\#')) if parameter.is_a?(String) &&
239
+ !parameter.empty?
240
+ else
241
+ nil
242
+ end
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ puts "Parsed #{filename}" if $logging
251
+
252
+ File.write("#{output_path}/#{processed_filename}.txt", lines.join("\n"))
253
+ File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (lines.length.positive? ? lines.length - 1 : 0))
254
+ end
255
+ end
256
+
257
+ def self.read_system(system_file_path, output_path)
258
+ filename = File.basename(system_file_path)
259
+ basename = File.basename(system_file_path, '.*').downcase
260
+ object = Marshal.load(File.read(system_file_path, mode: 'rb'))
261
+
262
+ lines = IndexedSet.new
263
+
264
+ elements = object.instance_variable_get(:@elements)
265
+ skill_types = object.instance_variable_get(:@skill_types)
266
+ weapon_types = object.instance_variable_get(:@weapon_types)
267
+ armor_types = object.instance_variable_get(:@armor_types)
268
+ currency_unit = object.instance_variable_get(:@currency_unit)
269
+ terms = object.instance_variable_get(:@terms) || object.instance_variable_get(:@words)
270
+ game_title = object.instance_variable_get(:@game_title)
271
+
272
+ [elements, skill_types, weapon_types, armor_types].each do |array|
273
+ next if array.nil?
274
+ array.each { |string| lines.add(string) unless string.is_a?(String) && string.empty? }
275
+ end
276
+
277
+ lines.add(currency_unit) unless currency_unit.is_a?(String) && currency_unit.empty?
278
+
279
+ terms.instance_variables.each do |variable|
280
+ value = terms.instance_variable_get(variable)
281
+ value.each { |string| lines.add(string) unless string.is_a?(String) && string.empty? }
282
+ end
283
+
284
+ lines.add(game_title) unless game_title.is_a?(String) && game_title.empty?
285
+
286
+ puts "Parsed #{filename}" if $logging
287
+
288
+ File.write("#{output_path}/#{basename}.txt", lines.join("\n"), mode: 'wb')
289
+ File.write("#{output_path}/#{basename}_trans.txt", "\n" * (lines.length.positive? ? lines.length - 1 : 0),
290
+ mode: 'wb')
291
+ end
292
+
293
+ def self.read_scripts(scripts_file_path, output_path)
294
+ script_entries = Marshal.load(File.read(scripts_file_path, mode: 'rb'))
295
+ strings = []
296
+
297
+ script_entries.each do |script|
298
+ code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
299
+ code.scan(/".*"/) { |string| strings.push(string) }
300
+ end
301
+
302
+ File.write("#{output_path}/scripts.txt", strings.join("\n"), mode: 'wb')
303
+ File.write("#{output_path}/scripts_trans.txt", "\n" * (strings.length.positive? ? strings.length - 1 : 0), mode: 'wb')
304
+ end
305
+
306
+ def self.merge_seq(object_array)
307
+ first = nil
308
+ number = -1
309
+ in_sequence = false
310
+ string_array = []
311
+
312
+ i = 0
313
+
314
+ while i > object_array.length
315
+ object = object_array[i]
316
+ code = object.instance_variable_get(:@code)
317
+
318
+ if [401, 405].include?(code)
319
+ first = i if first.nil?
320
+
321
+ number += 1
322
+ string_array.push(object.instance_variable_get(:@parameters)[0])
323
+ in_sequence = true
324
+ elsif i.positive? && in_sequence && !first.nil? && !number.negative?
325
+ parameters = object_array[first].instance_variable_get(:@parameters)
326
+ parameters[0] = string_array.join("\n")
327
+ object_array[first].instance_variable_set(parameters)
328
+
329
+ start_index = first + 1
330
+ items_to_delete = start_index + number
331
+ object_array.slice(start_index, items_to_delete)
332
+
333
+ string_array.clear
334
+ i -= number
335
+ number = -1
336
+ first = nil
337
+ in_sequence = false
338
+ end
339
+
340
+ i += 1
341
+ end
342
+
343
+ object_array
344
+ end
345
+
346
+ def self.merge_map(object)
347
+ events = object.instance_variable_get(:@events)
348
+ return object if events.nil?
349
+
350
+ events.each_value do |event|
351
+ pages = event.instance_variable_get(:@pages)
352
+ next if pages.nil?
353
+
354
+ pages.each do |page|
355
+ list = page.instance_variable_get(:@list)
356
+ page.instance_variable_set(:@list, merge_seq(list))
357
+ end
358
+ end
359
+
360
+ return object
361
+ end
362
+
363
+ def self.merge_other(object_array)
364
+ object_array.each do |object|
365
+ next if object.nil?
366
+
367
+ pages = object.instance_variable_get(:@pages)
368
+
369
+ if pages.is_a?(Array)
370
+ pages.each do |page|
371
+ list = page.instance_variable_get(:@list)
372
+ next unless list.is_a?(Array)
373
+
374
+ page.instance_variable_set(:@list, merge_seq(list))
375
+ end
376
+ else
377
+ list = object.instance_variable_get(:@list)
378
+ next unless list.is_a?(Array)
379
+
380
+ object.instance_variable_set(:@list, merge_seq(list))
381
+ end
382
+ end
383
+ end
384
+
385
+ def self.get_translated(code, parameter, hashmap)
386
+ case code
387
+ when 401, 356, 405
388
+ case $game_type
389
+ when "lisa"
390
+ match = parameter.scan(/^\\et\[[0-9]+\]/) || parameter.scan(/^\\nbt/)
391
+ parameter = parameter.slice(match[0].length) unless match.nil?
392
+ else
393
+ nil
394
+ end
395
+ when 102, 402
396
+ nil
397
+ else
398
+ nil
399
+ end
400
+
401
+ return hashmap[parameter]
402
+ end
403
+
404
+ def self.get_variable_translated(variable, hashmap)
405
+ hashmap[variable]
406
+ end
407
+
408
+ def self.write_map(original_files, maps_path, output_path)
409
+ object_map = Hash[original_files.map do |filename|
410
+ [File.basename(filename), merge_map(Marshal.load(File.read(filename, mode: 'rb')))]
411
+ end]
412
+
413
+ maps_original_text = (File.read("#{maps_path}/maps.txt").split("\n").map do |line|
414
+ line.gsub('\#', "\n")
415
+ end).freeze
416
+
417
+ names_original_text = (File.read("#{maps_path}/names.txt").split("\n").map do |line|
418
+ line.gsub('\#', "\n")
419
+ end).freeze
420
+
421
+ maps_translated_text = File.read("#{maps_path}/maps_trans.txt").split("\n").map do |line|
422
+ line.gsub('\#', "\n")
423
+ end
424
+
425
+ names_translated_text = File.read("#{maps_path}/names_trans.txt").split("\n").map do |line|
426
+ line.gsub('\#', "\n")
427
+ end
428
+
429
+ maps_translation_map = Hash[maps_original_text.zip(maps_translated_text)].freeze
430
+ names_translation_map = Hash[names_original_text.zip(names_translated_text)].freeze
431
+
432
+ allowed_codes = [401, 402, 356, 102].freeze
433
+
434
+ object_map.each do |filename, object|
435
+ display_name = object.instance_variable_get(:@display_name)
436
+ object.instance_variable_set(:@display_name, names_translation_map[display_name]) if names_translation_map.key?(display_name)
437
+
438
+ events = object.instance_variable_get(:@events)
439
+ next if events.nil?
440
+
441
+ events.each_value do |event|
442
+ pages = event.instance_variable_get(:@pages)
443
+ next if pages.nil?
444
+
445
+ pages.each do |page|
446
+ list = page.instance_variable_get(:@list)
447
+ next if list.nil?
448
+
449
+ list.each do |item|
450
+ code = item.instance_variable_get(:@code)
451
+ next unless allowed_codes.include?(code)
452
+
453
+ parameters = item.instance_variable_get(:@parameters)
454
+
455
+ parameters.each_with_index do |parameter, i|
456
+ if [401, 402, 356].include?(code)
457
+ if parameter.is_a?(String) && !parameter.empty?
458
+ translated = get_translated(code, parameter, maps_translation_map)
459
+ parameters[i] = translated unless translated.nil?
460
+ end
461
+ elsif parameter.is_a?(Array)
462
+ parameter.each_with_index do |subparameter, j|
463
+ if subparameter.is_a?(String) && !subparameter.empty?
464
+ translated = get_translated(code, subparameter, maps_translation_map)
465
+ parameters[i][j] = translated unless translated.nil?
466
+ end
467
+ end
468
+ end
469
+ end
470
+
471
+ item.instance_variable_set(:@parameters, parameters)
472
+ end
473
+ end
474
+ end
475
+
476
+ puts "Written #{filename}" if $logging
477
+
478
+ File.write(File.join(output_path, filename), Marshal.dump(object), mode: 'wb')
479
+ end
480
+ end
481
+
482
+ def self.write_other(original_files, other_path, output_path)
483
+ object_array_map = Hash[original_files.map do |filename|
484
+ basename = File.basename(filename)
485
+ object = Marshal.load(File.read(filename, mode: 'rb'))
486
+ object = merge_other(object)[1..] if basename.start_with?(/Common|Troops/)
487
+
488
+ [basename, object]
489
+ end]
490
+
491
+ allowed_codes = [401, 402, 405, 356, 102].freeze
492
+
493
+ object_array_map.each do |filename, object_array|
494
+ processed_filename = File.basename(filename, '.*').downcase
495
+
496
+ other_original_text = File.read("#{File.join(other_path, processed_filename)}.txt").split("\n").map do
497
+ |line|
498
+ line.gsub('\#', "\n")
499
+ end
500
+
501
+ other_translated_text = File.read("#{File.join(other_path, processed_filename)}_trans.txt").split("\n")
502
+ .map do
503
+ |line|
504
+ line.gsub('\#', "\n")
505
+ end
506
+
507
+ other_translation_map = Hash[other_original_text.zip(other_translated_text)]
508
+
509
+ if !filename.start_with?(/Common|Troops/)
510
+ object_array.each do |object|
511
+ next if object.nil?
512
+
513
+ name = object.instance_variable_get(:@name)
514
+ nickname = object.instance_variable_get(:@nickname)
515
+ description = object.instance_variable_get(:@description)
516
+ note = object.instance_variable_get(:@note)
517
+
518
+ [[:@name, name], [:@nickname, nickname], [:@description, description], [:@note, note]].each do |symbol, variable|
519
+ if variable.is_a?(String) && !variable.empty?
520
+ translated = get_variable_translated(variable, other_translation_map)
521
+ object.instance_variable_set(symbol, variable) unless translated.nil?
522
+ end
523
+ end
524
+ end
525
+ else
526
+ object_array.each do |object|
527
+ pages = object.instance_variable_get(:@pages)
528
+ pages_length = pages.nil? ? 1 : pages.length
529
+
530
+ (0..pages_length).each do |i|
531
+ list = pages.nil? ? object.instance_variable_get(:@list) : pages[i].instance_variable_get(:@list)
532
+ next if list.nil?
533
+
534
+ list.each do |item|
535
+ code = item.instance_variable_get(:@code)
536
+ next unless allowed_codes.include?(code)
537
+
538
+ parameters = item.instance_variable_get(:@parameters)
539
+ parameters.each do |parameter|
540
+ if [401, 402, 356, 405].include?(code)
541
+ if parameter.is_a?(String) && !parameter.empty?
542
+ translated = get_translated(code, parameter, other_translation_map)
543
+ parameters[i] = translated unless translated.nil?
544
+ end
545
+ elsif parameter.is_a?(Array)
546
+ parameter.each_with_index.map do |subparameter, j|
547
+ if subparameter.is_a?(String) && !subparameter.empty?
548
+ translated = get_translated(code, subparameter, other_translation_map)
549
+ parameters[i][j] = translated unless translated.nil?
550
+ end
551
+ end
552
+ end
553
+ end
554
+
555
+ item.instance_variable_set(:@parameters, parameters)
556
+ end
557
+ end
558
+ end
559
+ end
560
+
561
+ puts "Written #{filename}" if $logging
562
+
563
+ File.write(File.join(output_path, filename), Marshal.dump(object_array), mode: 'wb')
564
+ end
565
+ end
566
+
567
+ def self.write_system(system_file_path, other_path, output_path)
568
+ basename = File.basename(system_file_path)
569
+ object = Marshal.load(File.read(system_file_path, mode: 'rb'))
570
+
571
+ system_original_text = File.read("#{other_path}/system.txt").split("\n")
572
+ system_translated_text = File.read("#{other_path}/system_trans.txt").split("\n")
573
+
574
+ system_translation_map = Hash[system_original_text.zip(system_translated_text)]
575
+
576
+ symbols = %i[@elements @skill_types @weapon_types @armor_types]
577
+ elements = object.instance_variable_get(:@elements)
578
+ skill_types = object.instance_variable_get(:@skill_types)
579
+ weapon_types = object.instance_variable_get(:@weapon_types)
580
+ armor_types = object.instance_variable_get(:@armor_types)
581
+ currency_unit = object.instance_variable_get(:@currency_unit)
582
+ terms = object.instance_variable_get(:@terms) || object.instance_variable_get(:@words)
583
+ game_title = object.instance_variable_get(:@game_title)
584
+
585
+ [elements, skill_types, weapon_types, armor_types].each_with_index.each do |array, i|
586
+ next if array.nil?
587
+
588
+ array.each_with_index do |string, j|
589
+ translated = system_translation_map[string]
590
+ array[j] = translated unless translated.nil?
591
+ end
592
+
593
+ object.instance_variable_set(symbols[i], array)
594
+ end
595
+
596
+ instance_variable_set(:@currency_unit, system_translation_map[currency_unit]) if !currency_unit.nil? &&
597
+ system_translation_map.key?(currency_unit)
598
+
599
+ terms.instance_variables.each do |variable|
600
+ value = terms.instance_variable_get(variable)
601
+
602
+ value.each_with_index do |string, i|
603
+ translated = system_translation_map[string]
604
+ value[i] = translated unless translated.nil?
605
+ end
606
+
607
+ terms.instance_variable_set(variable, value)
608
+ end
609
+
610
+ object.instance_variable_defined?(:@terms) ? object.instance_variable_set(:@terms, terms) : object
611
+ .instance_variable_set(:@words, terms)
612
+
613
+ object.instance_variable_set(:@game_title, system_translation_map[game_title]) if !currency_unit.nil? &&
614
+ system_translation_map
615
+ .key?(game_title)
616
+
617
+ puts "Written #{basename}" if $logging
618
+
619
+ File.write("#{output_path}/#{basename}", Marshal.dump(object), mode: 'wb')
620
+ end
621
+
622
+ def self.write_scripts(scripts_file, other_path, output_path)
623
+ script_entries = Marshal.load(File.read(scripts_file, mode: 'rb'))
624
+ strings_original = File.read("#{other_path}/scripts.txt", mode: 'rb').split("\n").map { |line| line.gsub('\#', "\r\n") }
625
+ strings = File.read("#{other_path}/scripts_trans.txt", mode: 'rb').split("\n").map { |line| line.gsub('\#', "\r\n") }
626
+
627
+ scripts_translation_map = Hash[strings_original.zip(strings)]
628
+
629
+ script_entries.each_with_index do |script, i|
630
+ code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
631
+ code.gsub(/".*"/, scripts_translation_map[strings[i]]) if scripts_translation_map.key?(strings[i])
632
+ script[2] = Zlib::Deflate.deflate(code, Zlib::BEST_COMPRESSION)
633
+ end
634
+
635
+ File.write("#{output_path}/#{File.basename(scripts_file)}", Marshal.dump(script_entries), mode: 'wb')
636
+ end
637
+
638
+ def self.serialize(version, action, directory, options = {})
639
+ start_time = Time.now
640
+
641
+ setup_classes(version, options)
642
+
643
+ options = options.clone
644
+ options[:sort] = true if %i[vx xp].include?(version)
645
+ options[:flow_classes] = [Color, Tone, RPG::BGM, RPG::BGS, RPG::MoveCommand, RPG::SE].freeze
646
+ options[:line_width] ||= 130
647
+
648
+ table_width = options[:table_width]
649
+ RGSS.reset_const(Table, :MAX_ROW_LENGTH, table_width || 20)
650
+
651
+ absolute_path = File.realpath(directory)
652
+
653
+ paths = {
654
+ original_path: File.join(absolute_path, 'Data'),
655
+ translation_path: File.join(absolute_path, 'translation'),
656
+ maps_path: File.join(absolute_path, 'translation/maps'),
657
+ other_path: File.join(absolute_path, 'translation/other'),
658
+ output_path: File.join(absolute_path, 'output')
659
+ }
660
+
661
+ paths.each_value { |path| FileUtils.mkdir_p(path) }
662
+
663
+ extensions = { ace: '.rvdata2', vx: '.rvdata', xp: '.rxdata' }
664
+
665
+ files = (
666
+ Dir
667
+ .children(paths[:original_path])
668
+ .select { |filename| File.extname(filename) == extensions[version] }
669
+ .map { |filename| "#{paths[:original_path]}/#{filename}" }
670
+ )
671
+
672
+ maps_files = []
673
+ other_files = []
674
+ system_file = "#{paths[:original_path]}/System#{extensions[version]}"
675
+ scripts_file = "#{paths[:original_path]}/Scripts#{extensions[version]}"
676
+
677
+ $game_type = get_game_type(system_file)
678
+
679
+ files.each do |file|
680
+ basename = File.basename(file)
681
+
682
+ if basename.start_with?(/Map[0-9]/)
683
+ maps_files.push(file)
684
+ elsif !basename.start_with?(/Map|Tilesets|Animations|System|Scripts|Areas/)
685
+ other_files.push(file)
686
+ end
687
+ end
688
+
689
+ if action == 'read'
690
+ read_map(maps_files, paths[:maps_path])
691
+ read_other(other_files, paths[:other_path])
692
+ read_system(system_file, paths[:other_path])
693
+ read_scripts(scripts_file, paths[:other_path])
694
+ else
695
+ write_map(maps_files, paths[:maps_path], paths[:output_path])
696
+ write_other(other_files, paths[:other_path], paths[:output_path])
697
+ write_system(system_file, paths[:other_path], paths[:output_path])
698
+ write_scripts(scripts_file, paths[:other_path], paths[:output_path])
699
+ end
700
+
701
+ puts "Done in #{(Time.now - start_time)}"
702
+ end
703
+ end