public bool PatchPrepare( AVM1Code code, ModLib modLibrary )
{
List<int> triggerPositions = new List<int>();
// check if trigger action is found, if not bail
for ( int i = 0; i < code.Count; i++ )
{
if ( code[ i ].ActionType == _TriggerAction )
{
triggerPositions.Add( i );
}
}
if ( 0 == triggerPositions.Count )
return false;
// check if static analysis can show no need to patch
List<int> patchPositions = new List<int>();
List<int> modificationPositions = new List<int>();
for ( int i = 0; i < triggerPositions.Count; i++ )
{
switch ( NeedsPatching( code, triggerPositions[i] ) )
{
case PatchState.Innocent:
// ignore
break;
case PatchState.Indeterministic:
patchPositions.Add( triggerPositions[ i ] );
break;
case PatchState.Change:
modificationPositions.Add( triggerPositions[ i ] );
break;
default:
throw new Exception( "FUCKUP, cannot even handle an enum correctly" );
}
}
// now patch the indeterministic ones
for ( int i = 0; i < patchPositions.Count; i++ )
{
Modification mod = this.GetInlineCode( code, patchPositions[ i ] );
modLibrary.Modifications.Add( mod );
}
// now, patch the ones that need to go!
// ... this.GetRemovalCode( ... );
return true;
}