Is there a decompiler able to handle yield return?

Started by Rahjital, May 30, 2015, 04:24:30 PM

Previous topic - Next topic

Rahjital

ILSpy and Dotpeek are fine decompilers, but they fail horribly at one thing: decompiling functions where yield return is used. One example:

This:
protected override IEnumerable<Toil> MakeNewToils()
{
this.EndOnDespawned( VictimInd, JobCondition.Succeeded );

yield return Toils_Reserve.Reserve(VictimInd );
yield return Toils_Combat.TrySetJobToUseAttackVerb();

Toil gotoCastPos = Toils_Combat.GotoCastPosition( VictimInd );

yield return gotoCastPos;

Toil jumpIfCannotHit =  Toils_Jump.JumpIfTargetNotHittable( VictimInd, gotoCastPos );

yield return jumpIfCannotHit;
yield return Toils_Combat.CastVerb( VictimInd );
yield return Toils_Jump.Jump( jumpIfCannotHit );
}


Gets turned by ILSpy and Dotpeek into this:
[DebuggerHidden]
protected override IEnumerable<Toil> MakeNewToils()
{
JobDriver_Kill.<MakeNewToils>c__IteratorDD <MakeNewToils>c__IteratorDD = new JobDriver_Kill.<MakeNewToils>c__IteratorDD();
<MakeNewToils>c__IteratorDD.<>f__this = this;
JobDriver_Kill.<MakeNewToils>c__IteratorDD expr_0E = <MakeNewToils>c__IteratorDD;
expr_0E.$PC = -2;
return expr_0E;
}


Now of course that's rather useless for modding. Tynan has been gracious to give us quite a few source files using this, but if I want to look at how, say, the kidnapping JobDriver works, there's not much I can do. So I want to ask, is there any decompiler able to handle this case correctly?

RawCode

you are missing internal class c__IteratorDD that contains all logic in pretty linear way.
you must enable "compiler\internal" code to see that type.

this is how iterators and enums actually looks, with a bit more skill you will be able to read such code without issues.