private static IEnumerable <CodeInstruction> Transpiler(MethodBase method, ILGenerator il, IEnumerable <CodeInstruction> instructions) { // var skipLabel = il.DefineLabel(); var arr = instructions.ToArray(); // CodeInstruction enumeratorInstruction = null; var loadListViewElementIndex = -1; for (var index = 0; index < arr.Length; index++) { var inst = arr[index]; // if(index > 350 && index < 500) // Debug.Log("<color=grey>" + index + ": " + inst + "</color>"); // if (inst.opcode == OpCodes.Unbox_Any && inst.operand != null && inst.ToString() == "UnityEditor.ListViewElement") // { // Debug.Log("LIST VIEW ELEMENT " + inst.operand); // } // if (enumeratorInstruction == null && inst.operand != null && inst.opcode == OpCodes.Callvirt && inst.operand is MethodInfo m) // { // if (m.DeclaringType?.Name.EndsWith("ListViewElementsEnumerator") ?? false) // { // enumeratorInstruction = inst; // enumeratorInstruction.labels.Add(continueLabel); // Debug.Log("ENUMERATOR " + m.FullDescription()); // } // } // if (inst.IsStloc() && inst.operand != null && inst.operand is LocalBuilder loc && loc.LocalType == typeof(ListViewElement)) // { // yield return inst; // Debug.Log("STORING " + inst + ", " + loc.LocalIndex); // yield return new CodeInstruction(OpCodes.Ldloc, loc.LocalIndex); // yield return CodeInstruction.Call(typeof(ListViewPatch), nameof(OnDrawElement), new[] {typeof(ListViewElement)}); // yield return new CodeInstruction(OpCodes.Brfalse, skipLabel); // arr[653].labels.Add(skipLabel); // continue; // } // get local index for current list view element if (loadListViewElementIndex == -1 || inst.IsStloc() && inst.operand is LocalBuilder) { var loc = inst.operand as LocalBuilder; if (loc?.LocalType == typeof(ListViewElement)) { loadListViewElementIndex = loc.LocalIndex; } } if (inst.opcode == OpCodes.Call && inst.operand is MethodInfo m) { if (m.DeclaringType == typeof(LogEntries) && m.Name == "GetLinesAndModeFromEntryInternal") { yield return(inst); // load text is one element before var ldStr = arr[index - 1]; yield return(new CodeInstruction(OpCodes.Ldloc, loadListViewElementIndex)); yield return(ldStr); yield return(CodeInstruction.Call(typeof(ConsoleListView), nameof(ConsoleListView.ModifyText))); continue; } } yield return(inst); } }