Ludeon Forums

RimWorld => Mods => Help => Topic started by: SenaCat on March 19, 2017, 05:41:58 PM

Title: How to have a different out of fuel icon
Post by: SenaCat on March 19, 2017, 05:41:58 PM
So I'm probably overstepping my bounds here but I'm curious for myself. https://ludeon.com/forums/index.php?topic=29662.msg319707#msg319707 is a thread with a mod by Thyme that adds a chemfuel powered generator. They lamented that the generator still used the out of fuel log icon. So I made them a chemfuel version of the icon, but I've dug anywhere I can possibly think of that would control what icon the generator uses for the out of fuel state. No joy. Is it stuck in a dll somewhere?
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 20, 2017, 01:09:53 AM
icon itself is not inside DLL, all resources are stored inside "asset" file.

your first stop is "CompRefuelable" (you will need dnspy or similar tool)
(in any case you will need "source" to implement code injection or custom logic)
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 20, 2017, 09:00:52 PM
icon itself is not inside DLL, all resources are stored inside "asset" file.

your first stop is "CompRefuelable" (you will need dnspy or similar tool)
(in any case you will need "source" to implement code injection or custom logic)

Yeah, I got the icon done, so that's sorted. As for the code behind CompRefuelable, where's that actually located so I can go get at it? I did happen to find it called in a .cs for a joy object added by a mod.
Code: [Select]
public CompRefuelable refuelableComp; But it's an object I've not used yet because it's got some extra requirements to use it. Looking at this code, I'm not seeing where it'd call up the graphic. So I imagine this modded item will be something to reference, at least.

I never did like C#, but I know enough to be dangerous, don't be shy with your explanations if need be.
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 21, 2017, 03:39:29 AM
there is no "shy"
i never spoonfeed as long as no proof of work is provided

please open code of CompRefuelable and read it fully, if you do not understand something, ask your question and it will be answered.
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 22, 2017, 04:19:49 PM
there is no "shy"
i never spoonfeed as long as no proof of work is provided

please open code of CompRefuelable and read it fully, if you do not understand something, ask your question and it will be answered.

That's what I'm asking. Where's CompRefuelable kept? Once I can get into it then I can probably figure it out. I've found references elsewhere to it, but they weren't very helpful.
Title: Re: How to have a different out of fuel icon
Post by: jimthenoob on March 22, 2017, 04:51:35 PM
I think it should be located inside of the "Assembly-CSharp" file located @:  ~/RimWorld/RimWorldWin_data/Managed/Assembly-CSharp.DLL .
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 22, 2017, 06:06:31 PM
I think it should be located inside of the "Assembly-CSharp" file located @:  ~/RimWorld/RimWorldWin_data/Managed/Assembly-CSharp.DLL .

Found it, thank you. So I have
Code: [Select]
public override void PostDraw()
{
base.PostDraw();
if (!this.HasFuel && this.Props.drawOutOfFuelOverlay)
{
this.parent.Map.overlayDrawer.DrawOverlay(this.parent, OverlayTypes.OutOfFuel);
}
}

Which is my main interest. The original modder has the generator in an .xml, but I'm assuming that this is going to need to be .cs. Is it possible to slip this code into the original .xml, or does it need to go to it's own .cs? And if that's the case, do I need to define the entire generator in there, or does the .xml's ThingDef cover the basics and I just need the .cs to cover this modification? And with
Code: [Select]
OverlayTypes.OutOfFuel, how would I specify the OutOfChemfuel.png in it's place?
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 22, 2017, 06:25:10 PM
open DrawOverlay and read it's source code, you will see how "outoffuel" image is actually binded and rendered.

then you will need custom CompRefuelable that accept only chemfuel and draw your custom out of fuel image.
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 22, 2017, 09:32:36 PM
open DrawOverlay and read it's source code, you will see how "outoffuel" image is actually binded and rendered.

then you will need custom CompRefuelable that accept only chemfuel and draw your custom out of fuel image.

Alright, so I'll need to build my CompRefuelable, probably tomorrow but I have what I need there I think. As for the graphic asset itself, I have a .png done. When I see
Code: [Select]
private static readonly Material OutOfFuelMat = MaterialPool.MatFrom("UI/Overlays/OutOfFuel", ShaderDatabase.MetaOverlay); in OverlayDrawer, is it assuming that OutOfFuel is a .png? And if so, to follow their file path, would I want it to be "Chemfuel Generator\UI\Overlays\OutOfChemfuel.png?" in my mod folder?

