rvpacker-txt 1.11.0 → 1.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0be6dfc912a9d15dd4be7c37ecee0c316d650ca10f89eb99af19d5baf38addf2
4
- data.tar.gz: a0ed09eac3d11c36db6d9014e4c0bc6ffa2408ac8c4a78f55fdfbb08285b759a
3
+ metadata.gz: dc893f5cf25ad608e961d2b85408d1acaedaed3e508eaf74688bc0814f4a740c
4
+ data.tar.gz: 8c157c1d2446add716a05615e1f1d10dd758bcbb30feba4938a2420b350e892d
5
5
  SHA512:
6
- metadata.gz: bfc00222eff1dc676c73e62bc9048a89a4ea01fdce63eda1e7373a8d4f5a4d9975418111844704127cae24f2d01848d8486ba544f8f2de409346801f9563325c
7
- data.tar.gz: 473d0707b8359f54dd49ed665addf7cbfedf4a80ccadfaf6f7d997db9e4f691ae05a4882187a5dad3c8a6dc37231c11efb6e997a573bd89a70bc3f366f6e8695
6
+ metadata.gz: 3dd75b346fa21bcbc16b15c7e081b7fbd72a97796afac4343fc43c656b9d84ff504cdfc51962a771e4a54a9a17c29134a0e23fc3e158cab245c8226935c23035
7
+ data.tar.gz: 5fe5adf14cc73bd8681c61e16186a4652e22223581265784b207553ecc592252b574b15881f0f6964074c90fdd45b58a455ccb10469932248477ef79a91c07e5
data/lib/classes.rb CHANGED
@@ -75,43 +75,6 @@ class Rect
75
75
  end
76
76
  end
77
77
 
78
- # Fuck using an array with set, that's just straight dumb and not efficient
79
- class IndexSet
80
- def initialize
81
- @hash = Hash.new
82
- end
83
-
84
- def add(item)
85
- return if @hash.include?(item)
86
- @hash[item] = @hash.size
87
- @hash
88
- end
89
-
90
- def include?(item)
91
- @hash.include?(item)
92
- end
93
-
94
- def each(&block)
95
- @hash.each_key(&block)
96
- end
97
-
98
- def to_a
99
- @hash.dup
100
- end
101
-
102
- def join(delimiter = '')
103
- @hash.keys.join(delimiter)
104
- end
105
-
106
- def length
107
- @hash.size
108
- end
109
-
110
- def empty?
111
- @hash.empty?
112
- end
113
- end
114
-
115
78
  class Hash
116
79
  def insert_at_index(index, key, value)
117
80
  return self[key] = value if index >= size
data/lib/extensions.rb CHANGED
@@ -127,110 +127,79 @@ def self.shuffle_words(array)
127
127
  end
128
128
  end
129
129
 
