rvpacker-txt 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/bin/rvpacker-txt +3 -2
- data/lib/RGSS/serialize.rb +154 -55
- data/lib/RGSS.rb +1 -1
- data/rvpacker-txt.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 366c510ab91e885534a8dd5d3c7421b3b6c68f03beaad2bcc7e5e160ba05bbf8
|
|
4
|
+
data.tar.gz: 6d93ab447d98bd285d738b0e5183ffadd8c59bb0e078a8b2a42db8fc3c463153
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba4567fab07d8d079b9a5b60663c9a45ed006edba0006c48dfebf7d4bef70ad5fa5f338f7bd6ed8211530c8f69861c309d14d8f07a59b747e65d21d5227b2f12
|
|
7
|
+
data.tar.gz: cb0d9fe0cab421d58c0d6d867b6602974d5b94191b0fa421171ccf0d87ea5a93ef821838ece9f4d6990dd50542ccd0d82d566f184c2e5b66d180f6462e3f6e0a
|
data/bin/rvpacker-txt
CHANGED
|
@@ -3,6 +3,7 @@ require 'RGSS'
|
|
|
3
3
|
require 'optparse'
|
|
4
4
|
|
|
5
5
|
$logging = false
|
|
6
|
+
$shuffle = 0
|
|
6
7
|
$no = [true, true, true, true] # 0 is whether to process maps, 1 is other, 2 is system, 3 is scripts
|
|
7
8
|
|
|
8
9
|
opts = {}
|
|
@@ -35,13 +36,13 @@ OptionParser.new do |options|
|
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
options.on('-s', '--shuffle NUMBER', 'At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.') do |number|
|
|
38
|
-
|
|
39
|
+
$shuffle = number
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
options.on('-l', '--log', 'Log information while processing.') do
|
|
42
43
|
$logging = true
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
options.on_tail('-h', '--help', 'Show help message.') do
|
|
46
47
|
puts options
|
|
47
48
|
exit
|
data/lib/RGSS/serialize.rb
CHANGED
|
@@ -78,7 +78,7 @@ module RGSS
|
|
|
78
78
|
case $game_type
|
|
79
79
|
when "lisa"
|
|
80
80
|
match = parameter.scan(/^\\et\[[0-9]+\]|\\nbt/)
|
|
81
|
-
parameter = parameter.slice(match[0].length) if match
|
|
81
|
+
parameter = parameter.slice((match[0].length)..) if match
|
|
82
82
|
else
|
|
83
83
|
nil
|
|
84
84
|
end
|
|
@@ -181,7 +181,11 @@ module RGSS
|
|
|
181
181
|
|
|
182
182
|
def self.read_other(original_other_files, output_path)
|
|
183
183
|
object_array_map = Hash[original_other_files.map do |filename|
|
|
184
|
-
|
|
184
|
+
basename = File.basename(filename)
|
|
185
|
+
object = Marshal.load(File.read(filename, mode: 'rb'))
|
|
186
|
+
object = merge_other(object).slice(1..) if basename.start_with?(/Common|Troops/)
|
|
187
|
+
|
|
188
|
+
[basename, object]
|
|
185
189
|
end]
|
|
186
190
|
|
|
187
191
|
object_array_map.each do |filename, object_array|
|
|
@@ -298,43 +302,56 @@ module RGSS
|
|
|
298
302
|
mode: 'wb')
|
|
299
303
|
end
|
|
300
304
|
|
|
305
|
+
def self.shuffle_words(array)
|
|
306
|
+
array.map do |string|
|
|
307
|
+
re = /\S+/
|
|
308
|
+
words = string.scan(re)
|
|
309
|
+
words.shuffle
|
|
310
|
+
|
|
311
|
+
result = nil
|
|
312
|
+
|
|
313
|
+
(0..(words.length)).each do |i|
|
|
314
|
+
result = string.sub(string[i], words[i])
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
result
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
301
321
|
def self.extract_quoted_strings(input)
|
|
302
322
|
result = []
|
|
323
|
+
|
|
324
|
+
skip_block = false
|
|
303
325
|
in_quotes = false
|
|
304
326
|
quote_type = nil
|
|
305
327
|
buffer = []
|
|
306
328
|
|
|
307
|
-
input.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
next
|
|
311
|
-
end
|
|
329
|
+
input.each_line(chomp: true) do |line|
|
|
330
|
+
line.strip!
|
|
331
|
+
next if line[0] == '#' || line.start_with?(/(Win|Lose)|_Fanfare/)
|
|
312
332
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if char == quote_type
|
|
316
|
-
result.push(buffer.join)
|
|
317
|
-
buffer.clear
|
|
318
|
-
in_quotes = false
|
|
319
|
-
quote_type = nil
|
|
320
|
-
else
|
|
321
|
-
buffer.push(char)
|
|
322
|
-
end
|
|
323
|
-
else
|
|
324
|
-
in_quotes = true
|
|
325
|
-
quote_type = char
|
|
326
|
-
end
|
|
333
|
+
skip_block = true if line.start_with?("=begin")
|
|
334
|
+
skip_block = false if line.start_with?("=end")
|
|
327
335
|
|
|
328
|
-
|
|
329
|
-
end
|
|
336
|
+
next if skip_block
|
|
330
337
|
|
|
331
|
-
if in_quotes
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
338
|
+
buffer.push('\#') if in_quotes
|
|
339
|
+
|
|
340
|
+
line.each_char do |char|
|
|
341
|
+
if char == "'" || char == '"'
|
|
342
|
+
if !quote_type.nil? && char != quote_type
|
|
343
|
+
buffer.push(char)
|
|
335
344
|
next
|
|
336
345
|
end
|
|
337
346
|
|
|
347
|
+
quote_type = char
|
|
348
|
+
in_quotes = !in_quotes
|
|
349
|
+
result.push(buffer.join)
|
|
350
|
+
buffer.clear
|
|
351
|
+
next
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
if in_quotes
|
|
338
355
|
buffer.push(char)
|
|
339
356
|
end
|
|
340
357
|
end
|
|
@@ -346,20 +363,46 @@ module RGSS
|
|
|
346
363
|
def self.read_scripts(scripts_file_path, output_path)
|
|
347
364
|
script_entries = Marshal.load(File.read(scripts_file_path, mode: 'rb'))
|
|
348
365
|
strings = IndexedSet.new
|
|
366
|
+
codes = []
|
|
349
367
|
|
|
350
368
|
script_entries.each do |script|
|
|
351
369
|
code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
|
|
370
|
+
codes.push(code)
|
|
352
371
|
|
|
353
372
|
extract_quoted_strings(code).each do |string|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
next if string.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
373
|
+
string.strip!
|
|
374
|
+
|
|
375
|
+
next if string.empty? || string.delete(' ').empty?
|
|
376
|
+
|
|
377
|
+
# Maybe this mess will remove something that mustn't be removed, but it needs to be tested
|
|
378
|
+
next if string.start_with?(/(#|!?\$|@|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
|
|
379
|
+
string.match?(/^\d+$/) ||
|
|
380
|
+
string.match?(/^(.)\1{2,}$/) ||
|
|
381
|
+
string.match?(/^(false|true)$/) ||
|
|
382
|
+
string.match?(/^(wb|rb)$/) ||
|
|
383
|
+
string.match?(/^(?=.*\d)[A-Za-z0-9\-]+$/) ||
|
|
384
|
+
string.match?(/^[A-Z\-()\/ +'&]*$/) ||
|
|
385
|
+
string.match?(/^[a-z\-()\/ +'&]*$/) ||
|
|
386
|
+
string.match?(/^[A-Za-z]+[+-]$/) ||
|
|
387
|
+
string.match?(/^[.()+-:;\[\]^~%&!*\/→×??x%▼|]$/) ||
|
|
388
|
+
string.match?(/^Tile.*[A-Z]$/) ||
|
|
389
|
+
string.match?(/^:?%.*[ds][:%]*?$/) ||
|
|
390
|
+
string.match?(/^[a-zA-Z]+([A-Z][a-z]*)+$/) ||
|
|
391
|
+
string.match?(/\.(mp3|ogg|jpg|png|ini)$/) ||
|
|
392
|
+
string.match?(/#\{/) ||
|
|
393
|
+
string.match?(/\\(?!#)/) ||
|
|
394
|
+
string.match?(/\+?=?=/) ||
|
|
395
|
+
string.match?(/[}{_<>]/) ||
|
|
396
|
+
string.match?(/r[vx]data/) ||
|
|
397
|
+
string.match?(/\/(\d.*)?$/) ||
|
|
398
|
+
string.match?(/FILE$/) ||
|
|
399
|
+
string.match?(/No such file or directory|level \*\*|Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Player start location|Common event call has exceeded|se-|Start Pos|An error has occurred|Define it first|Process Skill|Wpn Only|Don't Wait|Clear image|Can Collapse|^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/)
|
|
400
|
+
|
|
401
|
+
strings.add(string)
|
|
360
402
|
end
|
|
361
403
|
end
|
|
362
404
|
|
|
405
|
+
File.write("#{output_path}/scripts_plain.txt", codes.join("\n"), mode: 'wb')
|
|
363
406
|
File.write("#{output_path}/scripts.txt", strings.join("\n"), mode: 'wb')
|
|
364
407
|
File.write("#{output_path}/scripts_trans.txt", "\n" * (!strings.empty? ? strings.length - 1 : 0), mode: 'wb')
|
|
365
408
|
end
|
|
@@ -434,6 +477,8 @@ module RGSS
|
|
|
434
477
|
|
|
435
478
|
page.instance_variable_set(:@list, merge_seq(list))
|
|
436
479
|
end
|
|
480
|
+
|
|
481
|
+
object.instance_variable_set(:@pages, pages)
|
|
437
482
|
else
|
|
438
483
|
list = object.instance_variable_get(:@list)
|
|
439
484
|
next unless list.is_a?(Array)
|
|
@@ -446,12 +491,15 @@ module RGSS
|
|
|
446
491
|
end
|
|
447
492
|
|
|
448
493
|
def self.get_translated(code, parameter, hashmap)
|
|
494
|
+
lisa_start = nil
|
|
495
|
+
|
|
449
496
|
case code
|
|
450
497
|
when 401, 356, 405
|
|
451
498
|
case $game_type
|
|
452
499
|
when "lisa"
|
|
453
500
|
match = parameter.scan(/^\\et\[[0-9]+\]/) || parameter.scan(/^\\nbt/)
|
|
454
|
-
|
|
501
|
+
lisa_start = match[0]
|
|
502
|
+
parameter = parameter.slice((match[0].length)..) unless match.nil?
|
|
455
503
|
else
|
|
456
504
|
nil
|
|
457
505
|
end
|
|
@@ -461,7 +509,16 @@ module RGSS
|
|
|
461
509
|
nil
|
|
462
510
|
end
|
|
463
511
|
|
|
464
|
-
|
|
512
|
+
gotten = hashmap[parameter]
|
|
513
|
+
|
|
514
|
+
case $game_type
|
|
515
|
+
when "lisa"
|
|
516
|
+
gotten = lisa_start + gotten unless lisa_start.nil?
|
|
517
|
+
else
|
|
518
|
+
nil
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
gotten
|
|
465
522
|
end
|
|
466
523
|
|
|
467
524
|
def self.get_variable_translated(variable, hashmap)
|
|
@@ -489,6 +546,16 @@ module RGSS
|
|
|
489
546
|
line.gsub('\#', "\n")
|
|
490
547
|
end
|
|
491
548
|
|
|
549
|
+
if $shuffle > 0
|
|
550
|
+
maps_translated_text.shuffle!
|
|
551
|
+
names_translated_text.shuffle!
|
|
552
|
+
|
|
553
|
+
if $shuffle == 2
|
|
554
|
+
maps_translated_text = shuffle_words(maps_translated_text)
|
|
555
|
+
names_translated_text = shuffle_words(names_translated_text)
|
|
556
|
+
end
|
|
557
|
+
end
|
|
558
|
+
|
|
492
559
|
maps_translation_map = Hash[maps_original_text.zip(maps_translated_text)].freeze
|
|
493
560
|
names_translation_map = Hash[names_original_text.zip(names_translated_text)].freeze
|
|
494
561
|
|
|
@@ -546,7 +613,7 @@ module RGSS
|
|
|
546
613
|
object_array_map = Hash[original_files.map do |filename|
|
|
547
614
|
basename = File.basename(filename)
|
|
548
615
|
object = Marshal.load(File.read(filename, mode: 'rb'))
|
|
549
|
-
object = merge_other(object)
|
|
616
|
+
object = merge_other(object).slice(1..) if basename.start_with?(/Common|Troops/)
|
|
550
617
|
|
|
551
618
|
[basename, object]
|
|
552
619
|
end]
|
|
@@ -567,18 +634,31 @@ module RGSS
|
|
|
567
634
|
line.gsub('\#', "\n")
|
|
568
635
|
end
|
|
569
636
|
|
|
637
|
+
if $shuffle > 0
|
|
638
|
+
other_translated_text.shuffle!
|
|
639
|
+
|
|
640
|
+
if $shuffle == 2
|
|
641
|
+
other_translated_text = shuffle_words(other_translated_text)
|
|
642
|
+
end
|
|
643
|
+
end
|
|
644
|
+
|
|
570
645
|
other_translation_map = Hash[other_original_text.zip(other_translated_text)]
|
|
571
646
|
|
|
572
647
|
if !filename.start_with?(/Common|Troops/)
|
|
573
648
|
object_array.each do |object|
|
|
574
649
|
next if object.nil?
|
|
575
650
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
651
|
+
variables_symbols = %i[@name @nickname @description @note]
|
|
652
|
+
|
|
653
|
+
name = object.instance_variable_get(variables_symbols[0])
|
|
654
|
+
nickname = object.instance_variable_get(variables_symbols[1])
|
|
655
|
+
description = object.instance_variable_get(variables_symbols[2])
|
|
656
|
+
note = object.instance_variable_get(variables_symbols[3])
|
|
580
657
|
|
|
581
|
-
[[
|
|
658
|
+
[[variables_symbols[0], name],
|
|
659
|
+
[variables_symbols[1], nickname],
|
|
660
|
+
[variables_symbols[2], description],
|
|
661
|
+
[variables_symbols[3], note]].each do |symbol, variable|
|
|
582
662
|
if variable.is_a?(String) && !variable.empty?
|
|
583
663
|
translated = get_variable_translated(variable, other_translation_map)
|
|
584
664
|
object.instance_variable_set(symbol, variable) unless translated.nil?
|
|
@@ -634,6 +714,14 @@ module RGSS
|
|
|
634
714
|
system_original_text = File.read("#{other_path}/system.txt").split("\n")
|
|
635
715
|
system_translated_text = File.read("#{other_path}/system_trans.txt").split("\n")
|
|
636
716
|
|
|
717
|
+
if $shuffle > 0
|
|
718
|
+
system_translated_text.shuffle!
|
|
719
|
+
|
|
720
|
+
if $shuffle == 2
|
|
721
|
+
system_translated_text = shuffle_words(system_translated_text)
|
|
722
|
+
end
|
|
723
|
+
end
|
|
724
|
+
|
|
637
725
|
system_translation_map = Hash[system_original_text.zip(system_translated_text)]
|
|
638
726
|
|
|
639
727
|
symbols = %i[@elements @skill_types @weapon_types @armor_types]
|
|
@@ -684,19 +772,30 @@ module RGSS
|
|
|
684
772
|
|
|
685
773
|
puts "Written #{basename}" if $logging
|
|
686
774
|
|
|
687
|
-
File.write("#{output_path}
|
|
775
|
+
File.write("#{output_path}/ #{basename}", Marshal.dump(object), mode: 'wb')
|
|
688
776
|
end
|
|
689
777
|
|
|
690
778
|
def self.write_scripts(scripts_file, other_path, output_path)
|
|
691
779
|
script_entries = Marshal.load(File.read(scripts_file, mode: 'rb'))
|
|
692
|
-
|
|
693
|
-
|
|
780
|
+
original_strings = File.read("#{other_path}/scripts.txt", mode: 'rb')
|
|
781
|
+
.force_encoding('UTF-8')
|
|
782
|
+
.split("\n")
|
|
783
|
+
.map { |line| line.gsub('\#', "\r\n") }
|
|
694
784
|
|
|
695
|
-
|
|
785
|
+
translation_strings = File.read("#{other_path}/scripts_trans.txt", mode: 'rb')
|
|
786
|
+
.force_encoding('UTF-8')
|
|
787
|
+
.split("\n")
|
|
788
|
+
.map { |line| line.gsub('\#', "\r\n") }
|
|
696
789
|
|
|
697
|
-
|
|
790
|
+
# Shuffle can possibly break the game in scripts, so no shuffling
|
|
791
|
+
|
|
792
|
+
script_entries.each do |script|
|
|
698
793
|
code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
|
|
699
|
-
|
|
794
|
+
|
|
795
|
+
original_strings.zip(translation_strings).each do |original, translated|
|
|
796
|
+
code.gsub!(original, translated) unless translated.nil?
|
|
797
|
+
end
|
|
798
|
+
|
|
700
799
|
script[2] = Zlib::Deflate.deflate(code, Zlib::BEST_COMPRESSION)
|
|
701
800
|
end
|
|
702
801
|
|
|
@@ -747,15 +846,15 @@ module RGSS
|
|
|
747
846
|
end
|
|
748
847
|
|
|
749
848
|
if action == 'read'
|
|
750
|
-
read_map(maps_files, paths[:maps_path])
|
|
751
|
-
read_other(other_files, paths[:other_path])
|
|
752
|
-
read_system(system_file, paths[:other_path])
|
|
753
|
-
read_scripts(scripts_file, paths[:other_path])
|
|
849
|
+
read_map(maps_files, paths[:maps_path]) if $no[0]
|
|
850
|
+
read_other(other_files, paths[:other_path]) if $no[1]
|
|
851
|
+
read_system(system_file, paths[:other_path]) if $no[2]
|
|
852
|
+
read_scripts(scripts_file, paths[:other_path]) if $no[3]
|
|
754
853
|
else
|
|
755
|
-
write_map(maps_files, paths[:maps_path], paths[:output_path])
|
|
756
|
-
write_other(other_files, paths[:other_path], paths[:output_path])
|
|
757
|
-
write_system(system_file, paths[:other_path], paths[:output_path])
|
|
758
|
-
write_scripts(scripts_file, paths[:other_path], paths[:output_path])
|
|
854
|
+
write_map(maps_files, paths[:maps_path], paths[:output_path]) if $no[0]
|
|
855
|
+
write_other(other_files, paths[:other_path], paths[:output_path]) if $no[1]
|
|
856
|
+
write_system(system_file, paths[:other_path], paths[:output_path]) if $no[2]
|
|
857
|
+
write_scripts(scripts_file, paths[:other_path], paths[:output_path]) if $no[3]
|
|
759
858
|
end
|
|
760
859
|
|
|
761
860
|
puts "Done in #{(Time.now - start_time)}"
|
data/lib/RGSS.rb
CHANGED
|
@@ -234,7 +234,7 @@ module RGSS
|
|
|
234
234
|
|
|
235
235
|
# Game_Interpreter is marshalled differently in VX Ace
|
|
236
236
|
if version == :ace
|
|
237
|
-
reset_method(Game_Interpreter, :marshal_dump, -> {
|
|
237
|
+
reset_method(Game_Interpreter, :marshal_dump, -> { @data })
|
|
238
238
|
reset_method(
|
|
239
239
|
Game_Interpreter,
|
|
240
240
|
:marshal_load,
|
data/rvpacker-txt.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |spec|
|
|
2
2
|
spec.name = 'rvpacker-txt'
|
|
3
|
-
spec.version = '1.2.
|
|
3
|
+
spec.version = '1.2.1'
|
|
4
4
|
spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
|
|
5
5
|
spec.email = ['savannstm@gmail.com']
|
|
6
6
|
spec.summary = 'Reads or writes RPG Maker XP/VX/VXAce game text to .txt files'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rvpacker-txt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Howard Jeng
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date: 2024-07-
|
|
15
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: bundler
|