Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - battlemage64

#1
My mod's settings involve making settings for certain traits. I hold these in a Dictionary mapping TraitDefs to values of an enum. I try to save the Dictionary inside the ExposeData() of my ModSettings subclass, like so:

public class PCCSettings : ModSettings
    {
[...]
        Dictionary<TraitDef, TraitSetting> traitSettings = new Dictionary<TraitDef, TraitSetting>();
[...]
public override void ExposeData()
        {
[...]
            Scribe_Collections.Look(ref traitSettings, "traitSettings", LookMode.Def, LookMode.Value);
            if (traitSettings == null) traitSettings = new Dictionary<TraitDef, TraitSetting>();
        }


Data saves correctly. However, when the game tries to load the data when the game starts up, it seems to do so before it's loaded the TraitDef data, so I get many copies of this error:
Could not load reference to RimWorld.TraitDef named AnnoyingVoice [or whatever]

At the time of trait loading, DefDatabase<TraitDef>.DefCount is 0, so the Defs really haven't been loaded. But I saved them using LookMode.Def, so I really have no idea what the proper way to save Defs is, if not that. How can I fix this error? Or do I have to work around it and save the defName instead, then manually load it later? (This would be a pain to implement and I'd really rather avoid it if possible.)
#2
Help / [solved] How to patch another mod?
February 18, 2021, 08:02:46 PM
My mod has a conflict with the mod Dubs Apparel Tweaks (henceforth DAT). I can fix the error by using Harmony to add a Postfix to one of the mod's methods, but I'm not sure how to set up the patch. If I have my code reference DAT's .dll file with using QuickFast (QuickFast is the dll filename), then the code throws an error when the mod is not loaded and often fails to load it even if DAT is active. If I do not include this line, the code does not compile at all because I can't run the patching operation:
harmony.Patch(typeof(bs).GetMethod("SwitchInside"), postfix: new HarmonyMethod(typeof(RBHarmonyDubsRendererPatch).GetMethod("Postfix")));
(Note that bs is the type containing the method SwitchInside that I want to patch, defined in QuickFast.dll, so without the using statement the type is not recognized. RBHarmonyDubsRendererPatch is defined in my code.)

What is the proper way to add a Harmony patch to another mod's code? The documentation claims it can be done but does not explain how.
#3
Tired of colonists getting mad about being left out in the rain? Keep them happy and dry with this fantastic new invention: the umbrella! Craftable from any kind of fabric, umbrellas will keep people dry as well as being worth a lot on the market as a symbol of style and fashion!

-ITEMS-
Adds five umbrellas of various uses and tech levels:

-Umbrella: the basic umbrella, a canopy on a pole. You don't need research to make this -- just enough knowledge to weave fabric and put it on a stick. It's useful but not especially nice.

-Parasol: Just as simple as the umbrella, but this one is a fashion statement! Have your parasol decorated by an artist and give it to a colonist for a small social impact bonus! Requires complex clothing research to make.

-Foldable umbrella: Much less cumbersome and bulky, the foldable umbrella is worth more and gives a small social boost due to its flashy display of manufacturing technology. Requires knowledge of machining to produce the small catches and bars needed to construct one. Also requires a small amount of steel to craft.

-Foldable parasol: a parasol, but foldable. Gives bonuses for both a parasol and a foldable umbrella. The ultimate in overhead artistry. Also requires machining and a small amount of steel.

-Steel umbrella: an armored umbrella, constructed mostly of steel, that will turn aside bullets (sometimes) but is VERY unwieldy. When held over one's head, it protects them from headshots, converting any sharp damage into blunt damage and preventing most instant kill shots to the head. However, a colonist carrying this will be encumbered and very slow. Requires plate armor research.

Umbrellas are made at a tailoring bench, except the steel umbrella which is made at a smithy.

-COMPATIBILITY-
This mod is compatible with existing saves, but should not be removed from saves containing it.
Mod compatibility: This mod may not work with mods that add modified pawn types, like cyborgs or aliens, or mods that modify graphics or pawn thoughts. If you find an incompatibility, let me know and I'll do my best to make it compatible.

-REQUIREMENTS-
Requires Harmony 2.0.

-DOWNLOADS-
Github: https://github.com/battlemage64/Rimbrellas/
Steam Workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=2079784964

If you have questions, suggestions, or bug reports, please leave them in the Steam Workshop item if possible, because I'm much more likely to see it. I'll probably see it here (eventually) as well.
#4
I want to make a piece of apparel have fully random colors without being tinted based on what it's made out of. Currently my def has this code:
    <colorGenerator Class="ColorGenerator_Options">
      <options>
        <li>
          <weight>1</weight>
          <min>(0.5,0.5,0.5,1)</min>
          <max>(1.0,1.0,1.0,1)</max>
        </li>
      </options>
    </colorGenerator>


