This early development version but, it working just as designed.
At this moment "injection" done by additional "monitor" thread, this subject to change, perfectly - by original game developer.
there is only single def at play:
this def will perform loading of *main* type of assembly, allowing to inject code at early stages of game.
payload code is
c# unlike java allows to override only methods marked virtual, this is severe limitation to hacking.
since WeatherDecider still have single virtual method - we override it.
At this moment "injection" done by additional "monitor" thread, this subject to change, perfectly - by original game developer.
there is only single def at play:
Code Select
<?xml version="1.0" encoding="utf-8" ?>
<Loaders>
<Loader>
</Loader>
</Loaders>
this def will perform loading of *main* type of assembly, allowing to inject code at early stages of game.
payload code is
Code Select
public class Loader : Def
{
static Loader()
{
Log.Error("<CINIT>(..cctor) Section invocation ((static)Type Constructor)");
Thread branchA = new Thread(new ThreadStart(Loader.watchInternalState));
branchA.Start();
//we start new thread here to monitor game activity and field change, this done in place of bytecode injection.
}
static void watchInternalState()
{
for(;;) //infinite loop
{
try //just in case, normal exceptions wont show up in console
{
if (Find.RootMap == null) //as long as map not initialized we do nothing
continue;
Thread.Sleep(100); //when map is initialized, we wait to ensure object init and perform payload
//throw GameInitializeEvent and handle all mods that listen to it NYI
Find.Map.storyteller.weatherDecider = new WeatherDeciderImpl();
Log.Error("Weather Decider is replaced;");
break; //we no longer need this thread, we break loop and terminate it
}catch( Exception E)
{
Log.Error(E.ToString());
}
}
}
}
c# unlike java allows to override only methods marked virtual, this is severe limitation to hacking.
since WeatherDecider still have single virtual method - we override it.
Code Select
public class WeatherDeciderImpl : WeatherDecider
{
protected override WeatherDef NextWeather() //only method that can be "hooked"
{
Log.Error("Virtual method invocation");
return DefDatabase<WeatherDef>.AllDefs.First(); //first def is "clear" weather, it's possible to define any other weather, including permanent dry thunderstorm or cycle weather in predefined order
}
}