[attachment deleted by admin due to age]
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 22, 2017, 10:10:48 PM
this is not advised because will affect all fuel based objects, including ones that accepts wood.

if you want "proper" mod you need custom CompRefuelable
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 22, 2017, 10:36:44 PM
this is not advised because will affect all fuel based objects, including ones that accepts wood.

if you want "proper" mod you need custom CompRefuelable

I think you misunderstood me. I'm planning on making a custom CompRefuelable. I'm just making sure I understand where the OutOfChemfuel image is going to need to go within the generator mod's folder. I.e. the finished mod would be "Rimworld/Mods/Chemfuel Generator\UI\Overlays\OutOfChemfuel.png"
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 23, 2017, 03:48:44 AM
you can place it anywhere, just make sure that your code have same path
Title: Re: How to have a different out of fuel icon
Post by: SenaCat on March 23, 2017, 04:52:57 PM
you can place it anywhere, just make sure that your code have same path

Alright. So I'm building my CompRefuelable. In regards to the code in DrawOverlay that pulls the .png from the proper folder, assigns it to a Material and sets that Material to be the one used when out of fuel. Do I take that and put it into my version of CompRefuelable?
Title: Re: How to have a different out of fuel icon
Post by: RawCode on March 23, 2017, 09:54:51 PM
copypaste payload of DrawOverlay directly into your class and adjust bindings.

DrawOverlay is static prebind class and it will not accept new overlays without code injection.
Title: Re: How to have a different out of fuel icon
Post by: Cayprol on July 24, 2017, 12:52:00 AM
Hi, I know this is a old thread, but as I am trying to learn how to do the exact same thing, I suppose there's no point to start a new topic.

Since I cloned the original CompRefuelable and change all names to CompRefuelableChem while creating a new method in this class with everything identical to DrawOverlay.

I don't understand how vanilla graphics are bind to this method and the way to adjust it.
Code: [Select]
        public void DrawOverlay(Thing t, OverlayTypes overlayType)
        {
            if (OverlayDrawer.overlaysToDraw.ContainsKey(t))
            {
                Dictionary<Thing, OverlayTypes> dictionary;
                Dictionary<Thing, OverlayTypes> expr_17 = dictionary = OverlayDrawer.overlaysToDraw;
                OverlayTypes overlayTypes = dictionary[t];
                expr_17[t] = (overlayTypes | overlayType);

            }
            else
            {
                OverlayDrawer.overlaysToDraw.Add(t, overlayType);
            }
        }
Could anyone possibly explain it more into details to me.
particularly why it is using a bitwise operator?
Thank you.
Title: Re: How to have a different out of fuel icon
Post by: RawCode on July 24, 2017, 09:57:22 AM
use Console.WriteLine to emit into log code lines you do not understand

in your case Console.WriteLine(overlayTypes | overlayType);

this is very easy and fast way to get information about what exactly code does and how conditions are resolved.
Title: Re: How to have a different out of fuel icon
Post by: Cayprol on July 28, 2017, 04:10:00 AM
After a few days of trying, not sure if I am getting this, please enlighten me a bit more.
I am a total newbie, probably some more details a long the way.

I suppose it was creating 3 dictionaries, the if statement is checking whether a predefined OverlayTypes enum is in there or not, else it would add a new Thing paring OverlayTypes.
So, the goal here is to pass Thing(Chemfuel) and a new OverlayTypes(OutOfChemfuel) into the dictionary from else statement, Correct?

Bitwise | would result the enum name and the matching OverlayTypes called overlayType.
However, I still don't understand how the actual graphics should be path linked in here.
I saw there's the MaterialPool class that would source graphics from the ShaderDatabase.
The next step is to add a new line in static OverlayDrawer() ?

Should I create an entire OverlayDrawer Class if that's the case?

besides the custom compRefuel, a compProperty is also needed to use in XML correct?

thx for the help.

Title: Re: How to have a different out of fuel icon
Post by: RawCode on July 29, 2017, 05:57:16 AM
replace CompRefuelable with custom implementation that render required image over object directly, without using any wrappers over unity engine provided by game period

is this soo hard to understand?
required method postdraw is marked virtual and you do not need code injection to override it.