I thought this would make the color random and not material-tinted because it doesn't use ColorGenerator_Apparel, but this is not the case. The color of the apparel is still primarily based on the material, which looks okay but not very colorful because most of the materials are drab leather. Is there a way (XML or C#/Harmony) I can make the apparel color ignore its material?
#5
I'm making a joke mod that replaces "bill" (as in a colonist crafting bill) with "william". Unfortunately XML patches can't modify LanguageData, so I'm trying to use Harmony to patch Translator.Translate(this string key) so it replaces any instance of "bill" with "william" in the result. Unfortunately I don't really know how to use Harmony, especially with the recent update, and my code doesn't seem to run at all, although there are no errors. Here's my code:
using System;
using RimWorld;
using HarmonyLib;
using Verse;
public class WilliamHarmonyPatcher {
    public static void DoPatching() {
        Log.Message("code is running");
        var harmony = new Harmony("battlemage64.WilliamInitiative");
        harmony.PatchAll();
    }
}
[HarmonyPatch(typeof(Translator))]
[HarmonyPatch("Translate")]
public class Patch {
    static void Postfix(ref TaggedString __result) {
        Log.Message("patch running...");
        if (__result.RawText.Contains("billiards")) {
            __result = __result.Replace("billiards", "williards");
        }
        else if (__result.RawText.Contains("Billiards")) {
            __result = __result.Replace("Billiards", "Williards");
        }
        __result = __result.Replace("bill", "will");
        __result = __result.Replace("Bill", "Will");
    }
}

The project has 0Harmony.dll (version 2, no local copy) as a reference as well as the usual Assembly-CSharp.dll.
Neither of the log messages display anything and nothing is changed in the text, which is how I concluded the code isn't running. As far as I can tell, this code matches what's on the Harmony documentation, and I can't figure out what to change. Can anyone help?
#6
Help / Modifying game base code
February 18, 2020, 08:53:53 PM
Is there a way to modify/rewrite a class in the game's base code? For my mod I want to modify the code of the Pawn_MindState class (specifically just a few lines) but I'm not sure how to patch/modify it (or if I have to overwrite it completely, how to do that). Is such a thing possible? If not, is there a workaround?

edit: maybe Harmony would work for this? If so can someone link a tutorial on how to use it because the description sounds like it would work but I have no idea how to use it.
#7
I want to modify the code that gives a pawn the Soaking Wet thought, which means finding where pawns are given the SoakingWet thought. SoakingWet is the exposedThought for the WeatherDef of rain, and the traversedThought for water floors, but I can't actually find references to either exposedThought or traversedThought anywhere in the code except for in the class declarations for WeatherDef and TerrainDef. Literally not a single mention (I used grep -i -lr to search for them and it didn't find anything, nor ILSpy or Visual Studio). I've looked through every method even tangentially related to weather, and I can't find a single mention. But it has to happen somewhere, because pawns get the Soaking Wet thought at some point! I'm out of places to look and I'm sorry to ask for help on something so trivial, but can anyone locate what bit of code (and in what class/method) actually gives this thought?

UPDATE: Found it! It's handled in Pawn_MindState. I couldn't find it because my decompiled code was from a previous version with some subtle differences and my version of ILSpy was bugged (reinstalled ILSpy and decompiled again and found it 10 sec later)
#8
Help / How to save a variable?
January 15, 2020, 07:32:45 PM
I have two (possibly three) IDictionaries as part of a MapComponent, each recording a count of a certain timer for each pawn (for example, one is a dictionary where each Pawn has an int counting up to a certain value). I need to save these so they aren't reset to new each time, as they currently are. How do I add them to the player's save file?
#9
Mods / How to save a variable?
January 15, 2020, 07:32:07 PM
I have two (possibly three) IDictionaries as part of a MapComponent, each recording a count of a certain timer for each pawn (for example, one is a dictionary where each Pawn has an int counting up to a certain value). I need to save these so they aren't reset to new each time, as they currently are. How do I add them to the player's save file?
#10
I'm calling a method from inside a MapComponent to give a pawn a Hediff and a Thought. The Hediff works fine, but when I try to call pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfStubToe.StubbedMyToe), I get an error: Object instance not set to an instance of an object. The only object I see that could be causing that is ThoughtDefOfStubToe.StubbedMyToe, and the code for it is functionally the same as the code for the Hediff (StubbedDef):

namespace StubToe
{
    [DefOf]
    public static class HediffDefOfStubToe
    {
        /* Medical conditions */
        public static HediffDef StubbedDef;
    }
    public static class ThoughtDefOfStubToe
    {
        public static ThoughtDef StubbedMyToe;
    }
}


