WeaponsAndOutfits [Patch WIP] - Assign weapons just like apparel! [OLD]

Started by EntityFramework, December 17, 2018, 07:16:49 PM

Previous topic - Next topic

EntityFramework

This mod has been released
forum link: https://ludeon.com/forums/index.php?topic=47700.0
----------------------------------------------------------

Weapons And Outfits


Description of the mod:

This gives the pawn the possibility to assign weapons to outfits, just like apparel.

Just like the apparel filter you have in the outfit manager menu, you will have one for weapons (equipment).Quality and hitpoints percentage filters works for this too (Since the method allows of the thingfilter class does so) . The idea is to just pick a few from the filter so that you can switch weapons quickly when raided (like hunter outfit -> Battle outfit) etc.

The pawn then will check if he is equipping that weapon. If true he will do nothing, otherwise he will look for the first weapon in his filter list available to pick up from storages. He will just go to the weapon, throw the one he is equipping, equip the desired one, and opportunistically will haul the weapon to the correct storage

--------------------------------------------------------
Patching problems [Skip this if you don't care about it ]

I have been having  quite a stressful lot of problems patching it with or without Harmony, and also considering that some of the classes involved have not def associated it and adding new class fields is not possible with harmony. Using xpath operations can be possible if it weren't that, again, some of the classes have no direct def association (like Dialogs). Just so you can know.. It took less time to write the code and recompile the assembly than figuring out how to patch it.

Long story short: I don't have the time, patience  or the knowledge right now to work it out

This is the reason it is still a Patch WIP. If you want to use this mod, just overwrite the assembly-CSharp.dll in your  /Managed folder with the one provided in the github repository

If you want to know the code involved.. ,again, look in the github repository below ; who knows, some more advanced modders might take it to the next level by patching it, if requested by popular demand.
Note that I would happily work in the patching in collaboration mode with other modders.

Assembly recompilation is just fine.

--------------------------------------------------------

Compatibility:

I have tested it quite a while with this modlist and had no problems:

<activeMods>
    <li>Core</li>
    <li>HugsLib</li>
    <li>BetterPawnControl</li>
    <li>PathAvoid</li>
    <li>While You are Up</li>
    <li>PickUpAndHaul</li>
    <li>P-Music</li>
    <li>HeatMap</li>
    <li>MedicalTab</li>
    <li>AvoidFriendlyFire</li>
    <li>Pharmacist</li>
    <li>RimworldSearchAgency</li>
    <li>AreaUnlocker</li>
    <li>Miscellaneous_TrainingFacility</li>
    <li>PriorityClean</li>
    <li>MoreHarvestDesignators</li>
    <li>kNumbers</li>
    <li>Blueprints</li>
    <li>GearUpAndGo</li>
    <li>SnapOut</li>
</activeMods>


It greatly benefits from BetterPawnControl as you can imagine.

Incompatibility:

This mod doesn't change the existing functionality, but it expands it.. except maybe in the sense that the outfit and the dialogManager instances have an extra field property... I think then that It shouldn't be incompatible with any mod that wouldn't use code transpilation in the following classes

Outfit.cs
Dialog_ManageOutfits.cs
JobGiver_OptimizeApparel.cs


UPDATE: Fixed some problem with the quality and hitpoints filters.. but I had to modify another class in the Verse namespace

ThingFilterUI.cs


EDIT: The assembly is for 64 bit version of rimworld.. if requested I will make the same for the 32 bit version!
--------------------------------------------------------

Instructions

1- ALWAYS backup the assembly-CSharp.dll located in your game's Managed folder

2- Overwrite that file with the one in the github's repository

3- Play

--------------------------------------------------------

Github: https://github.com/ErnestUTN/Rimworld_WeaponsAndOutfits

Credits-
Rimworld's Discord Mod Development channel  for all the help regarding modding the game :)

[attachment deleted due to age]


VisseNekku

Fantastic mod.  ;D I'm so glad someone has been doing this.
I've been having a problem though that the settings seem to reset every time I load a save. No idea why that is happening.

EntityFramework

#3
Quote from: Heymom on December 27, 2018, 11:35:34 AM
Looks good, keep up the work :D
Thanks, I'll try to fix the bugs of it in vanilla code before going into the patching process

Quote from: VisseNekku on December 30, 2018, 09:51:31 PM
Fantastic mod.  ;D I'm so glad someone has been doing this.
I've been having a problem though that the settings seem to reset every time I load a save. No idea why that is happening.

Thanks for pointing that out, I had once seen that problem too, but I thought it was just coincidence.. I'll look into that these days!
EDIT: It happened to you with the weapons filter, the equipment filter, or both?

5thHorseman

I kinda fell off Rimworld after playing for multiple hundred hours over the past few months. This is the kind of mod that would bring me back.

Weapon management has always driven me nuts. Why can they decide what parka to wear but can't pick a gun?

One question, you say in the OP that the pawn picks the first gun he finds that matches. First how? Closest? First in the alphabet? I'd love it if they go by - say - dps or something like that. Or just raw damage.
Toolboxifier - Soil Clarifier
I never got how pawns in the game could have such insanely bad reactions to such mundane things.
Then I came to the forums.

EntityFramework

#5
Quote from: 5thHorseman on January 01, 2019, 03:05:49 AM
I kinda fell off Rimworld after playing for multiple hundred hours over the past few months. This is the kind of mod that would bring me back.

Weapon management has always driven me nuts. Why can they decide what parka to wear but can't pick a gun?

One question, you say in the OP that the pawn picks the first gun he finds that matches. First how? Closest? First in the alphabet?

Glad you think likewise, in the sense that these Quality of Life mod should be vanilla already! :P. I should update the OP because the way it searches for weapons is just like appearel but disregarding temperature conditions (AFAIC and from reading the code, the pawn will smart- select from the filter list the appearel based on temperature needed to be comfortable)..

I'm not sure for for weapons I think then  it depends on location, danger to acquire it, reservations for that weapon (if someone asked for that gun, and there is no more left of that type, then the pawn will try to look for other type of weapon), if it is burning, if it is in a player own storage, etc.

QuoteI'd love it if they go by - say - dps or something like that. Or just raw damage.
There's a quite new mod being developed called "Outfitted" which  has what you want but for apparel.. The dev is considering adding weapons so it would be far superior to this in that sense :P. Right now I'm like putting the what-should-have-been-in-vanilla features.

EntityFramework

#6
@VisseNekku I seem to have found the problem. I added a method to save the equipment filter, just like apparel. The problem is that you  need  to delete all existing outfits (Sorry about that ) and recreate them again (but now with the weapons). Old outfits are broken from what I have tested.

I hope to find a way to make the old outfit system be converted to the new one without this problem

VisseNekku

Quote from: EntityFramework on January 01, 2019, 03:26:50 AM
@VisseNekku I seem to have found the problem. I added a method to save the equipment filter, just like apparel. The problem is that you  need  to delete all existing outfits (Sorry about that ) and recreate them again (but now with the weapons). Old outfits are broken from what I have tested.

I hope to find a way to make the old outfit system be converted to the new one without this problem

Oh, I'll see if that works out.  :) No need for sorries! I'm glad there is a solution. Thanks for quick reply.

EntityFramework

No problem :) . But First! , do a different save after deleting all outfits because Im just about to update the assembly so as to allow old system outfits to work with new ones.. in a few minutes I'll upload it. Then you can use the previous save where you had your old outfits

