void GameLocation_answerDialogueAction() { var code = FindCode( // else if ((int)Game1.player.maxItems != 36) { Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), OpCodes.Call, Instructions.Ldc_I4_S(36), OpCodes.Beq ); var get_player = Instructions.Call_get(typeof(Game1), nameof(Game1.player)); code.Replace( // else if ((int)Game1.player.maxItems < 36 Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), code[2], Instructions.Ldc_I4_S(48), Instructions.Bge(AttachLabel(get_player)), // && Game1.player.Money >= 50000) { Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Callvirt_get(typeof(Farmer), nameof(Farmer.Money)), Instructions.Ldc_I4(50000), Instructions.Blt(AttachLabel(get_player)), // buyBackpack(); Instructions.Call(GetType(), "buyBackpack"), // } // else if ((int)Game1.player.maxItems != 48) { get_player, Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), code[2], Instructions.Ldc_I4_S(48), code[4] ); }
void GameLocation_performAction() { var code = FindCode( Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), OpCodes.Call, Instructions.Ldc_I4_S(36), OpCodes.Bge ); code.Extend( Instructions.Ldstr("Backpack"), OpCodes.Call, OpCodes.Br ); var len = code.length; code.Append( Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), code[2], Instructions.Ldc_I4_S(48), code[4], Instructions.Call(GetType(), "clickBackpack"), Instructions.Br((Label)code[len - 1].operand) ); code[4] = Instructions.Bge(AttachLabel(code[len])); }
void SeedShop_draw() { var check = FindCode( Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), OpCodes.Call, Instructions.Ldc_I4_S(36), OpCodes.Bge ); var pos = check.Follow(4); // Do a sanity check if ((pos[-1].opcode == OpCodes.Ret || pos[-1].opcode == OpCodes.Br) && pos[0].opcode == OpCodes.Ldarg_1) { // Ok } else { throw new System.Exception("Jump does not go to expected location."); } // Inject check and call to drawBiggerBackpack. pos.Insert(0, // else if (maxItems < 48) Instructions.Call_get(typeof(Game1), nameof(Game1.player)), Instructions.Ldfld(typeof(Farmer), nameof(Farmer.maxItems)), check[2], // Nothing jumps here so reusing this should be OK. Instructions.Ldc_I4_S(48), check[4], // We'll create a new jump in check later. // drawBiggerBackpack(b); Instructions.Ldarg_1(), Instructions.Call(GetType(), "drawBiggerBackpack", typeof(SpriteBatch)) // } ); // Create a new jump in check. check[4] = Instructions.Bge(AttachLabel(pos[0])); }