Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Created June 4, 2011 18:57
Show Gist options
  • Save flying-sheep/1008201 to your computer and use it in GitHub Desktop.
Save flying-sheep/1008201 to your computer and use it in GitHub Desktop.
Terraria Sprite Extractor
namespace WindowsGame2
import System.IO
import Microsoft.Xna.Framework
public class Extractor(Game):
private graphics as GraphicsDeviceManager
private basePath as string
private outPath as string
def constructor(basePath as string, outPath as string):
graphics = GraphicsDeviceManager(self)
self.basePath = basePath
self.outPath = outPath
super.Content.RootDirectory = basePath
override def LoadContent():
for file as string in Directory.GetFiles(Path.Combine(basePath, 'Images')):
print('Converting and saving ' + file)
if not Directory.Exists(outPath):
Directory.CreateDirectory(outPath)
filePath = Path.Combine(outPath, FileInfo(file).Name.Replace('xnb', 'png'))
if File.Exists(filePath):
File.Delete(filePath)
OFS = FileStream(filePath, FileMode.CreateNew, FileAccess.Write)
sourceImage = super.Content.Load[of Graphics.Texture2D](file.Replace('.xnb', ''))
sourceImage.SaveAsPng(OFS, sourceImage.Width, sourceImage.Height)
OFS.Flush()
OFS.Close()
System.Windows.Forms.MessageBox.Show('Done!')
self.Exit()
def Main(args as (string)):
if args.Length > 1:
outPath = args[1]
else:
outPath = Path.Combine(Directory.GetCurrentDirectory(), "Terraria Sprite Dump")
extractor = Extractor(args[0], outPath)
extractor.Run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment