Finding and editing private objects with plugins in c#
I am working on making a plugin for a game and am trying to locate a private object inside of a public class. I already have a way to postcall my new method after the primary one in the game's class.
//Game classes, simplified version
public class guy{
public int height;
}
public class theGame{
private guy Waldo = new guy();
public void setWaldoHeight{
Waldo.height = 5
}
}
With the plugin
public class plugin{
private guy Waldo;
//???
public void setWaldoHeight{
//give Waldo a new height value of 8
}
}
I have already tried a few methods such as reflection, using FieldInfo field = typeof(guy).GetField("Waldo", BindingFlags.NonPublic | BindingFlags.Instance)
with Field.SetValue(Waldo.height, 8);
, but it had no luck finding Waldo. I have also tried using the GameObject.Find()
command to locate either theGame or Waldo himself, but it does not seem to work because Waldo is private and theGame is never declared as an object. I saw some other answers to similar UnintyEditor, but it sounds like that is not an option outside of the Editor.