Both are defined in XML correctly, here's the def for the thought:
<ThoughtDef>
<defName>StubbedMyToe</defName>
<durationDays>0.25</durationDays>
<stackLimit>300</stackLimit>
<stackedEffectMultiplier>0.50</stackedEffectMultiplier>
<stages>
<li>
<label>stubbed my toe</label>
<description>I stubbed my toe. Ouch! That sucked.</description>
<baseOpinionOffset>-3</baseOpinionOffset>
</li>
</stages>
</ThoughtDef>

The error always appears when trying to give a pawn the thought, but never when giving the pawn the Hediff. Does anyone know how to fix this?
#11
Help / GameCondition description modification
June 08, 2018, 08:24:33 PM
I have a game condition where two factions declare war on each other. I'd like to either put the faction names in the GameCondition description (which would need to be done in the XML because in C# it's read-only), or in the Factions tab. How do I do either of those?
#12
Help / How do I save a list?
June 04, 2018, 06:51:12 PM
I have a list of special faction relations that I need to save in a save file so when a save is loaded they return. What's the best way to save a List (List<List<Faction>> to be precise) to the XML save file and load it again later?
#13
I'm playing modded RW and I have a bug where when I select a caravan on the world map, I can't select anything else on the map. All I can click are the colonist bar and the World tab. To fix the issue, I have to go back to my base view through the Colonist bar, then right-click on a colonist to select my base on the world map. Then it's fine until I click a caravan again.

EDIT: BTW I have to double-click on the colonist bar for it to do anything.

EDIT 2: reloading seems to have fixed it, but it's happened before, so it might come back.

EDIT 3: It's back! And I can't view caravan info btw.

Mod list: HugsLib, Giddy-up! Core, Giddy-up! Ride and Roll, Giddy-up! Battle Mounts, Giddy-up! Caravan, Path Avoid - A18, [KV] Refugee Stats - B18, I Can Fix It!, While You're Up, [KV] Trading Spot - B18, Animals Logic, RunAndGun, Pick Up And Haul, Hand Me That Brick, What Is My Purpose, Just Ignore Me Passing, Biomatter, Dinosauria, CleaningArea, Sometimes Raids Go Wrong, HolyWasher, Pharmacist, Megafauna, RimQuest, Let's Trade!, Prison Labor, ClosedDoors, More Vanilla Turrets [B18], Quarry, GeneticRim b18, More Lances, Heat Map, GlitterWorld Prime [B18]
#14
Bugs / Phantom sound effect
May 19, 2018, 07:24:52 AM
I just had the letter alert sound randomly play with no letter or message. I checked my colonists and caravans, and all were fine. However, the sound definitely played. That's all I know.
#15
Help / Custom damage amounts?
April 18, 2018, 09:32:13 PM
I'm using this command to give a minor injury to a colonist's toe. Everything works, except no matter what I do the damage is 0.5. How can I set how much damage it does?

target.health.AddHediff(HediffDefOf.Bruise, toe, new DamageInfo(def: DamageDefOf.Blunt, amount: 1, hitPart: toe));

I feel like amount: (whatever) should set it, especially after reading the source, but it doesn't seem to.

#16
Help / How do I make a drop pod?
April 16, 2018, 07:55:19 PM
I want to, using C#, spawn a drop pod with a set target X and Y and a set cargo. How do I do this? Can't figure out how to spawn it or set its contents.
#17
I'm really curious as to how the map is originally procedurally generated. I tried writing my own planet generator for fun, but I couldn't get realistic-looking continents, and when I looked up a better way, it was very complicated. Anyone know what Tynan did?
#18
Help / Play song with C#
February 15, 2018, 08:51:41 PM
Can I play a certain song with C#? I want to have custom songs for events like raids and biomes.
#19
Help / Some traits don't have a TraitDef
January 20, 2018, 08:35:58 PM
I found out that some traits that directly affect a pawn's stat and nothing else (like Careful shooter/Trigger-happy, Nimble, etc.) don't have a TraitDef but are still traits. Instead of a TraitDef, they have a StatDef. If I want to use one as a trait (so I can use the same code as normal traits to give/remove), what do I do? Can I convert them to TraitDefs at all or do I have to write new code for StatDefs?
#20
Help / Listen for a Pyro Break
January 07, 2018, 08:48:14 PM
I want a certain piece of code to execute once every time a pawn has a pyro break. However, pyro break doesn't have a MentalStateDefOf and I don't know how to detect when a colonist starts a break, although I can detect every tick they have it. How do I detect a pyro break, and how do I run something just the first frame they start the break?