internal static void RunNonDestructivePatches()
        {
            Type original = typeof(WorkGiver_ConstructDeliverResources);
            Type patched  = typeof(WorkGiver_ConstructDeliverResources_Transpile);

            RimThreadedHarmony.Transpile(original, patched, "ResourceDeliverJobFor", null, new string[] { "CodeOptimist.JobsOfOpportunity" });
        }
Ejemplo n.º 2
0
        public static void Patch()
        {
            Type type = TypeByName("ZombieLand.ZombieStateHandler");

            if (type != null)
            {
                foreach (MethodInfo method in type.GetMethods())
                {
                    if (method.IsDeclaredMember())
                    {
                        try
                        {
                            IEnumerable <KeyValuePair <OpCode, object> > f = PatchProcessor.ReadMethodBody(method);
                            foreach (KeyValuePair <OpCode, object> e in f)
                            {
                                if (e.Value is FieldInfo fieldInfo && RimThreadedHarmony.replaceFields.ContainsKey(fieldInfo))
                                {
                                    RimThreadedHarmony.TranspileFieldReplacements(method);
                                    break;
                                }
                                if (e.Value is MethodInfo methodInfo && RimThreadedHarmony.replaceFields.ContainsKey(methodInfo))
                                {
                                    RimThreadedHarmony.TranspileFieldReplacements(method);
                                    break;
                                }
                            }
                        }
                        catch (NotSupportedException) { }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <CodeInstruction> GetExtendedDataFor(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            Type typeDictionaryIntData = typeof(Dictionary <,>).MakeGenericType(new Type[] { typeof(int), GiddyUpCore_Patch.giddyUpCoreStorageExtendedPawnData });
            List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(GiddyUpCore_Patch.giddyUpCoreStorageExtendedDataStorage, "_store")),
            };
            List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy();

            searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_0));
            searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_2));
            searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeDictionaryIntData, "set_Item", new Type[] { typeof(int) })));
            //searchInstructions.Add(new CodeInstruction(OpCodes.Pop));

            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count, loadLockObjectInstructions, typeDictionaryIntData))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> WaitForRider(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions2 = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Call, AccessTools.Method(GiddyUpCore_Patch.giddyUpCoreJobsJobDriver_Mounted, "get_Rider")),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Pawn), "get_CurJob")),
            };
            List <CodeInstruction> searchInstructions = searchInstructions2.ListFullCopy();

            searchInstructions.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Job), "def")));
            searchInstructions.Add(new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(GiddyUpCore_Patch.giddyUpCoreJobsGUC_JobDefOf, "Mount")));
            searchInstructions.Add(new CodeInstruction(OpCodes.Beq_S));

            List <CodeInstruction> instructionsList = instructions.ToList();
            int          currentInstructionIndex    = 0;
            bool         matchFound = false;
            LocalBuilder curJob     = iLGenerator.DeclareLocal(typeof(Job));

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    for (int i = 0; i < 3; i++)
                    {
                        yield return(instructionsList[currentInstructionIndex]);

                        currentInstructionIndex++;
                    }

                    yield return(new CodeInstruction(OpCodes.Stloc, curJob.LocalIndex));

                    yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex));

                    yield return(new CodeInstruction(OpCodes.Brfalse_S,
                                                     instructionsList[currentInstructionIndex + 2].operand)); //this may need to be a jump to a line 5 lines above this

                    yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex));

                    for (int i = 0; i < 3; i++)
                    {
                        yield return(instructionsList[currentInstructionIndex]);

                        currentInstructionIndex++;
                    }
                }
                else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex));

                    for (int i = 0; i < 3; i++)
                    {
                        //yield return instructionsList[currentInstructionIndex];
                        currentInstructionIndex++;
                    }
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }