Got it working, thanks!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Pages1
#2
Tools / Re: [LIB] Harmony v1.2.0.1
June 07, 2020, 05:35:21 PM
This is what I have (it throws a NullReferenceException):
Code Select
if (float.Parse(codes[i].operand.ToString()) == -10)
{
codes[i].operand = -5;
UnityEngine.Debug.Log("Index " + i + ": " + codes[i].operand.ToString());
}
else if (float.Parse(codes[i].operand.ToString()) == 10)
{
codes[i].operand = 5;
UnityEngine.Debug.Log("Index " + i + ": " + codes[i].operand.ToString());
}
#3
Tools / Re: [LIB] Harmony v1.2.0.1
May 29, 2020, 03:07:55 AM
Okay, I've managed to figure out something that works for finding and replacing methods in operands:
Now I have a different question, though: how do I set an operand to something that's not a method? I have an instruction whose operand is a float, but trying to set it to a different float causes a NullReferenceException. How do I get around this?
Code Select
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for (var i = 0; i < codes.Count; i++)
{
if (codes[i].operand == typeof(UnityEngine.Input).GetMethod("GetKeyDown", new[] { typeof(KeyCode) }))
{
codes[i].operand = typeof(UnityEngine.Input).GetMethod("GetKey", new[] { typeof(KeyCode) });
}
}
return codes.AsEnumerable();
}
Now I have a different question, though: how do I set an operand to something that's not a method? I have an instruction whose operand is a float, but trying to set it to a different float causes a NullReferenceException. How do I get around this?
#4
Tools / Re: [LIB] Harmony v1.2.0.1
May 28, 2020, 08:55:27 PM
The context is that it's calling a method, like so:
Code Select
call bool [UnityEngine]UnityEngine.Input::GetKeyDown(valuetype [UnityEngine]UnityEngine.KeyCode)
I'm attempting to follow the example on the Harmony wiki, which checks the value of an instruction's operand using Code Select
code[i].operand as String
Unfortunately, that returns null for me. I tried doing Code Select
code[i].operand = "method I want to call";
but that caused the game to crash.
#5
Tools / Re: [LIB] Harmony v1.2.0.1
May 28, 2020, 06:39:00 PM
Hi, how would one go about setting an instruction's operand? I'm trying to write a transpiler that changes the operands of certain instructions, but I'm not sure how to actually go about doing that. I've tried setting them to a string, but that ends in a crash. Also, trying to get the operand as a string using "codes.operand as String" returns null for some reason.
Pages1