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

Fix patching run and gun log spam #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions 1.4/Source/DualWield/Harmony/RunAndGun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,36 @@ namespace DualWield.Harmony
[HarmonyPatch]
public class RunAndGun
{
static MethodBase TargetMethod()
static IEnumerable<MethodBase> TargetMethods()
{
Assembly ass = GetAssemblyByName("RunAndGun");
if(ass != null)
{
Type predicateClass = GetAssemblyByName("RunAndGun").GetTypes().FirstOrDefault((Type type) => type.Name == "Verb_TryCastNextBurstShot");
Type predicateClass = ass.GetTypes().FirstOrDefault((Type type) => type.Name == "Verb_TryCastNextBurstShot");
if(predicateClass != null)
{
MethodInfo minfo = predicateClass.GetMethods(AccessTools.all).FirstOrDefault(m => m.Name.Contains("SetStanceRunAndGun"));
if (minfo != null)
{
return minfo;
yield return minfo;
}
}
}
return typeof(RunAndGun).GetMethod("Stub");
}
static void Prepare(MethodBase original)
{
if (original != null)
{
Log.Message("patching run and gun");
}
}
static void Postfix(Pawn_StanceTracker stanceTracker, Stance_Cooldown stance)
{
//Make sure this is called when run and gun patches the same line of code as we do in the harmony Patch Verb_TryCastNextBurstShot.
//SetStanceOffHand(stanceTracker, stance);
Log.Message("patching run and gun");
Verb_TryCastNextBurstShot.SetStanceOffHand(stanceTracker, stance);
}

//When Run and Gun or the to be patched method isn't found, patch this stub method so no error is thrown.
public static void Stub(Pawn_StanceTracker stanceTracker, Stance_Cooldown stance)
{
//Do nothing
}

static Assembly GetAssemblyByName(string name)
{
return AppDomain.CurrentDomain.GetAssemblies().
Expand Down