Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding support for Shadow 0.50.
  • Loading branch information
MainMemory committed Feb 27, 2016
1 parent bd9aac5 commit a05bc53
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 34 deletions.
14 changes: 9 additions & 5 deletions HeroesONE/Program.cs
Expand Up @@ -10,7 +10,8 @@ static class Program
new LongOpt("help", Argument.No, null, 'h'),
new LongOpt("pack", Argument.No, null, 'p'),
new LongOpt("unpack", Argument.No, null, 'u'),
new LongOpt("shadow", Argument.No, null, 's')
new LongOpt("shadow060", Argument.No, null, '6'),
new LongOpt("shadow050", Argument.No, null, '5')
};

/// <summary>
Expand All @@ -20,7 +21,7 @@ static void Main(string[] args)
{
Getopt getopt = new Getopt("HeroesONE", args, Getopt.digest(opts), opts);
Mode? mode = null;
bool shadow = false;
ArchiveType type = ArchiveType.Heroes;
int opt = getopt.getopt();
while (opt != -1)
{
Expand All @@ -35,8 +36,11 @@ static void Main(string[] args)
case 'u':
mode = Mode.Unpack;
break;
case 's':
shadow = true;
case '6':
type = ArchiveType.Shadow060;
break;
case '5':
type = ArchiveType.Shadow050;
break;
}
opt = getopt.getopt();
Expand Down Expand Up @@ -71,7 +75,7 @@ static void Main(string[] args)
HeroesONEFile ar = new HeroesONEFile();
for (int i = getopt.Optind; i < args.Length - 1; i++)
ar.Files.Add(new HeroesONEFile.File(args[i]));
ar.Save(fn, shadow);
ar.Save(fn, type);
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
break;
Expand Down
6 changes: 4 additions & 2 deletions HeroesONE/Resources/HelpText.txt
Expand Up @@ -4,5 +4,7 @@ Arguments:
-u, --unpack filename [destination] Extracts filename to destination, or the
current directory.
-p, --pack filenames destination Packs files into the destination archive.
-s, --shadow Packs the archive with the "Shadow the
Hedgehog" format.
-6, --shadow060 Packs the archive with the "Shadow the
Hedgehog" 0.60 format.
-5, --shadow050 Packs the archive with the "Shadow the
Hedgehog" 0.50 format.
35 changes: 32 additions & 3 deletions HeroesONEEdit/MainForm.cs
Expand Up @@ -41,7 +41,18 @@ private void LoadFile(string filename)
return;
}
#endif
shadowModeToolStripMenuItem.Checked = file.IsShadow;
switch (file.Type)
{
case ArchiveType.Heroes:
heroesToolStripMenuItem_Click(this, EventArgs.Empty);
break;
case ArchiveType.Shadow060:
shadow060ToolStripMenuItem_Click(this, EventArgs.Empty);
break;
case ArchiveType.Shadow050:
shadow050ToolStripMenuItem_Click(this, EventArgs.Empty);
break;
}
this.filename = filename;
listView1.Items.Clear();
imageList1.Images.Clear();
Expand Down Expand Up @@ -70,15 +81,15 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(filename))
saveAsToolStripMenuItem_Click(sender, e);
else
file.Save(filename, shadowModeToolStripMenuItem.Checked);
file.Save(filename, heroesToolStripMenuItem.Checked ? ArchiveType.Heroes : shadow060ToolStripMenuItem.Checked ? ArchiveType.Shadow060 : ArchiveType.Shadow050);
}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog a = new SaveFileDialog() { Filter = "ONE Files|*.one|All Files|*.*" })
if (a.ShowDialog() == DialogResult.OK)
{
file.Save(a.FileName, shadowModeToolStripMenuItem.Checked);
file.Save(a.FileName, heroesToolStripMenuItem.Checked ? ArchiveType.Heroes : shadow060ToolStripMenuItem.Checked ? ArchiveType.Shadow060 : ArchiveType.Shadow050);
this.filename = a.FileName;
}
}
Expand Down Expand Up @@ -308,5 +319,23 @@ private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}

private void heroesToolStripMenuItem_Click(object sender, EventArgs e)
{
heroesToolStripMenuItem.Checked = true;
shadow050ToolStripMenuItem.Checked = shadow060ToolStripMenuItem.Checked = false;
}

private void shadow060ToolStripMenuItem_Click(object sender, EventArgs e)
{
shadow060ToolStripMenuItem.Checked = true;
heroesToolStripMenuItem.Checked = shadow050ToolStripMenuItem.Checked = false;
}

private void shadow050ToolStripMenuItem_Click(object sender, EventArgs e)
{
shadow050ToolStripMenuItem.Checked = true;
heroesToolStripMenuItem.Checked = shadow060ToolStripMenuItem.Checked = false;
}
}
}
59 changes: 46 additions & 13 deletions HeroesONEEdit/MainForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 32 additions & 11 deletions HeroesONELib/HeroesONEFile.cs
Expand Up @@ -31,11 +31,12 @@ public File(string name, byte[] data)
}
}

public bool IsShadow { get; private set; }
public ArchiveType Type { get; private set; }
public List<File> Files { get; set; }

const int HeroesMagic = 0x1400FFFF;
const int ShadowMagic = 0x1C020037;
const int Shadow060Magic = 0x1C020037;
const int Shadow050Magic = 0x1C020020;

public HeroesONEFile()
{
Expand Down Expand Up @@ -71,21 +72,32 @@ public HeroesONEFile(string filename)
}
}
break;
case ShadowMagic:
case Shadow060Magic:
case Shadow050Magic:
{
IsShadow = true;
if (reader.ReadString(12) != "One Ver 0.60") goto default;
switch (reader.ReadString(12))
{
case "One Ver 0.60":
Type = ArchiveType.Shadow060;
break;
case "One Ver 0.50":
Type = ArchiveType.Shadow050;
break;
}
if (Type == ArchiveType.Heroes) goto default;
stream.Seek(4, SeekOrigin.Current);
int fnum = reader.ReadInt32();
stream.Seek(0x90, SeekOrigin.Current);
List<string> filenames = new List<string>(fnum);
List<int> fileaddrs = new List<int>(fnum);
for (int i = 0; i < fnum; i++)
{
filenames.Add(reader.ReadString(0x2C));
filenames.Add(reader.ReadString(Type == ArchiveType.Shadow060 ? 0x2C : 0x20));
stream.Seek(4, SeekOrigin.Current);
fileaddrs.Add(reader.ReadInt32());
stream.Seek(4, SeekOrigin.Current);
if (Type == ArchiveType.Shadow050)
stream.Seek(0xC, SeekOrigin.Current);
}
fileaddrs.Add(filesize);
for (int i = 0; i < fnum; i++)
Expand All @@ -101,15 +113,15 @@ public HeroesONEFile(string filename)
}
}

public void Save(string filename, bool shadow)
public void Save(string filename, ArchiveType type)
{
using (FileStream stream = System.IO.File.Open(filename, FileMode.Create, FileAccess.Write))
using (BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.ASCII))
{
writer.Write(0);
long fspos = stream.Position;
writer.Write(-1);
if (!shadow)
if (type == ArchiveType.Heroes)
{
byte[] filenames = new byte[256 * 64];
writer.Write(HeroesMagic);
Expand All @@ -133,8 +145,8 @@ public void Save(string filename, bool shadow)
}
else
{
writer.Write(ShadowMagic);
writer.Write("One Ver 0.60", 12);
writer.Write(type == ArchiveType.Shadow060 ? Shadow060Magic : Shadow050Magic);
writer.Write(type == ArchiveType.Shadow060 ? "One Ver 0.60" : "One Ver 0.50", 12);
writer.Write(0);
writer.Write(Files.Count);
byte[] buf = new byte[0x90];
Expand All @@ -144,11 +156,13 @@ public void Save(string filename, bool shadow)
Queue<long> addrpos = new Queue<long>(Files.Count);
foreach (File item in Files)
{
writer.Write(item.Name, 0x2C);
writer.Write(item.Name, type == ArchiveType.Shadow060 ? 0x2C : 0x20);
writer.Write(item.Data.Length);
addrpos.Enqueue(stream.Position);
writer.Write(-1);
writer.Write(1);
if (type == ArchiveType.Shadow050)
writer.Write(new byte[0xC]);
}
foreach (File item in Files)
{
Expand All @@ -164,6 +178,13 @@ public void Save(string filename, bool shadow)
}
}

public enum ArchiveType
{
Heroes,
Shadow060,
Shadow050
}

public static class Extensions
{
/// <summary>
Expand Down

0 comments on commit a05bc53

Please sign in to comment.