Skip to content

Instantly share code, notes, and snippets.

@depili
Last active March 3, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save depili/9f1591b18923e4639204 to your computer and use it in GitHub Desktop.
Save depili/9f1591b18923e4639204 to your computer and use it in GitHub Desktop.
Improved Pillars of Eternity MobileObjects.save cleaner, use at own risk
#!/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