Ludeon Forums

RimWorld => Releases => Mods => Outdated => Topic started by: Kiame on November 13, 2017, 10:13:54 PM

Title: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Kiame on November 13, 2017, 10:13:54 PM
A patch for Mending (https://ludeon.com/forums/index.php?topic=22894.0) which allows pawns to remove apparel from ChangeDressers (https://ludeon.com/forums/index.php?topic=35632.0).


Mod load order:
Mending (https://ludeon.com/forums/index.php?topic=22894.0) must be before this patch-mod


Steam: B18 (http://steamcommunity.com/sharedfiles/filedetails/?id=1200683902)

Direct Download:
A17 (https://github.com/KiameV/rimworld-mendingchangedresserpatch/releases/download/A17/MendingChangeDresserPatch.zip)
B18 (https://github.com/KiameV/rimworld-mendingchangedresserpatch/releases/download/B18/MendingChangeDresserPatch.zip)


Github (https://github.com/KiameV/rimworld-mendingchangedresserpatch/)


Like my mods? Consider supporting me!
(https://i.imgur.com/i08683D.png) (https://ko-fi.com/kiamev)


(https://steamuserimages-a.akamaihd.net/ugc/874124100364790730/5402112D6739E3BDF10697C08BF371CC07912092/)

(http://verify.modsync.ninja?bd13b164-afc0-4bdd-8c97-87d11f30c9cf) (http://www.modsync.ninja)
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Nightinggale on November 13, 2017, 11:41:04 PM
Nice work. Allowing those two mods to work together is something, which I have been wishing for  :D

Quote from: Kiame on November 13, 2017, 10:13:54 PMOnly supports Change Dresser - BETA (https://ludeon.com/forums/index.php?topic=35632.0) (A17+)
the older version of ChangeDresser is not supported.

Mod load order:
Mending (https://ludeon.com/forums/index.php?topic=22894.0) must be before this patch-mod
This is precisely what I wrote ModCheck (https://ludeon.com/forums/index.php?topic=36534.0) for (well that and actual conditional patch operations depending on presence of other mods). The following should display an error if the mods aren't set up correctly, which not only makes it easier for users to get it right, it should also prevent people from posting about problems due to not having the right order.
<Operation Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="ModCheck.isModLoaded">
<modName>Change Dresser - BETA</modName>
<yourMod>Mending Change Dresser Patch - A17</yourMod>
<errorOnFail>true</errorOnFail>
</li>
<li Class="ModCheck.isModLoaded">
<modName>Mending</modName>
<yourMod>Mending Change Dresser Patch - A17</yourMod>
<errorOnFail>true</errorOnFail>
</li>
<li Class="ModCheck.loadOrder">
<modName>Mending</modName>
<yourMod>Mending Change Dresser Patch - A17</yourMod>
<errorOnFail>true</errorOnFail>
</li>
</operations>
</Operation>


While ModCheck (https://ludeon.com/forums/index.php?topic=36534.0) supports adding patchmods into the main mod itself, I only considered xml patches. In this case it's a DLL, which injects into another DLL. This takes place before PatchOperations are even called meaning there is nothing I can do to make it optional short of a complete redesign and rewrite.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Canute on November 14, 2017, 03:20:59 AM
Kiame,
since i just saw the mending patch, what do you think about a hightech changedresser.
These changedresser need power and can slowly (1-10% each day) repair stuff inside.
Orcouse you need Mending mod and research, and some extra automatic mending research.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Kiame on November 14, 2017, 11:19:33 AM
Ha! i'm sad i didn't think of that!

Let me brainstorm some.


Nightinggale
Thanks i'll take a look at that
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Kiame on November 15, 2017, 01:21:20 AM
Quote from: Canute on November 14, 2017, 03:20:59 AM
Kiame,
since i just saw the mending patch, what do you think about a hightech changedresser.
These changedresser need power and can slowly (1-10% each day) repair stuff inside.
Orcouse you need Mending mod and research, and some extra automatic mending research.

A18 version of change dresser now has a mending attachment which can be built which'll do just this. The mending rate may be a little high but the energy cost I hope balances it out. Feedback will be helpful!

https://ludeon.com/forums/index.php?topic=35632.0
QuoteMending Attachment
-Size: 1x1
-Cost 250 steal + 6 components + 20 wood/stone/steel
-Energy: 10 W (not in use) or 300 W (in use)
-Place next to (touching) a Change Dresser to have apparel automatically mended/repaired
-Research Required: Mending & Multi-Analyzer
-Mending (https://ludeon.com/forums/index.php?topic=22894.0) Mod not required (highly recommended though once it's updated to A18)
...
Mending Attachment
Will detect if apparel needs to be mended. Can only mend one apparel at a time. To make the process faster, multiple Mending Attachments can be built around a single dresser but only one apparel will be repair still (it'll be faster though!)
A single Mending Attachment can also be attached to more than one dresser as long as they're touching.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Canute on November 15, 2017, 03:54:31 AM
Nice work, now A18 just need to be released ! :-)

QuoteA single Mending Attachment can also be attached to more than one dresser as long as they're touching.
With touching  the dresser, you either end up with cross setup with the mending in the middle, or behind each dresser an attachment.

It is maybe possible to made these attachments like toolbox for workbenches, so they auto. link to dresser in the surrounding, and max. 2 attachment can link to 1 dresser. Same like the toolbox.

Title: Re: [A17] Mending ChangeDresser Patch
Post by: Kiame on November 15, 2017, 11:10:19 AM
Quote from: Canute on November 15, 2017, 03:54:31 AM
Nice work, now A18 just need to be released ! :-)

QuoteA single Mending Attachment can also be attached to more than one dresser as long as they're touching.
With touching  the dresser, you either end up with cross setup with the mending in the middle, or behind each dresser an attachment.

It is maybe possible to made these attachments like toolbox for workbenches, so they auto. link to dresser in the surrounding, and max. 2 attachment can link to 1 dresser. Same like the toolbox.

It wouldn't be difficult. I just liked the concept that the mending attachment would 'physically' pull the apparel out of the touching dressers. Also if the desire is to only fix apparel in one dresser it would be easier to manage by touching. I will consider this though.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Canute on November 15, 2017, 12:29:26 PM
Yep, only 1 apparel in 1 dresser should be mended.
I just wanted a bit more placing variation, beside cross setup, or placing the attachment behind the dresser.

Another thing.
Normaly you need mending kits to mend stuff. And i think that still  cheap but balanced at this way.
But when you attachment just need power, i would place a few of them just to mend stuff primary.
So maybe you need to fuel up these with mending kits too.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Kiame on November 15, 2017, 12:49:28 PM
I was considering that but it runs into issues like requiring Mending mod be installed (which some may not want). My hope is that the power requirement will be a large enough tradeoff - 300 is sizable (assuming no mods that add larger power sources) but I could see about increasing it to 500 or even 1000 W (1,000 i htink is too high though).
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Nightinggale on November 15, 2017, 01:00:16 PM
Quote from: Canute on November 15, 2017, 12:29:26 PM
Yep, only 1 apparel in 1 dresser should be mended.
I assume that's one at a time, meaning once the item has 100% health, it moves on to the next one and over time everything will be 100%.

Quote from: Canute on November 15, 2017, 12:29:26 PMNormaly you need mending kits to mend stuff. And i think that still  cheap but balanced at this way.
But when you attachment just need power, i would place a few of them just to mend stuff primary.
So maybe you need to fuel up these with mending kits too.
Remember that there are two mending mods and only one of them use mending kits.

Quote from: Kiame on November 15, 2017, 12:49:28 PM
I was considering that but it runs into issues like requiring Mending mod be installed (which some may not want). My hope is that the power requirement will be a large enough tradeoff - 300 is sizable (assuming no mods that add larger power sources) but I could see about increasing it to 500 or even 1000 W (1,000 i htink is too high though).
This mod patches the mending DLL, meaning the auto repair building would fit best inside this one rather than the dresser mod. If you need to make something conditional based on the presence of mending kit thingdef, then that should be doable too, either with vanilla PatchOperationFindMod (https://ludeon.com/forums/index.php?topic=36208.msg375367#msg375367) (A18 only) or ModCheck for xml and if it needs to be a check in C#, then I should be able to make the code for that as well without too much hassle.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Canute on November 15, 2017, 01:05:25 PM
A few mods got ingame checks if some item/recipe exist or not.
Fertile field/Vegetable garden at example.
Why you don't do the same.
Add your own mending kit, and do a check if another mending kit exist, then disable your recipe/item.
And add both mending kits to the fuel list for the attachment.

And power is relativ, 1000 is just one fueled generator.
And at my last colony with Ramtomics mod, i got 30k power surplus (ok you need these power for the weapons for these mod).
But i would definitv build a fueled generator to have an attachment mend my stuff, special when a pawn don't need to do it.
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Kiame on November 15, 2017, 01:07:32 PM
Just to be clear the conversation around mending is for the a18 update of change dresser, not this mod  :)

It is possible to add diffs conditionally though my current hope is to avoid the overhead as i would like the tradeoff to be the extra power needed - extra power costs more resources than making stacks of mending kits

Fair point canute. And since the mending attachment is later in the game 1k power is not as outrageous. Ive been playing tribal starts lately and i spend so much time w/ lower power 300 seems like a lot   :P
Title: Re: [A17] Mending ChangeDresser Patch
Post by: Nightinggale on November 15, 2017, 01:25:39 PM
Quote from: Kiame on November 15, 2017, 01:07:32 PMIt is possible to add diffs conditionally though my current hope is to avoid the overhead as i would like the tradeoff to be the extra power needed - extra power costs more resources than making stacks of mending kits
I'm with you on this one. Since it's something, which happens frequently in the background (every X ticks presumably), it shouldn't require too much CPU power. If all it does is searching through the list to identify something, which needs mending and then work a bit as well as switch between high and low power usage, the CPU load will be less than if it starts to search for items in stockpiles, adds a job to make colonists feed it with items or anything of that sort.

Quote from: Kiame on November 15, 2017, 01:07:32 PMFair point canute. And since the mending attachment is later in the game 1k power is not as outrageous. Ive been playing tribal starts lately and i spend so much time w/ lower power 300 seems like a lot   :P
You can mix this with other mods, which allows you to turn power on and off based on battery levels, time, outdoor light level etc and none of this is highly advanced relative to mending. As a result, it will be possible to mend say 4 hours each day or only when solar panels are active or whatever you can supply the power for if you use this feature in early/mid game. With this in mind, I too would go for something like 1000 power usage when active and then see how well it works ingame.
Title: Re: [B18] Mending ChangeDresser Patch
Post by: Kiame on November 19, 2017, 12:26:09 AM
Updated for B18
Title: Re: [B18] Mending ChangeDresser Patch
Post by: ShadowXIII on November 24, 2017, 03:23:52 PM
Today I got following error while right clicking onto the mending bench with a selected colonist.

Method not found: 'ChangeDresser.WorldComp.get_DressersToUse'.
at (wrapper dynamic-method) Mending.WorkGiver_DoBill.TryFindBestBillIngredients_Patch1 (RimWorld.Bill,Verse.Pawn,Verse.Thing,bool,Verse.Thing&) <0x001df>
at Mending.WorkGiver_DoBill.StartOrResumeBillJob (Verse.Pawn,RimWorld.IBillGiver) <0x0015b>
at Mending.WorkGiver_DoBill.JobOnThing (Verse.Pawn,Verse.Thing,bool) <0x0023f>
at RimWorld.WorkGiver_Scanner.HasJobOnThing (Verse.Pawn,Verse.Thing,bool) <0x0001e>
at RimWorld.FloatMenuMakerMap.AddUndraftedOrders (UnityEngine.Vector3,Verse.Pawn,System.Collections.Generic.List`1<Verse.FloatMenuOption>) <0x00605>
at (wrapper dynamic-method) RimWorld.FloatMenuMakerMap.ChoicesAtFor_Patch2 (UnityEngine.Vector3,Verse.Pawn) <0x00242>
at RimWorld.FloatMenuMakerMap.TryMakeFloatMenu (Verse.Pawn) <0x00125>
at RimWorld.Selector.HandleMapClicks () <0x00179>
at RimWorld.Selector.SelectorOnGUI () <0x00014>
at RimWorld.MapInterface.HandleLowPriorityInput () <0x00033>
at RimWorld.UIRoot_Play.UIRootOnGUI () <0x001ad>
at Verse.Root.OnGUI () <0x000c6>



When I have build a mending bench, some jobs won't be done by the colonists. For example my crafter won't cut stones anymore. After deconstruct the bench, the jobs will be executed again.
Title: Re: [B18] Mending ChangeDresser Patch
Post by: Kiame on November 24, 2017, 04:02:19 PM
Quote from: ShadowXIII on November 24, 2017, 03:23:52 PM
Today I got following error while right clicking onto the mending bench with a selected colonist.

Method not found: 'ChangeDresser.WorldComp.get_DressersToUse'...

When I have build a mending bench, some jobs won't be done by the colonists. For example my crafter won't cut stones anymore. After deconstruct the bench, the jobs will be executed again.

It looks like you do not have ChangeDresser - https://ludeon.com/forums/index.php?topic=35632.0 - installed.
If you're playing B18, get the B18 verison
If you're playing A17, make sure you're using the newer version "Change Dresser - BETA" is the name in the mod manager in game.
Title: Re: [B18] Mending ChangeDresser Patch
Post by: ShadowXIII on November 24, 2017, 04:27:22 PM
Quote from: Kiame on November 24, 2017, 04:02:19 PM
It looks like you do not have ChangeDresser - https://ludeon.com/forums/index.php?topic=35632.0 - installed.
If you're playing B18, get the B18 verison
If you're playing A17, make sure you're using the newer version "Change Dresser - BETA" is the name in the mod manager in game.

I am playing B18 at the moment and I already have installed the B18 Version from Steam Workshop.

This one:

http://steamcommunity.com/sharedfiles/filedetails/?id=1180720623&searchtext=change+dresser

Title: Re: [B18] Mending ChangeDresser Patch
Post by: Kiame on November 24, 2017, 11:46:08 PM
Thanks for reporting the issue ShadowXIII

Looks like when B18 came out as the official version a cross-link i was using got broken.

Direct download and steam uploaded with the fix
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Kiame on December 03, 2017, 07:18:22 PM
Adding ModSync.ninja (http://www.modsync.ninja/) support
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Nightinggale on May 31, 2018, 06:53:11 PM
I have been wondering about this mod and how it conditionally adds harmony patching. I tried to get ModCheck to load a DLL file conditionally and failed to get it working reliably. Still I don't like patch mods and while conditional xml patching works fine with ModCheck, I'm still on the lookout for conditional harmony patching. I have finally come up with an idea, which I think will do the trick.

protected bool isModLoaded(string name)
{
        return ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == name);
}

This method is included in ModCheck 1.6 and does precisely what you would think. It checks if a mod is loaded and it compares against the name tag in About.xml. Since it relies on vanilla code only, it should be safe to copy between mods. I imagine it could be used something like this.
static Main()
{
        if (isModLoaded("Mending"))
        {
                var harmony = HarmonyInstance.Create("com.mendingchangedresserpatch.rimworld.mod");
                // rest of the harmony code
        }
}

Now when the DLL is loaded, if Mending is loaded, it will do the same as the existing DLL. If Mending is not loaded, the static constructor will do absolutely nothing. In other words it should be safe to add this to change dresser and it should work even if Mending isn't loaded. You can't merge the DLL files though as it will use all the harmony code in the DLL and as such makes it problematic to conditionally load just some of it. However there is no issues involved in adding multiple DLLs to a single mod. They will be loaded alphabetically.

Now the really big question is if it works. I haven't actually tested it, but based on my experience in this area, I see no reason why it shouldn't work.
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Kiame on May 31, 2018, 07:21:02 PM
Thanks I'll try that. If it works I'll do that for Weapon Storage as well.

I wonder if I can get a way to only load certain methods with harmony and just wrap it into one mod. Would be wonderful not to have these patches  ;D

Quick correction for the code
protected bool isModLoaded(string name)
{
        return ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name.Equals(name));
}


Equals instead of ==
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Kiame on May 31, 2018, 09:10:20 PM
I think i know how to do it w/o a 'patch mod'. For Change Dresser and Weapon Storage it'd be a huge pain as I'd have to specifiy each method to patch...


// Patch all methods:
var harmony = HarmonyInstance.Create("com.changedresser.rimworld.mod");
harmony.Patch(...);
...
harmony.Patch(...);

if (isModLoaded("Mending"))
{
        // 'Mending' specific patches
        harmony.Patch(...);
}
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Nightinggale on May 31, 2018, 09:16:25 PM
Quote from: Kiame on May 31, 2018, 09:10:20 PM
I think i know how to do it w/o a 'patch mod'. For Change Dresser and Weapon Storage it'd be a huge pain as I'd have to specifiy each method to patch...
That's why I proposed one DLL file for patches to always apply and one for conditional patching. That way it is possible to maintain the simple approach to Harmony inside each DLL file and keep it in the "apply all patches from this DLL file" approach.
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Kiame on June 01, 2018, 01:02:21 AM
Quote from: Nightinggale on May 31, 2018, 09:16:25 PM
Quote from: Kiame on May 31, 2018, 09:10:20 PM
I think i know how to do it w/o a 'patch mod'. For Change Dresser and Weapon Storage it'd be a huge pain as I'd have to specifiy each method to patch...
That's why I proposed one DLL file for patches to always apply and one for conditional patching. That way it is possible to maintain the simple approach to Harmony inside each DLL file and keep it in the "apply all patches from this DLL file" approach.

/Lightbulb

Interesting... going to try that when I have a minute to try  ;D
Title: Re: [B18] [KV] Mending ChangeDresser Patch [ModSync]
Post by: Nightinggale on June 01, 2018, 05:18:47 PM
Quote from: Kiame on May 31, 2018, 07:21:02 PMQuick correction for the code
protected bool isModLoaded(string name)
{
        return ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name.Equals(name));
}


Equals instead of ==
I started researching this and it turns out that == vs .Equals is a hot topic online. Some says it's the same, some says it isn't and some says while it generally isn't, it is when working on two strings. Some says .Equals is slower due to added overhead and some don't. In other words the internet fails to provide a proper answer to this question.

I decided to call both in a loop. While the speed is a bit unstable (expected), all both mostly stayed below 33 ms, hit 32.4 ms multiple times, but none of them went below 32.4. If there is a performance difference, it's hidden in the noise and I'm not going to spend ages analyzing the noise to detect such a minor difference. I added a Dictionary<string, int> and called using ContainsKey. Not counting dictionary building, it managed to do the same in around 6.7 ms. However I suspect the building of the Dictionary takes way longer than a single call, meaning it's an approach for frequent calls.

The next question is what the functional difference is. In this case, apparently nothing. The == is part of the stable release since 1.0 (released on Halloween last year), is well tested and nobody have reported any issues.


One interesting observation I made here is that sometimes a test hit 42 ms. Not 44 or 37, but 42 every single time. I suspect this is the lag from moving the process from one CPU core to another. In case you don't know, modern CPUs move 100% loaded threads around frequently to spread the heat production. Say you have a cooling, which can handle 100W. That's 25W/core if they are all loaded. However if only one is loaded, you can use 60*1+5*3 = 75 W. The problem here is that the cooler can't cool 60W from one core, but inserting cooling periods and you get (60+5+5+5)/4 ≈ 19 W on average. More power allows higher clock speed. In my case single core can work 0.5 GHz faster than when using all cores, which still performs better overall even though it suffers from pauses while changing core. It's one of those issues you have to be aware of while benchmarking and one reason why getting reliable readings can be tricky.

This is getting a bit off topic regarding ChangeDresser and more about how to code (including ChangeDresser), but whatever. If the DLL patching idea works, this thread and patch mod will no longer be needed anyway.