Doubts about how to make one specific weather trigger a specific game effect

Started by Obsdark, September 13, 2020, 12:47:13 PM

Previous topic - Next topic

Obsdark

Hello there,
a question, did any of you know how to make a GameEffect happend when a Weather is triggered?

I mean, as it works with the Toxic Fallout event in Vanilla Rimworld, i'm trying to achieve that, but i cannot find anywhere in the RimWorld code the place where the game condition is triggered after the weather condition enters the game, and i'm trying to make my own game condition to happend in such cases, like in the case of Toxic Fallout event in vanilla.

I manage to actualy make the weather event to work, also an item than call such weather event, and i think i make successfully the game effect and condition too, but i cannot link both things, any ideas?

Suggestions?

Did any of you know a mod than actualy do something like that? (other than time rift, because that ones do it with pure XML, and that doesn't allow me to do the effect i'm trying)

Looking forward to read your replys

RawCode

you should search more, because entire vanilla implementation is c# and there are no hidden routines or native methods (unlike some other games like OXY) (and ever in case of native methods you can disassemble image and get code)

you should describe how exactly you searched and what is wrong with search results

and yes, if you want custom effect you have to provide custom logic

Obsdark

Quote from: RawCode on September 13, 2020, 01:00:32 PM
you should search more, because entire vanilla implementation is c# and there are no hidden routines or native methods (unlike some other games like OXY) (and ever in case of native methods you can disassemble image and get code)

you should describe how exactly you searched and what is wrong with search results

and yes, if you want custom effect you have to provide custom logic

I think i have the custom effect, the problem is connecting with the weather execution

I check using dnSpy for the toxic fallout, from what i learn there (in WeatherOverlay_Fallout, WeatherEvent_LightingFlash, WeatherEvent, WeatherManager and WeatherDefOf) i still can't find where the Game call the GameCondition_ToxicFallout so to execute the Toxic condition.

I'm probably not looking at the right place in the code, and if the dnSpy have the hability to check where is a function been called, so far, i haven't been able to found it, if it were the case this search should be very, very short, but sadly such is not the case.

I'm not certain how can i check for it either, or even if that is the right search, for instance, it could be the case than the thing than i actualy need to do is patch the list of GameConditions, events or something, and although i see some examples about how to patch (XML) i can't find examples of those specific patching actions if they ever exist, or something similar to learn how to fix that, if that's even a problem.

So, any direction you or whoever read this can bring, will be apreciated

The code is not necesary yet to show because i need to been able to execute the GameCondition first in order to test if it works or not, if it is by the code itself i should think than is working, but i wouldn't been able to know from where to call it.

If happend than i can find an example i could call the function in a similar fashion to the example, and then, if it doesn't work, of course i show code, the problem is right now i don't even know if that code is good or not because i don't know from where to execute it.

Of course i want to avoid bad implementations too, i say this because i add it to some other places, like in a custom made WeatherOverlay, and well, that doesn't go that well because of the way the WeatherOverlays exist and work.

If i found an example i can do the thing that is supposed to be done for things like that, hence, avoiding bad performances, errors and/or disordered code, and everything in between.

RawCode

all objects must be constructed before they can be used, when for some reason you not able to get entry point by static analysis (reading sources), you may perform dynamic methods, like injecting custom code into object constructor, or using debugger and installing breakpoints.

ever if object have no constructor defined, it still have empty constructor named <ctor> at runtime, injecting trace output into <ctor> will highlight all places where object is constructed.

also you must take in account reflection based construction, this is your case:

public static class GameConditionMaker
{
// Token: 0x06003D74 RID: 15732 RVA: 0x0014503A File Offset: 0x0014323A
public static GameCondition MakeConditionPermanent(GameConditionDef def)
{
GameCondition gameCondition = GameConditionMaker.MakeCondition(def, -1);
gameCondition.Permanent = true;
gameCondition.startTick -= 180000;
return gameCondition;
}

// Token: 0x06003D75 RID: 15733 RVA: 0x0014505C File Offset: 0x0014325C
public static GameCondition MakeCondition(GameConditionDef def, int duration = -1)
{
GameCondition gameCondition = (GameCondition)Activator.CreateInstance(def.conditionClass);
gameCondition.startTick = Find.TickManager.TicksGame;
gameCondition.def = def;
gameCondition.Duration = duration;
gameCondition.uniqueID = Find.UniqueIDsManager.GetNextGameConditionID();
gameCondition.PostMake();
return gameCondition;
}
}


and defs have exactly same field references as code:

  <GameConditionDef>
    <defName>SolarFlare</defName>
    <conditionClass>GameCondition_DisableElectricity</conditionClass>
    <label>solar flare</label>
    <description>A solar flare is blasting the planet. The electromagnetic interference will prevent most electrical devices from working.</description>
    <endMessage>The solar flare is ending.</endMessage>
    <letterText>A solar flare has begun.\n\nThe intense radiation will shut down all electrical devices.\n\nIt should pass in about a day.</letterText>
    <letterDef>NegativeEvent</letterDef>
    <canBePermanent>true</canBePermanent>
  </GameConditionDef>


searching sources with keyword
conditionClass

will point you to places, that use that field and related to actually constructing condition class.