Last active
March 3, 2018 14:11
-
-
Save depili/9f1591b18923e4639204 to your computer and use it in GitHub Desktop.
Improved Pillars of Eternity MobileObjects.save cleaner, use at own risk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
file = File.open(ARGV.last, 'rb') | |
chunks = Array.new | |
# We will read until we encounter the Root string in the next chunk. Then we will roll back that root and 4 bytes | |
# before it. | |
chunk_limiter = "Root" | |
read = String.new | |
$stdout.sync = true | |
chunks_read = 0 | |
trap_chunks = 0 | |
summon_chunks = 0 | |
puts "Reading the savefile:" | |
file.each_char do |b| | |
read << b | |
if (b == "t") && (read.length > 20) && (read[-4..-1] == chunk_limiter) | |
chunks_read += 1 | |
next_chunk = read[-(chunk_limiter.size + 4)..-1] | |
chunk = read[0...-(chunk_limiter.size + 4)] | |
read = next_chunk | |
if chunk.include? "Rime_and_Frost_Trap.prefab" | |
trap_chunks += 1 | |
print "T" | |
elsif chunk.include? "_Summon.prefab" | |
summon_chunks += 1 | |
print "S" | |
else | |
print "." | |
chunks << chunk | |
end | |
end | |
end | |
puts "\nRead #{chunks_read} objects, found #{trap_chunks} traps, #{summon_chunks} summoned creatures." | |
new_file = "#{ARGV.last}.cleaned" | |
puts "Now writing remaining #{chunks.size} objects to #{new_file}:" | |
File.open(new_file, 'wb') do |f| | |
chunks.each do |chunk| | |
f.write chunk | |
print "." | |
end | |
end | |
puts "\n All done, good luck!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment