Code:
namespace NImage
{
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
[DesignerGenerated]
public class Form1 : Form
{
[AccessedThroughProperty("BinaryToolStripMenuItem")]
private ToolStripMenuItem _BinaryToolStripMenuItem;
[AccessedThroughProperty("FileToolStripMenuItem")]
private ToolStripMenuItem _FileToolStripMenuItem;
[AccessedThroughProperty("ImageToolStripMenuItem")]
private ToolStripMenuItem _ImageToolStripMenuItem;
[AccessedThroughProperty("LOAD_BTN")]
private ToolStripMenuItem _LOAD_BTN;
[AccessedThroughProperty("MenuStrip1")]
private MenuStrip _MenuStrip1;
[AccessedThroughProperty("OPEN_BIN_BTN")]
private ToolStripMenuItem _OPEN_BIN_BTN;
[AccessedThroughProperty("picture")]
private PictureBox _picture;
[AccessedThroughProperty("SAVE_ALL_BTN")]
private ToolStripMenuItem _SAVE_ALL_BTN;
[AccessedThroughProperty("SAVE_BIN_BTN")]
private ToolStripMenuItem _SAVE_BIN_BTN;
[AccessedThroughProperty("SAVE_BTN")]
private ToolStripMenuItem _SAVE_BTN;
[AccessedThroughProperty("sList")]
private ListBox _sList;
private IContainer components;
private string fName;
private List<SpriteInfo> Sprites;
private string WTF = "If you're reading this you're a fuckin' bastard <3";
public Form1()
{
this.InitializeComponent();
}
public ushort ByteJoin(byte[] byt)
{
return BitConverter.ToUInt16(byt, 0);
}
public void Decrypt()
{
this.sList.Items.Clear();
BinaryReader reader = new BinaryReader(File.Open(this.fName, FileMode.Open));
this.Sprites = new List<SpriteInfo>();
byte num = reader.ReadByte();
int num6 = num - 1;
for (int i = 0; i <= num6; i++)
{
SpriteInfo item = new SpriteInfo();
item.Width = reader.ReadUInt16();
item.Height = reader.ReadUInt16();
item.unk_3 = reader.ReadUInt16();
item.unk_4 = reader.ReadUInt16();
item.OffSet = reader.ReadUInt32();
this.Sprites.Add(item);
}
int num7 = this.Sprites.ToArray().Length - 1;
for (int j = 0; j <= num7; j++)
{
SpriteInfo info6 = this.Sprites[j];
reader.BaseStream.Seek((long) info6.OffSet, SeekOrigin.Begin);
info6 = this.Sprites[j];
SpriteInfo info5 = this.Sprites[j];
Bitmap bitmap = new Bitmap(info6.Width, info5.Height);
info6 = this.Sprites[j];
int num8 = info6.Height - 1;
for (int k = 0; k <= num8; k++)
{
info5 = this.Sprites[j];
int num9 = info5.Width - 1;
for (int m = 0; m <= num9; m++)
{
bitmap.SetPixel(m, k, this.RGB4A_to_RGB888(reader.ReadUInt16()));
}
}
SpriteInfo info = this.Sprites[j];
info.Img = bitmap;
this.Sprites[j] = info;
this.sList.Items.Add(j + 1);
}
this.sList.SelectedIndex = 0;
this.Text = "NImage [" + Path.GetFileName(this.fName) + "]";
reader.Close();
}
public void Decrypt_32GBS()
{
try
{
BinaryReader reader = new BinaryReader(File.Open(this.fName, FileMode.Open));
short width = reader.ReadInt16();
short num2 = (short) Math.Round((double) (((double) width) / 4.0));
short height = reader.ReadInt16();
if ((width == 0) & (height == 0))
{
this.Text = "NImage [Failed - " + Path.GetFileName(this.fName) + "]";
}
else
{
short x = 0;
short y = 0;
Bitmap bitmap = new Bitmap(width, height);
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
short num;
byte blue = reader.ReadByte();
byte green = reader.ReadByte();
byte red = reader.ReadByte();
byte alpha = reader.ReadByte();
bitmap.SetPixel(x, y, Color.FromArgb(alpha, red, green, blue));
x = (short) (x + 1);
if (x == ((short) (num + num2)))
{
x = num;
y = (short) (y + 1);
}
if (y == height)
{
y = 0;
num = (short) (num + num2);
x = num;
}
}
this.picture.Image = bitmap;
this.Text = "NImage [" + Path.GetFileName(this.fName) + "]";
reader.Close();
}
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Exception exception = exception1;
this.Text = "NImage [Failed - " + Path.GetFileName(this.fName) + "]";
ProjectData.ClearProjectError();
}
}
[DebuggerNonUserCode]
protected override void Dispose(bool disposing)
{
try
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
}
finally
{
base.Dispose(disposing);
}
}
public void Encrypt()
{
SpriteInfo info5;
BinaryWriter writer = new BinaryWriter(File.Open(this.fName, FileMode.OpenOrCreate));
writer.Write((byte) this.Sprites.ToArray().Length);
writer.Seek(1 + (this.Sprites.ToArray().Length * 12), SeekOrigin.Begin);
int num6 = this.Sprites.ToArray().Length - 1;
for (int i = 0; i <= num6; i++)
{
int position = (int) writer.BaseStream.Position;
SpriteInfo info = this.Sprites[i];
Bitmap img = (Bitmap) info.Img;
int num7 = img.Height - 1;
for (int k = 0; k <= num7; k++)
{
int num8 = img.Width - 1;
for (int m = 0; m <= num8; m++)
{
writer.Write(this.RGB888_to_RGB4A(img.GetPixel(m, k)));
}
}
SpriteInfo info3 = new SpriteInfo {
Width = (ushort) img.Width,
Height = (ushort) img.Height
};
SpriteInfo info4 = this.Sprites[i];
info3.unk_3 = info4.unk_3;
info5 = this.Sprites[i];
info3.unk_4 = info5.unk_4;
info3.OffSet = (uint) position;
info3.Img = img;
this.Sprites[i] = info3;
}
writer.Seek(1, SeekOrigin.Begin);
int num9 = this.Sprites.ToArray().Length - 1;
for (int j = 0; j <= num9; j++)
{
info5 = this.Sprites[j];
writer.Write(info5.Width);
info5 = this.Sprites[j];
writer.Write(info5.Height);
info5 = this.Sprites[j];
writer.Write(info5.unk_3);
info5 = this.Sprites[j];
writer.Write(info5.unk_4);
info5 = this.Sprites[j];
writer.Write(info5.OffSet);
}
writer.Flush();
writer.Close();
}
public void Encrypt_32GBS()
{
BinaryWriter writer = new BinaryWriter(File.Open(this.fName, FileMode.OpenOrCreate));
bool flag = false;
Bitmap image = (Bitmap) this.picture.Image;
writer.Write((short) image.Width);
short num2 = (short) Math.Round((double) (((double) image.Width) / 4.0));
writer.Write((short) image.Height);
while (!flag)
{
short num;
short num3;
short num4;
writer.Write(image.GetPixel(num3, num4).B);
writer.Write(image.GetPixel(num3, num4).G);
writer.Write(image.GetPixel(num3, num4).R);
writer.Write(image.GetPixel(num3, num4).A);
num3 = (short) (num3 + 1);
if (num3 == ((short) (num + num2)))
{
num3 = num;
num4 = (short) (num4 + 1);
}
if (num4 == image.Height)
{
num4 = 0;
num = (short) (num + num2);
num3 = num;
}
if (num3 == image.Width)
{
flag = true;
}
}
writer.Flush();
writer.Close();
Interaction.MsgBox("File Saved!", MsgBoxStyle.Information, null);
}
public byte GetColour(byte byt, bool encoding = false)
{
if (encoding)
{
return (byte) Math.Round((double) (((double) byt) / 17.0));
}
return (byte) (byt * 0x11);
}
[DebuggerStepThrough]
private void InitializeComponent()
{
ComponentResourceManager manager = new ComponentResourceManager(typeof(Form1));
this.MenuStrip1 = new MenuStrip();
this.FileToolStripMenuItem = new ToolStripMenuItem();
this.BinaryToolStripMenuItem = new ToolStripMenuItem();
this.OPEN_BIN_BTN = new ToolStripMenuItem();
this.ImageToolStripMenuItem = new ToolStripMenuItem();
this.SAVE_BTN = new ToolStripMenuItem();
this.SAVE_ALL_BTN = new ToolStripMenuItem();
this.LOAD_BTN = new ToolStripMenuItem();
this.picture = new PictureBox();
this.sList = new ListBox();
this.SAVE_BIN_BTN = new ToolStripMenuItem();
this.MenuStrip1.SuspendLayout();
((ISupportInitialize) this.picture).BeginInit();
this.SuspendLayout();
this.MenuStrip1.Items.AddRange(new ToolStripItem[] { this.FileToolStripMenuItem });
Point point2 = new Point(0, 0);
this.MenuStrip1.Location = point2;
this.MenuStrip1.Name = "MenuStrip1";
Size size2 = new Size(0x317, 0x18);
this.MenuStrip1.Size = size2;
this.MenuStrip1.TabIndex = 0;
this.MenuStrip1.Text = "MenuStrip1";
this.FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.BinaryToolStripMenuItem, this.ImageToolStripMenuItem });
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
size2 = new Size(0x25, 20);
this.FileToolStripMenuItem.Size = size2;
this.FileToolStripMenuItem.Text = "File";
this.BinaryToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.OPEN_BIN_BTN, this.SAVE_BIN_BTN });
this.BinaryToolStripMenuItem.Name = "BinaryToolStripMenuItem";
size2 = new Size(0x98, 0x16);
this.BinaryToolStripMenuItem.Size = size2;
this.BinaryToolStripMenuItem.Text = "Binary";
this.OPEN_BIN_BTN.Name = "OPEN_BIN_BTN";
size2 = new Size(0x98, 0x16);
this.OPEN_BIN_BTN.Size = size2;
this.OPEN_BIN_BTN.Text = "Open";
this.ImageToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.SAVE_BTN, this.SAVE_ALL_BTN, this.LOAD_BTN });
this.ImageToolStripMenuItem.Name = "ImageToolStripMenuItem";
size2 = new Size(0x98, 0x16);
this.ImageToolStripMenuItem.Size = size2;
this.ImageToolStripMenuItem.Text = "Image";
this.SAVE_BTN.Name = "SAVE_BTN";
size2 = new Size(0x98, 0x16);
this.SAVE_BTN.Size = size2;
this.SAVE_BTN.Text = "Save";
this.SAVE_ALL_BTN.Name = "SAVE_ALL_BTN";
size2 = new Size(0x98, 0x16);
this.SAVE_ALL_BTN.Size = size2;
this.SAVE_ALL_BTN.Text = "Save all";
this.LOAD_BTN.Name = "LOAD_BTN";
size2 = new Size(0x98, 0x16);
this.LOAD_BTN.Size = size2;
this.LOAD_BTN.Text = "Load";
this.picture.Dock = DockStyle.Fill;
point2 = new Point(0xa9, 0x18);
this.picture.Location = point2;
this.picture.Name = "picture";
size2 = new Size(0x26e, 0x1c0);
this.picture.Size = size2;
this.picture.SizeMode = PictureBoxSizeMode.CenterImage;
this.picture.TabIndex = 1;
this.picture.TabStop = false;
this.sList.Dock = DockStyle.Left;
this.sList.FormattingEnabled = true;
point2 = new Point(0, 0x18);
this.sList.Location = point2;
this.sList.Name = "sList";
size2 = new Size(0xa9, 0x1c0);
this.sList.Size = size2;
this.sList.TabIndex = 2;
this.SAVE_BIN_BTN.Name = "SAVE_BIN_BTN";
size2 = new Size(0x98, 0x16);
this.SAVE_BIN_BTN.Size = size2;
this.SAVE_BIN_BTN.Text = "Save";
SizeF ef2 = new SizeF(6f, 13f);
this.AutoScaleDimensions = ef2;
this.AutoScaleMode = AutoScaleMode.Font;
this.BackColor = Color.White;
size2 = new Size(0x317, 0x1d8);
this.ClientSize = size2;
this.Controls.Add(this.picture);
this.Controls.Add(this.sList);
this.Controls.Add(this.MenuStrip1);
this.Icon = (Icon) manager.GetObject("$this.Icon");
this.MainMenuStrip = this.MenuStrip1;
this.Name = "Form1";
this.StartPosition = FormStartPosition.CenterScreen;
this.Text = "NImage";
this.MenuStrip1.ResumeLayout(false);
this.MenuStrip1.PerformLayout();
((ISupportInitialize) this.picture).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private void LOAD_BTN_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog {
Filter = "PNG File |*.png"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
SpriteInfo info = this.Sprites[this.sList.SelectedIndex];
info.Img = Image.FromFile(dialog.FileName);
info.Height = (ushort) info.Img.Height;
info.Width = (ushort) info.Img.Width;
this.Sprites[this.sList.SelectedIndex] = info;
SpriteInfo info3 = this.Sprites[this.sList.SelectedIndex];
this.picture.Image = info3.Img;
}
}
private void OPEN_BIN_BTN_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
this.fName = dialog.FileName;
this.Decrypt();
}
}
public Color RGB4A_to_RGB888(ushort clr)
{
int num = ((ushort) (clr >> 12)) & 15;
int num4 = ((ushort) (clr >> 8)) & 15;
int num3 = ((ushort) (clr >> 4)) & 15;
int num2 = clr & 15;
return Color.FromArgb(this.GetColour((byte) num, false), this.GetColour((byte) num4, false), this.GetColour((byte) num3, false), this.GetColour((byte) num2, false));
}
public ushort RGB888_to_RGB4A(Color clr)
{
byte num = (byte) (((byte) (this.GetColour(clr.A, 1) << 4)) | this.GetColour(clr.R, true));
byte num3 = (byte) (((byte) (this.GetColour(clr.G, 1) << 4)) | this.GetColour(clr.B, true));
return this.ByteJoin(new byte[] { num3, num });
}
private void SAVE_ALL_BTN_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
int num2 = this.Sprites.ToArray().Length - 1;
for (int i = 0; i <= num2; i++)
{
SpriteInfo info = this.Sprites[i];
int num3 = i + 1;
info.Img.Save(Path.Combine(dialog.SelectedPath, num3.ToString() + ".png"));
}
}
}
private void SAVE_BIN_BTN_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
this.fName = dialog.FileName;
this.Encrypt();
}
}
private void SAVE_BTN_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog {
Filter = "PNG File |*.png"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
this.picture.Image.Save(dialog.FileName, ImageFormat.Png);
}
}
private void sList_SelectedIndexChanged(object sender, EventArgs e)
{
SpriteInfo info = this.Sprites[this.sList.SelectedIndex];
this.picture.BackColor = ((Bitmap) info.Img).GetPixel(0, 0);
info = this.Sprites[this.sList.SelectedIndex];
this.picture.Image = info.Img;
}
internal virtual ToolStripMenuItem BinaryToolStripMenuItem
{
get
{
return this._BinaryToolStripMenuItem;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
this._BinaryToolStripMenuItem = value;
}
}
internal virtual ToolStripMenuItem FileToolStripMenuItem
{
get
{
return this._FileToolStripMenuItem;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
this._FileToolStripMenuItem = value;
}
}
internal virtual ToolStripMenuItem ImageToolStripMenuItem
{
get
{
return this._ImageToolStripMenuItem;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
this._ImageToolStripMenuItem = value;
}
}
internal virtual ToolStripMenuItem LOAD_BTN
{
get
{
return this._LOAD_BTN;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.LOAD_BTN_Click);
if (this._LOAD_BTN != null)
{
this._LOAD_BTN.Click -= handler;
}
this._LOAD_BTN = value;
if (this._LOAD_BTN != null)
{
this._LOAD_BTN.Click += handler;
}
}
}
internal virtual MenuStrip MenuStrip1
{
get
{
return this._MenuStrip1;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
this._MenuStrip1 = value;
}
}
internal virtual ToolStripMenuItem OPEN_BIN_BTN
{
get
{
return this._OPEN_BIN_BTN;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.OPEN_BIN_BTN_Click);
if (this._OPEN_BIN_BTN != null)
{
this._OPEN_BIN_BTN.Click -= handler;
}
this._OPEN_BIN_BTN = value;
if (this._OPEN_BIN_BTN != null)
{
this._OPEN_BIN_BTN.Click += handler;
}
}
}
internal virtual PictureBox picture
{
get
{
return this._picture;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
this._picture = value;
}
}
internal virtual ToolStripMenuItem SAVE_ALL_BTN
{
get
{
return this._SAVE_ALL_BTN;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.SAVE_ALL_BTN_Click);
if (this._SAVE_ALL_BTN != null)
{
this._SAVE_ALL_BTN.Click -= handler;
}
this._SAVE_ALL_BTN = value;
if (this._SAVE_ALL_BTN != null)
{
this._SAVE_ALL_BTN.Click += handler;
}
}
}
internal virtual ToolStripMenuItem SAVE_BIN_BTN
{
get
{
return this._SAVE_BIN_BTN;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.SAVE_BIN_BTN_Click);
if (this._SAVE_BIN_BTN != null)
{
this._SAVE_BIN_BTN.Click -= handler;
}
this._SAVE_BIN_BTN = value;
if (this._SAVE_BIN_BTN != null)
{
this._SAVE_BIN_BTN.Click += handler;
}
}
}
internal virtual ToolStripMenuItem SAVE_BTN
{
get
{
return this._SAVE_BTN;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.SAVE_BTN_Click);
if (this._SAVE_BTN != null)
{
this._SAVE_BTN.Click -= handler;
}
this._SAVE_BTN = value;
if (this._SAVE_BTN != null)
{
this._SAVE_BTN.Click += handler;
}
}
}
internal virtual ListBox sList
{
get
{
return this._sList;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
EventHandler handler = new EventHandler(this.sList_SelectedIndexChanged);
if (this._sList != null)
{
this._sList.SelectedIndexChanged -= handler;
}
this._sList = value;
if (this._sList != null)
{
this._sList.SelectedIndexChanged += handler;
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SpriteInfo
{
public ushort Width;
public ushort Height;
public ushort unk_3;
public ushort unk_4;
public uint OffSet;
public Image Img;
}
}
}