zeronofreya
V2EX  ›  问与答

有用 BepInEx 开发过 mod 的大佬吗,修改变量无效?

  •  1
     
  •   zeronofreya · Aug 3, 2021 · 1244 views
    This topic created in 1770 days ago, the information mentioned may be changed or developed.

    具体游戏是戴森球计划

    [HarmonyPrefix]
    [HarmonyPatch(typeof(InserterComponent), "InternalUpdate")]
    public static bool InternalUpdatePrefix(InserterComponent __instance)
    {
        __instance.itemId = 1234;  // 测试
        Console.WriteLine(__instance.itemId);   // 打印 1234
        return false;
    }
    
    [HarmonyPostfix]
    [HarmonyPatch(typeof(InserterComponent), "InternalUpdate")]
    public static void InternalUpdatePostfix(InserterComponent __instance)
    {
        Console.WriteLine(__instance.itemId);  // 打印 0
    }
    

    做了个简单的测试,但未能改变 itemId 的值,反编译游戏代码,itemId 是 public

    public int itemId;
    

    不清楚为什么不能改

    2 replies    2021-08-04 15:26:30 +08:00
    levelworm
        1
    levelworm  
       Aug 4, 2021
    弱弱的问,这是传引用还是值进去?
    zeronofreya
        2
    zeronofreya  
    OP
       Aug 4, 2021
    @levelworm 我觉得是值
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5919 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 02:09 · PVG 10:09 · LAX 19:09 · JFK 22:09
    ♥ Do have faith in what you're doing.