Skip to content

Unofficial Patch - Concert GetRevenue can silently fail due to opcode mismatch #3

Description

@ExSlam

Here is a fix to match Call OR Callvirt

[HarmonyPatch(typeof(SEvent_Concerts._concert._projectedValues), "GetRevenue")]
public class SEvent_Concerts__concert__projectedValues_GetRevenue
{
    public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
    {
        var list = new List<CodeInstruction>(instructions);

        MethodInfo getHype = AccessTools.Method(typeof(SEvent_Concerts._concert._projectedValues), "GetHype");
        MethodInfo infix   = AccessTools.Method(typeof(SEvent_Concerts__concert__projectedValues_GetRevenue), nameof(Infix));

        for (int i = 0; i < list.Count; i++)
        {
            if ((list[i].opcode == OpCodes.Call || list[i].opcode == OpCodes.Callvirt) &&
                list[i].operand is MethodInfo mi && mi == getHype)
            {
                list[i].opcode = OpCodes.Call; // force static call
                list[i].operand = infix;
                break;
            }
        }

        return list;
    }

    public static float Infix(SEvent_Concerts._concert._projectedValues __this)
    {
        float hype = __this.GetHype();

        if (hype > 1f)
        {
            // Avoid target-typed new() for max compatibility
            LinearFunction._function function = new LinearFunction._function();
            function.Init(0f, 0.5f, 1f, 0.25f);

            float num2 = hype - 1f;
            hype = num2 * function.GetY(num2) + 1f;
        }

        return hype;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions