Skip to content

Commit

Permalink
Add more EXE text and opcode search
Browse files Browse the repository at this point in the history
  • Loading branch information
petfriendamy committed Dec 15, 2024
1 parent 826a859 commit 43350ac
Show file tree
Hide file tree
Showing 12 changed files with 1,083 additions and 276 deletions.
19 changes: 18 additions & 1 deletion src/AIEditor/AIContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class AIContainer
public const int SCRIPT_NUMBER = 16;
protected readonly Script[] scripts = new Script[SCRIPT_NUMBER];
public IAttackContainer Parent { get; protected set; }
bool scriptsLoaded = false;

public Script[] Scripts
{
Expand All @@ -31,6 +32,21 @@ public bool HasScripts()
return false;
}

public int HasOpcode(Opcodes op)
{
if (HasScripts())
{
for (int i = 0; i < SCRIPT_NUMBER; ++i)
{
if (Scripts[i].HasOpcode(op))
{
return i;
}
}
}
return -1;
}

public void ParseScripts(byte[] data, int headerSize, int offset, int nextOffset)
{
int i, j, next, start, length;
Expand Down Expand Up @@ -79,6 +95,7 @@ public void ParseScripts(byte[] data, int headerSize, int offset, int nextOffset
scripts[i] = new Script(this, ref data, start, length);
}
}
scriptsLoaded = true;
}

public byte[] GetScriptBlock()
Expand Down Expand Up @@ -140,7 +157,7 @@ public static byte[] GetGroupedScriptBlock(int containerCount, int blockSize, AI
{
offsets[i] = HexParser.NULL_OFFSET_16_BIT;
length[i] = 0;
scriptList.Add(new byte[0]);
scriptList.Add(Array.Empty<byte>());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/AIEditor/Code.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class Code
{
return Parent.Parent.Parent;
}
public abstract bool HasOpcode(Opcodes op);

public Code(Script parent)
{
Expand Down
12 changes: 12 additions & 0 deletions src/AIEditor/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public CodeBlock(CodeBlock other) :base(other.Parent)
}
}

public override bool HasOpcode(Opcodes op)
{
foreach (var c in block)
{
if (c.HasOpcode(op))
{
return true;
}
}
return false;
}

public void AddToTop(Code code)
{
block.Insert(0, code);
Expand Down
5 changes: 5 additions & 0 deletions src/AIEditor/CodeLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public override ushort SetHeader(ushort value)
return Convert.ToUInt16(GetDataLength() + value);
}

public override bool HasOpcode(Opcodes op)
{
return (byte)op == Opcode;
}

public override string Disassemble(bool verbose)
{
string output = "";
Expand Down
17 changes: 12 additions & 5 deletions src/AIEditor/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public Script(Script other) :this(other.Parent)
headersAreCorrect = other.headersAreCorrect;
}

public bool HasOpcode(Opcodes op)
{
foreach (var c in code)
{
if (c.HasOpcode(op))
{
return true;
}
}
return false;
}

public void ParseScript(ref byte[] data, int offset, int length)
{
//run through the script and idenify all the opcodes
Expand Down Expand Up @@ -401,11 +413,6 @@ public string[] Disassemble()
//output the disassembled code
output.Add($"{new string(indent)}{c.Disassemble(true)}");
}

/*foreach (var c in code)
{
output.Add(c.Disassemble(true));
}*/
}
return output.ToArray();
}
Expand Down
Loading

0 comments on commit 43350ac

Please sign in to comment.