Roolo

Cool mod. If you still want to get your mod working by patching instead of overwriting the dll, just contact me on Discord (username: Roolo), I can likely give you some advice to get you further.

Quoteadding new class fields is not possible with harmony
This is indeed true an can be a severe limitation. However, you can work around this limitation by creating a dictionary containing classes with the extra fields you need. You can find an example in my Giddy-up mod: https://github.com/rheirman/GiddyUpCore/tree/master/Source/Giddy-up-Core/Storage. In the example ExtendedPawnData objects are used to store extra fields for Pawn objects, but in fact it can be used for almost anything. Do note that the Hugslib library is used for saving the dictionary, but it should be possible without hugslib.

edit: just for completeness, I originally took the code I'm referring to from the SimpleSideArms mod and re-purposed it for my mod.

EntityFramework

#10
Quote from: Roolo on January 01, 2019, 01:30:46 PM
Cool mod. If you still want to get your mod working by patching instead of overwriting the dll, just contact me on Discord (username: Roolo), I can likely give you some advice to get you further.

Quoteadding new class fields is not possible with harmony
This is indeed true an can be a severe limitation. However, you can work around this limitation by creating a dictionary containing classes with the extra fields you need. You can find an example in my Giddy-up mod: https://github.com/rheirman/GiddyUpCore/tree/master/Source/Giddy-up-Core/Storage. In the example ExtendedPawnData objects are used to store extra fields for Pawn objects, but in fact it can be used for almost anything. Do note that the Hugslib library is used for saving the dictionary, but it should be possible without hugslib.

Thank you very much!. I will gladly request your help for it; thanks for the "dictionary"  tip . I'll contact you within this week or weekend probably. I'm also checking all necessary changes are done before moving onto patching them!.

-----

Assembly and code Updated! Now you should be able to keep old apparel outfits presets (thought you need to redefine once again the weapon filter for them)