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

Messages - battlemage64

#1
Update: I think using strings is probably a better idea for me anyway (edit: and was pretty easy to implement), so I don't have any conflicts when the mod list changes. Should have thought of that earlier :(
However, if anyone knows why I ran into this earlier, I would still love an explanation! Especially since people might need it in the future
#2
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.)
#3
Help / Re: How to patch another mod?
February 21, 2021, 04:40:25 PM
Never mind, this post helped me:
https://ludeon.com/forums/index.php?topic=29517.msg448123;topicseen#msg448123

I just needed to use Prepare() and TargetMethods() to check if the method exists and patch it.
#4
Help / Re: Mod not loading content
February 19, 2021, 05:23:46 PM
Update: I tried playing with your mod, exactly as it was when I downloaded it, and... it worked for me... the XML loaded fine and I even spawned it in in-game. IDEK why you're getting the error but if anything is different between the .zip you sent and the files you're using, consider using the .zip version I guess...
#5
Help / Re: Mod not loading content
February 19, 2021, 05:16:11 PM
I think you made a mistake with Plants_Cultivated_Farm.xml. Not certain if that's what's causing the error, but it might help?
You forgot to put a <ThingDef> tag in there. This:
<?xml version="1.0" encoding="utf-8"?>
<Defs ParentName="PlantBase">
<defName>Plant_Modded_Test</defName>
<label>Sugarcane Plant</label>
<description>A sugarcane plant</description>
<statBases>
  <MaxHitPoints>65</MaxHitPoints>
  <Nutrition>0.18</Nutrition>
</statBases>
<graphicData>
  <texPath>Things/Plant/RicePlant</texPath>
  <graphicClass>Graphic_Random</graphicClass>
</graphicData>
<selectable>true</selectable>
<pathCost>14</pathCost>
<ingestible />
<plant>
  <dieIfLeafless>true</dieIfLeafless>
  <maxMeshCount>4</maxMeshCount>
  <harvestTag>Standard</harvestTag>
  <harvestedThingDef>RawModdedPlantTest</harvestedThingDef>
  <harvestYield>6</harvestYield>
  <sowTags>
<li>Ground</li>
<li>Hydroponic</li>
  </sowTags>
  <topWindExposure>0.1</topWindExposure>
  <growDays>.1</growDays>
  <visualSizeRange>0.3~0.8</visualSizeRange>
  <wildOrder>2</wildOrder>
</plant>
  </Defs>


should be this:
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<ThingDef  ParentName="PlantBase">
<defName>Plant_Modded_Test</defName>
<label>Sugarcane Plant</label>
<description>A sugarcane plant</description>
<statBases>
  <MaxHitPoints>65</MaxHitPoints>
  <Nutrition>0.18</Nutrition>
</statBases>
<graphicData>
  <texPath>Things/Plant/RicePlant</texPath>
  <graphicClass>Graphic_Random</graphicClass>
</graphicData>
<selectable>true</selectable>
<pathCost>14</pathCost>
<ingestible />
<plant>
  <dieIfLeafless>true</dieIfLeafless>
  <maxMeshCount>4</maxMeshCount>
  <harvestTag>Standard</harvestTag>
  <harvestedThingDef>RawModdedPlantTest</harvestedThingDef>
  <harvestYield>6</harvestYield>
  <sowTags>
<li>Ground</li>
<li>Hydroponic</li>
  </sowTags>
  <topWindExposure>0.1</topWindExposure>
  <growDays>.1</growDays>
  <visualSizeRange>0.3~0.8</visualSizeRange>
  <wildOrder>2</wildOrder>
</plant>
</ThingDef>
  </Defs>


If that doesn't help, you could try:
1) add a LoadFolders.xml (because the only time I've ever gotten that specific error was when I needed to fix my LoadFolder.xml)
2) add placeholder textures (the XML code you wrote references texture files that aren't in your mod yet, maybe the fact that they're not there is causing the error?)

Hope one of those helps! I'm also new to modding though so I could be wrong.
#6
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.
#7
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.
#8
Hmmm, that does look like a simpler way of doing it. I'll try it out. Thank you!
#9
probably? I don't know enough about programming to be sure and my current solution already works so I just left it
#10
That would probably be a better way of doing it, but I expect making a new version of ThingWithComps that's otherwise supposed to function exactly the same would cause some problems. I might try it if my current method stops working, though.
#11
Final update: it works now and I'm not sure why. Basically the patch's code sets the ThingWithComps.DrawColor to a random color, then sets __result equal to the DrawColor. For whatever reason (I'm honestly not sure why) this only sets the color once and then maintains it indefinitely. Anyway, here's my patch code in case anyone else ever needs it:

namespace Umbrellas {
[HarmonyPatch(typeof(Thing), "DrawColor",MethodType.Getter)]
class CompColorableRegardlessOfStuff {
        private static Color RandomColor() {
            return new Color(Random.Range(0f,1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f);
        }
static void Postfix (Thing __instance, ref Color __result) {
            if (__instance.def.Equals(UmbrellaDefOf.Parasol)) {
                __instance.DrawColor = RandomColor();
                __result = __instance.DrawColor;
            }
        }
}
}

(oh yeah btw the mod adds umbrellas in case you couldn't tell)
#12
Update again: I used Harmony to patch Thing.DrawColor (get) to return a random color if the Thing is my item's def. This works well except it's called every tick so the texture is flashing rainbow in GUIs and randomized every time a pawn moves it. As cool as that is, it's not what I want, but it should mean I just have to store the color as a variable and only generate it once, which should be fairly easy. I'm not going to mark this as solved since I haven't really found a good general solution, though.
#13
I made a custom ColorGenerator that always outputs the same color. The game still assigned the default Stuff color to each. Trying an edited version of CompColorable now.
#14
I can't make it a particular color. I'm now working on making either a ColorGenerator or a CompColorable subclass. Will update if anything works.
#15
Huh, I never thought of using DefInjected for LanguageData. Also yes I should have went to Translation but it didn't occur to me bc I've only ever used Mods/Help before. Thank you!  ;D