Skip to content

Commit

Permalink
- Fix conditionals for the last time
Browse files Browse the repository at this point in the history
- Allow adding commands to empty lists
- fix infinite loop memory leak when someone mistakenly opens anything other than ACMD
- fix save in fighter mode
  • Loading branch information
Sammi-Husky committed Feb 21, 2016
1 parent aae84f5 commit 00fe2fd
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 38 deletions.
10 changes: 10 additions & 0 deletions AnimCmd/Classes/Fighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public class Fighter
public MTable MotionTable { get { return _mtable; } set { _mtable = value; } }
private MTable _mtable;

public bool Dirty
{
get
{
for (int i = 0; i < 4; i++)
if (this[(ACMDType)i].Dirty)
return true;
return false;
}
}
/// <summary>
/// Dumps a fighters script in it's entirety as text for use in version diffing.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion AnimCmd/Classes/Nodes/CommandListGroupNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Sm4shCommand.Nodes
public class CommandListGroup : BaseNode
{
private static ContextMenuStrip _menu;

public bool Dirty { get { return Fighter.Dirty; } }
public CommandListGroup(Fighter fighter, uint CRC)
{

Expand Down
4 changes: 2 additions & 2 deletions AnimCmd/Events.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,9 @@ unknown,unknown,unknown,unknown,unknown,unknown,unknown,unknown
NONE

477705C2
Compare
unk_477705C2
0,0,0
var,mode,value
unknown,unknown,unknown
NONE

47810508
Expand Down
42 changes: 21 additions & 21 deletions AnimCmd/Gui/MainForm.Designer.cs

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

2 changes: 1 addition & 1 deletion AnimCmd/Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (isRoot && _curFighter == null)
return;
else if (_curFile == null)
else if (!isRoot && _curFile == null)
return;

for (int i = 0; i < tabControl1.TabCount; i++)
Expand Down
37 changes: 24 additions & 13 deletions AnimCmd/System/Windows/Components/ITSCodeBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ public void SetSource(CommandList list)
{
int amt = 0;
if ((amt = SerializeCommand(i, list[i]._commandInfo.Identifier)) > 0)
{
i += amt;
continue;
}
else

if (i < list.Count)
Lines.Add(new Line(list[i].ToString(), this));
}
if (list.Empty)
Lines.Add(new Line("// Empty List", this));

DoFormat();
}
#region Command Handling
Expand All @@ -92,20 +91,25 @@ private int SerializeConditional(int startIndex)
string str = _list[startIndex].ToString();
int len = (int)_list[startIndex].parameters[0] - 2;
Lines.Add(new Line($"{str}{{", this));
while ((len -= _list[++i].CalcSize() / 4) != 0)
int count = 1;
i++;

while (len > 0)
{
len -= _list[i].CalcSize() / 4;

if (IsCmdHandled(_list[i]._commandInfo.Identifier))
i += SerializeCommand(i, _list[i]._commandInfo.Identifier);
else
break;
else {
Lines.Add(new Line(_list[i].ToString(), this));
i++;
count++;
}
}
if (IsCmdHandled(_list[i]._commandInfo.Identifier))
SerializeCommand(i, _list[i]._commandInfo.Identifier);
else
Lines.Add(new Line(_list[i].ToString(), this));

i += (count += SerializeCommand(i, _list[i]._commandInfo.Identifier));
Lines.Add(new Line("}", this));
return i - startIndex;
return count;
}
private int SerializeLoop(int startIndex)
{
Expand Down Expand Up @@ -686,7 +690,10 @@ private void DoNewline()
else if (SelectionStart.X == Lines[SelectionStart.Y].Length)
{
Lines.Insert(SelectionStart.Y + 1, new Line(string.Empty, this));
_list.Insert(SelectionStart.Y + 1, null);
if (SelectionStart.Y + 1 > _list.Count)
_list.Add(null);
else
_list.Insert(SelectionStart.Y + 1, null);
CaretNextLine();
}
Invalidate();
Expand Down Expand Up @@ -835,6 +842,10 @@ public CommandInfo GetInfo()
else
return null;
}
public override string ToString()
{
return Text;
}

public void Draw(int x, int y, Graphics g)
{
Expand Down
5 changes: 5 additions & 0 deletions AnimCmd/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public ACMDFile OpenFile(string Filepath)
public ACMDFile OpenFile(string Filepath, ACMDType type)
{
DataSource source = new DataSource(FileMap.FromFile(Filepath));
if (new String((sbyte*)source.Address) != "ACMD")
{
MessageBox.Show("Not an ACMD file:\n" + Filepath);
return null;
}

if (*(byte*)(source.Address + 0x04) == 0x02)
Runtime.WorkingEndian = Endianness.Little;
Expand Down

0 comments on commit 00fe2fd

Please sign in to comment.