Skip to content

Instantly share code, notes, and snippets.

@sapslaj
Forked from flying-sheep/Extractor.boo
Last active August 29, 2015 14:04
Show Gist options
  • Save sapslaj/97c04c6e8ba50ab3857a to your computer and use it in GitHub Desktop.
Save sapslaj/97c04c6e8ba50ab3857a to your computer and use it in GitHub Desktop.
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()
public class ExportGame : Game
{
// Fields
private GraphicsDeviceManager gdm;
private string[] name;
private Texture2D[] texture;
// Methods
public ExportGame(string name)
{
if (name != "")
{
this.name = new string[] { name };
}
else
{
this.name = Directory.GetFiles(".", "*.xnb");
for (int i = 0; i < this.name.Length; i++)
{
this.name[i] = this.name[i].Split(new string[] { ".xnb" }, StringSplitOptions.RemoveEmptyEntries)[0];
}
}
this.gdm = new GraphicsDeviceManager(this);
}
protected override void Draw(GameTime gameTime)
{
for (int i = 0; i < this.texture.Length; i++)
{
using (Stream stream = File.Open(this.name[i] + ".png", FileMode.Create))
{
this.texture[i].SaveAsPng(stream, this.texture[i].get_Width(), this.texture[i].get_Height());
}
}
base.Draw(gameTime);
base.Exit();
}
protected override void LoadContent()
{
this.texture = new Texture2D[this.name.Length];
for (int i = 0; i < this.texture.Length; i++)
{
this.texture[i] = base.get_Content().Load<Texture2D>(this.name[i]);
}
base.LoadContent();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment