Guest User

Untitled

a guest
Feb 3rd, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using HarmonyLib;
  7. using GameNetcodeStuff;
  8. using System.Reflection;
  9. using System.Reflection.Emit;
  10. using BepInEx.Logging;
  11. using UnityEngine;
  12.  
  13. namespace ScarletMansion.GamePatch {
  14.   public class SpawnScrapInLevelPatch {
  15.  
  16.     [HarmonyTranspiler]
  17.     [HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
  18.     public static IEnumerable<CodeInstruction> ConnectOverlappingDoorwaysPatch(IEnumerable<CodeInstruction> instructions){
  19.       var variable = typeof(RoundManager).GetField("scrapAmountMultiplier", BindingFlags.Instance | BindingFlags.Public);
  20.  
  21.       var sequence = new InstructionSequence("scrap", false, "The Loot Multiplier config will not work.");
  22.       sequence.AddBasicWithAlternateMethodName(OpCodes.Ldfld, variable, "GetScrapValueModifier");
  23.       sequence.AddBasic(OpCodes.Mul);
  24.       sequence.AddBasic(OpCodes.Conv_I4);
  25.  
  26.       foreach(var instruction in instructions){
  27.  
  28.         if (sequence.VerifyStage(instruction)){
  29.  
  30.           var method = typeof(SpawnScrapInLevelPatch).GetMethod("ModifyScrapCount", BindingFlags.Static | BindingFlags.Public);
  31.  
  32.           yield return new CodeInstruction(OpCodes.Call, method);
  33.           yield return instruction;
  34.  
  35.           continue;
  36.         }
  37.  
  38.         yield return instruction;
  39.       }
  40.  
  41.       sequence.ReportComplete();
  42.     }
  43.  
  44.     public static float ModifyScrapCount(float count){
  45.       if (DunGenPatch.Patch.active == false) return count;
  46.       return count * PluginConfig.Instance.dunGenLootMultiplierValue;
  47.     }
  48.  
  49.   }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment