Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] #50

Open
orcun9988 opened this issue Jun 30, 2022 · 3 comments
Open

[question] #50

orcun9988 opened this issue Jun 30, 2022 · 3 comments

Comments

@orcun9988
Copy link

orcun9988 commented Jun 30, 2022

[HarmonyPatch(typeof(GhostInfo), nameof(GhostInfo.SyncValuesNetworked))]

class StringFileExists
{
    static bool Prefix(int param_1,int param_2,bool param_3,int param_4,int param_5,bool param_6, int param_7,int param_8,bool param_9,PhotonMessageInfo param_10)
    {
        Console.WriteLine(param_1.ToString(), param_2.ToString(), param_3.ToString(), param_4.ToString(), param_5.ToString(), param_6.ToString(), param_7.ToString(), param_8.ToString(), param_9.ToString(), param_10.ToString());
        return true;
    }

}

this is my code , I just want to know when ghostInfo.Syncvaluenetworked works print the parameters to console I don't want to patch that method

it print's the parameteres however it's also patching the method I don't want to patch thats why I added return true

cuz if u add return false = skip the orginial method

do you know how I can get it to patch only if certain conditions are met?
for example
if(checkbox.checked == true ) patch(ghostInfo.SyncValuesNetworked)

@ManlyMarco
Copy link
Member

If you want to patch only if there's a condition then you can just make a Harmony instance and patch/unpatch it as needed, you'll just need to patch in a way that only affects that specific patch, so either PatchAll(Type) or Patch().

It's much easier to just always patch and check the condition inside of the patch. If the patched method doesn't run often then there will be no real performance effect.

@orcun9988
Copy link
Author

orcun9988 commented Jun 30, 2022

can u give me example like

`[HarmonyPatch(typeof(MissionManager), nameof(MissionManager.SetMission))]
class Patch73141
{

static void Prefix()
{
    if (patchmissions  == true)
    {
        Console.WriteLine("Patched!");
        return;
    }
    else
    {
        Console.WriteLine("there should be no patch but still patched :(");
    }
}

}`

like that ( it's alwasy patching even patchmissions == false )

@ManlyMarco
Copy link
Member

If you want to patch a single method then you can do something like this https://github.com/IllusionMods/IllusionModdingAPI/blob/dc09eed2c1b740e32f63400e5efde527ddad7077/src/KKSAPI/MainGame/TopicApi.cs#L242-L243 and then do h.UnpatchSelf() to remove the patch. You can then patch again, rinse and repeat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants