Skip to content

Commit

Permalink
- Fix parsing animations
Browse files Browse the repository at this point in the history
- Fix saving as different platform
  • Loading branch information
Sammi-Husky committed Mar 10, 2016
1 parent 00fe2fd commit db5ebf7
Show file tree
Hide file tree
Showing 19 changed files with 2,514 additions and 2,304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace Sm4shCommand.Classes
{
public class Command
public class ACMDCommand
{
public Command(CommandInfo info)
public ACMDCommand(ACMD_CMD_INFO info)
{
_commandInfo = info;
}
public Command() { }
public ACMDCommand() { }

public CommandInfo _commandInfo;
public ACMD_CMD_INFO _commandInfo;


public List<object> parameters = new List<object>();
Expand Down Expand Up @@ -62,7 +62,7 @@ public virtual byte[] GetArray()
}
}

public class UnknownCommand : Command
public class UnknownCommand : ACMDCommand
{
public uint ident;

Expand Down
53 changes: 26 additions & 27 deletions AnimCmd/Classes/ACMDFile.cs → AnimCmd/Classes/ACMD/ACMDFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@ namespace Sm4shCommand.Classes
{
public unsafe class ACMDFile
{
public ACMDFile() { _hashPairs = new Dictionary<uint, string>(); }
public ACMDFile(DataSource source, Endianness Endian)
public ACMDFile()
{
_eventLists = new SortedList<uint, CommandList>();
_eventLists = new SortedList<uint, ACMDScript>();
_hashPairs = new Dictionary<uint, string>();
Type = ACMDType.NONE;

}
public ACMDFile(DataSource source) : this()
{
_workingSource = source;

_actionCount = Util.GetWordUnsafe(source.Address + 0x08, Runtime.WorkingEndian);
_commandCount = Util.GetWordUnsafe(source.Address + 0x0C, Runtime.WorkingEndian);

Initialize();
for (int i = 0; i < _actionCount; i++)
{
uint _crc = (uint)Util.GetWordUnsafe(_workingSource.Address + 0x10 + (i * 8), Runtime.WorkingEndian);
int _offset = Util.GetWordUnsafe((_workingSource.Address + 0x10 + (i * 8)) + 0x04, Runtime.WorkingEndian);

EventLists.Add(_crc, ParseEventList(_crc, _offset));
}
}
public ACMDFile(string filepath) : this(new DataSource(FileMap.FromFile(filepath))) { }

private VoidPtr WorkingSource => _replSource != DataSource.Empty ? _replSource.Address : _workingSource.Address;
private DataSource _workingSource, _replSource;

Expand All @@ -31,13 +40,13 @@ public ACMDFile(DataSource source, Endianness Endian)
public int ActionCount { get { return _actionCount; } set { _actionCount = value; } }
private int _actionCount;

public ACMDType Type;
public ACMDType Type { get; set; }

/// <summary>
/// List of all CommandLists in this file.
/// </summary>
public SortedList<uint, CommandList> EventLists { get { return _eventLists; } set { _eventLists = value; } }
private SortedList<uint, CommandList> _eventLists;
public SortedList<uint, ACMDScript> EventLists { get { return _eventLists; } set { _eventLists = value; } }
private SortedList<uint, ACMDScript> _eventLists;
/// <summary>
/// Linked list containing all animation names and their CRC32 hash.
/// </summary>
Expand All @@ -51,16 +60,6 @@ public ACMDFile(DataSource source, Endianness Endian)
/// True if the file has changes.
/// </summary>
public bool Dirty => EventLists.Values.Any(cl => cl.Dirty);
private void Initialize()
{
for (int i = 0; i < _actionCount; i++)
{
uint _crc = (uint)Util.GetWordUnsafe(_workingSource.Address + 0x10 + (i * 8), Runtime.WorkingEndian);
int _offset = Util.GetWordUnsafe((_workingSource.Address + 0x10 + (i * 8)) + 0x04, Runtime.WorkingEndian);

EventLists.Add(_crc, ParseEventList(_crc, _offset));
}
}
/// <summary>
/// Applies changes.
/// </summary>
Expand Down Expand Up @@ -110,17 +109,17 @@ private void OnRebuild(VoidPtr address, int length)
}

// Write event lists at final address.
foreach (CommandList e in EventLists.Values)
foreach (ACMDScript e in EventLists.Values)
{
e.Rebuild(addr, e.Size);
addr += e.Size;
}
}
private CommandList ParseEventList(uint CRC, int Offset)
private ACMDScript ParseEventList(uint CRC, int Offset)
{
CommandList _list = new CommandList(CRC);
ACMDScript _list = new ACMDScript(CRC);

Command c;
ACMDCommand c;

VoidPtr addr = (_workingSource.Address + Offset);

Expand All @@ -129,13 +128,13 @@ private CommandList ParseEventList(uint CRC, int Offset)
{
// Try to get command definition
uint ident = (uint)Util.GetWordUnsafe(addr, Runtime.WorkingEndian);
CommandInfo info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == ident);
ACMD_CMD_INFO info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == ident);

// If a command definition exists, use that info to deserialize.
if (info != null)
{
// Get command parameters and add the command to the event list.
c = new Command(info);
c = new ACMDCommand(info);
for (int i = 0; i < info.ParamSpecifiers.Count; i++)
{
switch (info.ParamSpecifiers[i])
Expand Down Expand Up @@ -171,9 +170,9 @@ private CommandList ParseEventList(uint CRC, int Offset)
// If we hit a script_end command, add it to the the Event List and terminate looping.
if (Util.GetWordUnsafe(addr, Runtime.WorkingEndian) == Runtime._endingCommand.Identifier)
{
CommandInfo info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == Runtime._endingCommand.Identifier);
ACMD_CMD_INFO info = Runtime.commandDictionary.FirstOrDefault(e => e.Identifier == Runtime._endingCommand.Identifier);

c = new Command(info);
c = new ACMDCommand(info);
_list.Add(c);
}

Expand Down Expand Up @@ -229,7 +228,7 @@ public string Serialize()

sb.Append("\n\tScript:{");
if (EventLists[u] != null)
foreach (Command cmd in EventLists[u])
foreach (ACMDCommand cmd in EventLists[u])
sb.Append(String.Format("\n\t\t{0}", cmd.ToString()));
else
sb.Append("\n\t\tEmpty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace Sm4shCommand.Classes
{
public unsafe class CommandList : IEnumerable<Command>
public unsafe class ACMDScript : IEnumerable<ACMDCommand>
{
private byte[] _data;

public CommandList(uint CRC)
public ACMDScript(uint CRC)
{
AnimationCRC = CRC;
}
Expand All @@ -23,7 +23,7 @@ public int Size
get
{
int size = 0;
foreach (Command e in _commands)
foreach (ACMDCommand e in _commands)
size += e.CalcSize();
return size;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public byte[] ToArray()
byte[] file = new byte[Size];

int i = 0;
foreach (Command c in _commands)
foreach (ACMDCommand c in _commands)
{
byte[] command = c.GetArray();
for (int x = 0; x < command.Length; x++, i++)
Expand All @@ -105,12 +105,12 @@ public byte[] ToArray()
return file;
}

public Command this[int i]
public ACMDCommand this[int i]
{
get { return _commands[i]; }
set { _commands[i] = value; }
}
private List<Command> _commands = new List<Command>();
private List<ACMDCommand> _commands = new List<ACMDCommand>();


#region IEnumerable Implemntation
Expand All @@ -121,19 +121,19 @@ public void Clear()
{
_commands.Clear();
}
public void Insert(int index, Command var)
public void Insert(int index, ACMDCommand var)
{
_commands.Insert(index, var);
}
public void InsertAfter(int index, Command var)
public void InsertAfter(int index, ACMDCommand var)
{
_commands.Insert(index + 1, var);
}
public void Add(Command var)
public void Add(ACMDCommand var)
{
_commands.Add(var);
}
public bool Remove(Command var)
public bool Remove(ACMDCommand var)
{
return _commands.Remove(var);
}
Expand All @@ -142,17 +142,17 @@ public void Remove(int index)
{
_commands.RemoveAt(index);
}
public bool Contains(Command var) { return _commands.Contains(var); }
public int IndexOf(Command var)
public bool Contains(ACMDCommand var) { return _commands.Contains(var); }
public int IndexOf(ACMDCommand var)
{
return _commands.IndexOf(var);
}
public void CopyTo(Command[] var, int index) { _commands.CopyTo(var, index); }
public void CopyTo(ACMDCommand[] var, int index) { _commands.CopyTo(var, index); }
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public IEnumerator<Command> GetEnumerator()
public IEnumerator<ACMDCommand> GetEnumerator()
{
for (int i = 0; i < _commands.Count; i++)
yield return _commands[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Sm4shCommand.Classes
/// <summary>
/// Contains command information
/// </summary>
public unsafe class CommandInfo
public unsafe class ACMD_CMD_INFO
{

public uint Identifier = 0;
public string Name { get { return _name; } set { _name = value; } }
private string _name;
Expand Down
18 changes: 13 additions & 5 deletions AnimCmd/Classes/Fighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public string Serialize()
label = $"{u:X8}";

sb.Append(String.Format($"\n\n{MotionTable.IndexOf(u):X}: [{label}]"));
CommandList c1 = null, c2 = null,
ACMDScript c1 = null, c2 = null,
c3 = null, c4 = null;

if (Main.EventLists.ContainsKey(u))
Expand All @@ -82,38 +82,46 @@ public string Serialize()

sb.Append("\n\tGame:{");
if (c1 != null)
foreach (Command cmd in c1)
foreach (ACMDCommand cmd in c1)
sb.Append(String.Format("\n\t\t{0}", cmd.ToString()));
else
sb.Append("\n\t\tEmpty");
sb.Append("\n\t}");

sb.Append("\n\tGFX:{");
if (c2 != null)
foreach (Command cmd in c2)
foreach (ACMDCommand cmd in c2)
sb.Append(String.Format("\n\t\t{0}", cmd.ToString()));
else
sb.Append("\n\t\tEmpty");
sb.Append("\n\t}");

sb.Append("\n\tSFX:{");
if (c3 != null)
foreach (Command cmd in c3)
foreach (ACMDCommand cmd in c3)
sb.Append(String.Format("\n\t\t{0}", cmd.ToString()));
else
sb.Append("\n\t\tEmpty");
sb.Append("\n\t}");

sb.Append("\n\tExpression:{");
if (c4 != null)
foreach (Command cmd in c4)
foreach (ACMDCommand cmd in c4)
sb.Append(String.Format("\n\t\t{0}", cmd.ToString()));
else
sb.Append("\n\t\tEmpty");
sb.Append("\n\t}");
}
return sb.ToString();
}
public void Export(string dirpath)
{
Main.Export($"{dirpath}/game.bin");
SFX.Export($"{dirpath}/sound.bin");
GFX.Export($"{dirpath}/effect.bin");
Expression.Export($"{dirpath}/expression.bin");
MotionTable.Export($"{dirpath}/motion.mtable");
}
public ACMDFile this[ACMDType type]
{
get
Expand Down
Loading

0 comments on commit db5ebf7

Please sign in to comment.