130
- # @param [String] string A parsed scripts code string, containing raw Ruby code
131
- # @param [Symbol] mode Mode to extract quoted strings
132
- # @return [IndexSet<String>] Set of extracted strings
133
- def extract_quoted_strings(string, mode)
134
- if mode == :read
135
- result = IndexSet.new
136
-
137
- skip_block = false
138
- in_quotes = false
139
- quote_type = nil
140
- buffer = []
141
-
142
- string.each_line do |line|
143
- stripped = line.strip
144
-
145
- next if stripped[0] == '#' ||
146
- (!in_quotes && !stripped.match?(/["']/)) ||
147
- stripped.start_with?(/(Win|Lose)|_Fanfare/) ||
148
- stripped.match?(/eval\(/)
149
-
150
- skip_block = true if stripped.start_with?('=begin')
151
- skip_block = false if stripped.start_with?('=end')
152
-
153
- next if skip_block
154
-
155
- line.each_char do |char|
156
- if %w[' "].include?(char)
157
- unless quote_type.nil? || char == quote_type
158
- buffer.push(char)
159
- next
160
- end
161
-
162
- quote_type = char
163
- in_quotes = !in_quotes
164
- result.add(buffer.join)
165
- buffer.clear
166
- next
167
- end
168
-
169
- next unless in_quotes
130
+ def escaped?(line, index)
131
+ backslash_count = 0
170
132
 
171
- if char == "\r"
172
- next
173
- elsif char == "\n"
174
- buffer.push('\#')
175
- next
176
- end
177
-
178
- buffer.push(char)
179
- end
180
- end
181
-
182
- result
183
- else
184
- strings_array = []
185
- indices_array = []
186
-
187
- skip_block = false
188
- in_quotes = false
189
- quote_type = nil
190
- buffer = []
133
+ (0..index).reverse_each do |i|
134
+ break if line[i] != '\\'
135
+ backslash_count += 1
136
+ end
191
137
 
192
- current_string_index = 0
193
- string.each_line do |line|
194
- stripped = line.strip
138
+ backslash_count.even?
139
+ end
195
140
 
196
- if stripped[0] == '#' || stripped.start_with?(/(Win|Lose)|_Fanfare/)
197
- current_string_index += line.length
141
+ # @param [String] ruby_code
142
+ def extract_strings(ruby_code, mode = false)
143
+ strings = mode ? [] : Set.new
144
+ indices = []
145
+ inside_string = false
146
+ inside_multiline_comment = false
147
+ string_start_index = 0
148
+ current_quote_type = ''
149
+
150
+ global_index = 0
151
+ ruby_code.each_line do |line|
152
+ stripped = line.strip
153
+
154
+ unless inside_string
155
+ if stripped[0] == '#'
156
+ global_index += line.length
198
157
  next
199
158
  end
200
159
 
201
- skip_block = true if stripped.start_with?('=begin')
202
- skip_block = false if stripped.start_with?('=end')
203
-
204
- if skip_block
205
- current_string_index += line.length
206
- next
160
+ if stripped.start_with?('=begin')
161
+ inside_multiline_comment = true
162
+ elsif stripped.start_with?('=end')
163
+ inside_multiline_comment = false
207
164
  end
165
+ end
208
166
 
209
- buffer.push('\#') if in_quotes
210
-
211
- line.each_char.each_with_index do |char, index|
212
- if %w[' "].include?(char)
213
- unless quote_type.nil? || char == quote_type
214
- buffer.push(char)
215
- next
216
- end
167
+ if inside_multiline_comment
168
+ global_index += line.length
169
+ next
170
+ end
217
171
 
218
- quote_type = char
219
- in_quotes = !in_quotes
172
+ i = 0
173
+ while i < line.length
174
+ char = line[i]
220
175
 
221
- strings_array.push(buffer.join)
222
- indices_array.push(current_string_index + index)
176
+ if !inside_string && char == '#'
177
+ break
178
+ end
223
179
 
224
- buffer.clear
225
- next
180
+ if !inside_string && ['"', "'"].include?(char)
181
+ inside_string = true
182
+ string_start_index = global_index + i
183
+ current_quote_type = char
184
+ elsif inside_string && char == current_quote_type && escaped?(line, i - 1)
185
+ extracted_string = ruby_code[string_start_index + 1...global_index + i].gsub(/\r?\n/, '\#')
186
+
187
+ if mode
188
+ strings << extracted_string
189
+ indices << string_start_index + 1
190
+ else
191
+ strings.add(extracted_string)
226
192
  end
227
193
 
228
- buffer.push(char) if in_quotes
194
+ inside_string = false
195
+ current_quote_type = ''
229
196
  end
230
197
 
231
- current_string_index += line.length
198
+ i += 1
232
199
  end
233
200
 
234
- [strings_array, indices_array]
201
+ global_index += line.length
235
202
  end
236
- end
203
+
204
+ mode ? [strings, indices] : strings.to_a
205
+ end
data/lib/read.rb CHANGED
@@ -92,8 +92,8 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
92
92
 
93
93
  maps_object_map = Hash[maps_files_paths.map { |f| [File.basename(f), Marshal.load(File.binread(f))] }]
94
94
 
95
- maps_lines = IndexSet.new
96
- names_lines = IndexSet.new
95
+ maps_lines = Set.new
96
+ names_lines = Set.new
97
97
 
98
98
  maps_translation_map = nil
99
99
  names_translation_map = nil
@@ -161,9 +161,10 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
161
161
 
162
162
  maps_lines.add(parsed)
163
163
  end
164
+
165
+ line.clear
164
166
  end
165
167
 
166
- line.clear
167
168
  in_sequence = false
168
169
  end
169
170
 
@@ -262,7 +263,7 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
262
263
  next
263
264
  end
264
265
 
265
- other_lines = IndexSet.new
266
+ other_lines = Set.new
266
267
  other_translation_map = nil
267
268
 
268
269
  if processing_mode == :append
@@ -339,9 +340,10 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
339
340
 
340
341
  other_lines.add(parsed)
341
342
  end
343
+
344
+ line.clear
342
345
  end
343
346
 
344
- line.clear
345
347
  in_sequence = false
346
348
  end
347
349
 
@@ -449,7 +451,7 @@ def self.read_system(system_file_path, ini_file_path, output_path, romanize, log
449
451
 
450
452
  system_object = Marshal.load(File.binread(system_file_path))
451
453
 
452
- system_lines = IndexSet.new
454
+ system_lines = Set.new
453
455
  system_translation_map = nil
454
456
 
455
457
  if processing_mode == :append
@@ -575,7 +577,7 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
575
577
 
576
578
  script_entries = Marshal.load(File.binread(scripts_file_path))
577
579
 
578
- scripts_lines = IndexSet.new
580
+ scripts_lines = Set.new
579
581
  scripts_translation_map = nil
580
582
 
581
583
  if processing_mode == :append
@@ -593,8 +595,6 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
593
595
  # This code was fun before `that` game used Windows-1252 degree symbol
594
596
  script_entries.each do |script|
595
597
  code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
596
- # we're fucking cloning because of encoding issue
597
- codes_content.push(code.clone)
598
598
 
599
599
  # I figured how String#encode works - now everything is good
600
600
  unless code.valid_encoding?
@@ -610,62 +610,35 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
610
610
  end
611
611
  end
612
612
 
613
- extract_quoted_strings(code, :read).each do |string|
614
- # Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
615
- string = string.strip.delete(' ')
613
+ codes_content.push(code)
614
+ end
615
+
616
+ extracted = extract_strings(codes_content.join)
616
617
 
617
- next if string.empty?
618
+ extracted.each do |string|
619
+ # Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
620
+ string = string.gsub(' ', ' ').strip
618
621
 
619
- # Maybe this mess will remove something that mustn't be removed, but it needs to be tested
620
- next if string.start_with?(/([#!?$@]|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
621
- string.match?(/^[^\p{L}]+$/) ||
622
- string.match?(/^\d+$/) ||
623
- string.match?(/%.*(\d|\+|\*)d\]?:?$/) ||
624
- string.match?(/^\[((ON|OFF)|P[EMRT])\]$/) ||
625
- string.match?(/^\[\]$/) ||
626
- string.match?(/^(.)\1{2,}$/) ||
627
- string.match?(/^(false|true)$/) ||
628
- string.match?(/^[wr]b$/) ||
629
- string.match?(/^(?=.*\d)[A-Za-z0-9-]+$/) ||
630
- string.match?(/^[a-z\-()\/ +'&]*$/) ||
631
- string.match?(/^[A-Za-z]+[+-]$/) ||
632
- string.match?(STRING_IS_ONLY_SYMBOLS_RE) ||
633
- string.match?(/^Tile.*[A-Z]$/) ||
634
- string.match?(/^[a-zA-Z][a-z]+([A-Z][a-z]*)+$/) ||
635
- string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
636
- string.match?(/^(?=.*%d)(?=.*%m)(?=.*%Y).*$/) ||
637
- string.match?(/^\\\\ALPHAC/) ||
638
- string.match?(/^[A-Z]{,3}-[A-Z][A-Za-z]+/) ||
639
- string.match?(/\.(mp3|ogg|jpg|png|ini|txt)$/i) ||
640
- string.match?(/\/(\d.*)?$/) ||
641
- string.match?(/FILE$/) ||
642
- string.match?(/#\{/) ||
643
- string.match?(/(?<!\\)\\(?![\\G#])/) ||
644
- string.match?(/\+?=?=/) ||
645
- string.match?(/[}{_<>]/) ||
646
- string.match?(/r[vx]data/) ||
647
- string.match?(/No such file or directory/) ||
648
- string.match?(/level \*\*/) ||
649
- string.match?(/Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Times New Roman/) ||
650
- string.match?(/Player start location/) ||
651
- string.match?(/Common event call has exceeded/) ||
652
- string.match?(/se-/) ||
653
- string.match?(/Start Pos/) ||
654
- string.match?(/An error has occurred/) ||
655
- string.match?(/Define it first/) ||
656
- string.match?(/Process Skill/) ||
657
- string.match?(/Wpn Only/) ||
658
- string.match?(/Don't Wait/) ||
659
- string.match?(/Clear image/) ||
660
- string.match?(/Can Collapse/)
622
+ next if string.empty?
661
623
 
662
- string = romanize_string(string) if romanize
624
+ next if string.match?(/(Graphics|Data|Audio|Movies|System)\/.*\/?/) ||
625
+ string.match?(/r[xv]data2?$/) ||
626
+ string.match?(STRING_IS_ONLY_SYMBOLS_RE) ||
627
+ string.match?(/@window/) ||
628
+ string.match?(/\$game/) ||
629
+ string.match?(/_/) ||
630
+ string.match?(/^\\e/) ||
631
+ string.match?(/.*\(/) ||
632
+ string.match?(/^([d\d\p{P}+-]*|[d\p{P}+-]*)$/) ||
633
+ string.match?(/ALPHAC/) ||
634
+ string.match?(/^(Actor<id>|ExtraDropItem|EquipLearnSkill|GameOver|Iconset|Window|true|false|MActor%d|w[rb]|\\f|\\n|\[[A-Z]*\])$/)
663
635
 
664
- scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_mode == :append &&
665
- !scripts_translation_map.include?(string)
636
+ string = romanize_string(string) if romanize
666
637
 
667
- scripts_lines.add(string)
668
- end
638
+ scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_mode == :append &&
639
+ !scripts_translation_map.include?(string)
640
+
641
+ scripts_lines.add(string)
669
642
  end
670
643
 
671
644
  puts "Parsed #{scripts_filename}" if logging
data/lib/write.rb CHANGED
@@ -164,7 +164,7 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
164
164
  end
165
165
 
166
166
  if split_length > line_length
167
- list[item_indices.last].parameters[0] = split[line_length..].join("\n")
167
+ list[item_indices.last].parameters[0] = split[line_length - 1..].join("\n")
168
168
  end
169
169
  end
170
170
  end
@@ -335,7 +335,7 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
335
335
  end
336
336
 
337
337
  if split_length > line_length
338
- list[item_indices.last].parameters[0] = split[line_length..].join("\n")
338
+ list[item_indices.last].parameters[0] = split[line_length - 1..].join("\n")
339
339
  end
340
340
  end
341
341
  end
@@ -536,15 +536,10 @@ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, log
536
536
 
537
537
  scripts_translation_map = Hash[scripts_original_text.zip(scripts_translated_text)]
538
538
 
539
- # Shuffle can possibly break the game in scripts, so no shuffling
540
- codes = []
541
-
542
- # This code was fun before `that` game used Windows-1252 degree symbol
543
539
  script_entries.each do |script|
544
540
  code = Zlib::Inflate.inflate(script[2])
545
541
  code.force_encoding('UTF-8')
546
542
 
547
- # I figured how String#encode works - now everything is good
548
543
  unless code.valid_encoding?
549
544
  [Encoding::UTF_8, Encoding::WINDOWS_1252, Encoding::SHIFT_JIS].each do |encoding|
550
545
  encoded = code.encode(code.encoding, encoding)
@@ -559,23 +554,21 @@ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, log
559
554
  end
560
555
 
561
556
  # this shit finally works and requires NO further changes
562
- string_array, index_array = extract_quoted_strings(code, :write)
557
+ string_array, index_array = extract_strings(code, true)
563
558
 
564
559
  string_array.zip(index_array).reverse_each do |string, index|
565
- string = string.strip.delete(' ')
560
+ string = string.gsub(' ', '').strip
566
561
  next if string.empty? || !scripts_translation_map.include?(string)
567
562
 
568
563
  string = romanize_string(string) if romanize
569
564
 
570
565
  gotten = scripts_translation_map[string]
571
- code[index - string.length, string.length] = gotten unless gotten.nil? || gotten.empty?
566
+ code[index, string.length] = gotten unless gotten.nil? || gotten.empty?
572
567
  end
573
568
 
574
- codes.push(code)
575
569
  script[2] = Zlib::Deflate.deflate(code, Zlib::BEST_COMPRESSION)
576
570
  end
577
571
 
578
- # File.binwrite(File.join(output_path, 'scripts_plain.txt'), codes.join("\n")) - debug line
579
572
  File.binwrite(File.join(output_path, scripts_basename), Marshal.dump(script_entries))
580
573
  puts "Written #{scripts_basename}" if logging
581
574
  end
data/rvpacker-txt.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rvpacker-txt'
5
- spec.version = '1.11.0'
5
+ spec.version = '1.12.0'
6
6
  spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
7
7
  spec.email = ['savannstm@gmail.com']
8
8
  spec.summary = 'Reads RPG Maker XP/VX/VXAce game text to .txt files and writes them to their initial form.'
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.11.0
4
+ version: 1.12.0
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-28 00:00:00.000000000 Z
15
+ date: 2024-08-02 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description:
18
18
  email: