V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zeronofreya
V2EX  ›  问与答

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

  •  1
     
  •   zeronofreya · Aug 3, 2021 · 1178 views
    This topic created in 1738 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   ·   5373 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:38 · PVG 17:38 · LAX 02:38 · JFK 05:38
    ♥ Do have faith in what you're doing.