public static IEnumerable <CodeInstruction> Transpiler(ILGenerator il, IEnumerable <CodeInstruction> instructions)
        {
            var originalCodes = new List <CodeInstruction>(instructions);
            var codes         = new List <CodeInstruction>(originalCodes);

            var index = 0;

            var infoLdInstruction      = new CodeInstruction(OpCodes.Ldarg_S, InfoArgIndex);
            var segmentIdLdInstruction = new CodeInstruction(OpCodes.Ldarg_2); // segmentID is second argument

            if (!NetSegmentRenderPatch.PatchLanesAndSegments(il, codes, infoLdInstruction, segmentIdLdInstruction, ref index))
            {
                Debug.LogError("Could not apply NetSegmentRenderPatch. Cancelling transpiler!");
                return(originalCodes);
            }

            return(codes);
        }
Esempio n. 2
0
        public static IEnumerable <CodeInstruction> Transpiler(ILGenerator il, IEnumerable <CodeInstruction> instructions)
        {
            var netSegmentInfoGetter = typeof(global::NetSegment).GetProperty("Info")?.GetGetMethod();

            if (netSegmentInfoGetter == null)
            {
                Debug.LogError("Necessary field not found. Cancelling transpiler!");
                return(instructions);
            }

            var originalCodes = new List <CodeInstruction>(instructions);
            var codes         = new List <CodeInstruction>(originalCodes);

            var index = 0;

            CodeInstruction infoLocalVarLdloc = null;

            for (; index < codes.Count; index++)
            {
                // IL_0003: call instance class NetInfo NetSegment::get_Info()
                if (codes[index].opcode == OpCodes.Call && codes[index].operand == netSegmentInfoGetter && TranspilerUtils.IsStLoc(codes[index + 1]))
                {
                    infoLocalVarLdloc = TranspilerUtils.BuildLdLocFromStLoc(codes[index + 1]);
                    index            += 2;
                    break;
                }
            }

            if (infoLocalVarLdloc == null)
            {
                Debug.LogError("NetSegmentCalculateGroupDataPatch: info local variable not found. Cancelling transpiler!");
                return(originalCodes);
            }

            var segmentIdLdInstruction = new CodeInstruction(OpCodes.Ldarg_1); // segmentID is first argument

            if (!NetSegmentRenderPatch.PatchLanesAndSegments(il, codes, infoLocalVarLdloc, segmentIdLdInstruction, ref index))
            {
                Debug.LogError("NetSegmentCalculateGroupDataPatch: Could not apply NetSegmentRenderPatch. Cancelling transpiler!");
                return(originalCodes);
            }

            return(codes);
        }