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 - Napoleonite

#16
I also noticed that it just saves DefNames and when loading it looks them up in the database. However, ExposeData() is called before the database is loaded... Thus the loading fails...

Haha yes, I also simply re-loaded the data thinking I fixed it. And yes, I also noticed that all settings got cleared this way -.-

Solved it by reverting back to strings instead of ThingDefs...
#17
Yes that's correct, the Dictionary of DrillData's, which in turn Expose this:
            Scribe_Defs.Look(ref ThingDefToDrill, Constants.SETTINGS_PREFIX + ThingDefToDrill.defName + "_DefName");
            Scribe_Values.Look(ref WorkAmount, Constants.SETTINGS_PREFIX + ThingDefToDrill.defName + "_WorkAmount", WorkAmount, true);


I basically have a dictionary of <ThingDef, DrillData (=CustomClass)> which I need saved & loaded. But ONLY loaded AFTER Rimworld's XML-database is fully initialized. This, however, is not that easy it seems. It almost seems easier to manually serialize the dictionary.
#18
Help / DesignatorDropdownGroupDef in 1.1?
March 02, 2020, 12:15:06 PM
<DesignatorDropdownGroupDef>
    <defName>SurveillanceCameras</defName>
</DesignatorDropdownGroupDef>

<!-- in my ThingDef -->
<designatorDropdown>SurveillanceCameras</designatorDropdown>
<uiIconPath>snip</uiIconPath>

Becomes:



In 1.1 the icons worked but in 1.1 they broke. I checked the autogenerated XML documentation but no example was given that is different from mine and this is also not mentioned in the 1.1 upgrade guide for modders. What should I do differently in 1.1?
#19
How do I load&save my
public Dictionary<ThingDef, DrillData> Drillables = new Dictionary<ThingDef, DrillData>();

Note that DrillData inherits IExposable and implements it. The main problem that I have is that DrillData requires the XML-database to be fully loaded before this setting can be loaded. How would I go about this?

Some extra code if it helps (which totally doesn't work at all):

// In my ModSettings:
public Dictionary<ThingDef, DrillData> Drillables = new Dictionary<ThingDef, DrillData>();
        public override void ExposeData()
        {
List<ThingDef> drillableItems = Drillables.Keys.ToList();
            Scribe_Collections.Look<ThingDef>(ref drillableItems, "SEPD_Drillables");
            //Log.Message(keys.Count.ToString());
            drillableItems.ToList()
                .ForEach(td =>
                {
                    if (td != null)
                    {
                        //Log.Message(td.defName);
                        if (!this.Drillables.ContainsKey(td))
                        {
                            this.Drillables.Add(td, new DrillData(td));
                        }
                    }
                    else
                    {
                        Log.Warning("SEPD_OreMissingWarning".Translate().CapitalizeFirst());
                    }
                });
            this.Drillables.Values.ToList().ForEach(d => d.ExposeData());
}


DrillData:
        public void ExposeData()
        {
            Scribe_Defs.Look(ref ThingDefToDrill, Constants.SETTINGS_PREFIX + ThingDefToDrill.defName + "_DefName");
            Scribe_Values.Look(ref WorkAmount, Constants.SETTINGS_PREFIX + ThingDefToDrill.defName + "_WorkAmount", WorkAmount, true);
        }


Hopefully, I'm not too vague or something :P. My English is not that great at this area.
#20
Help / Re: C# add recipe (or 'c#-patch' it)?
February 29, 2020, 03:31:10 PM
Ah, I see.

I got it working using XML-patches applied by C# (why is this not mentioned in the Wiki?).

Thanks, adding:
defaultIngredientFilter = new ThingFilter()
also fixed it! Now I have two ways to go about it + a possible 3rd-way using that comp.
#21
Help / Re: C# add recipe (or 'c#-patch' it)?
February 29, 2020, 02:56:57 PM
I haven't created a translation file yet so, for now, I hardcode them. Later I'll replace them yes.

A recipe doesn't require ingredients. I have XML versions that have no ingredients at all that work just fine. This works (and no ingredients, also none in the base):
<RecipeDef ParentName="myBase">
<defName>drill_myOre</defName>
<label>drill myOre</label>
<description>drill myOre</description>
<jobString>Drilling myOre</jobString>
<workAmount>1000</workAmount>
<products>
<MyOre>15</MyOre>
</products>
</RecipeDef>


I tried adding the line:
ingredients = new List<IngredientCount>(),
but still the same error.

I checked that component but I can't use it because I use bills and recipes instead.
#22
Help / [Solved] C# add recipe (or 'c#-patch' it)?
February 29, 2020, 01:55:43 PM

            //<snip>

            RecipeDef rd = new RecipeDef
            {
                defName = defName,
                effectWorking = DefDatabase<EffecterDef>.GetNamed("Smith"),
                workSkill = DefDatabase<SkillDef>.GetNamed("Mining"),
                workSpeedStat = DefDatabase<StatDef>.GetNamed("MiningSpeed"),
                workSkillLearnFactor = 0.5f,
                jobString = "Drilling" + " " + forthisThingDef.label,
                workAmount = 5000,
                soundWorking = DefDatabase<SoundDef>.GetNamed("Recipe_Machining"),
                label = "Drill" + " " + forthisThingDef.label,
                description = "Drill" + " " + forthisThingDef.label
            };

            rd.products.Add(new ThingDefCountClass(forthisThingDef, 20));
            DefDatabase<RecipeDef>.Add(rd);


Produces the following error when adding it as a bill (everything else seems to work so far):
QuoteException filling window for Verse.FloatMenu: System.NullReferenceException: Object reference not set to an instance of an object
  at Verse.ThingFilter.CopyAllowancesFrom (Verse.ThingFilter other) [0x0001f] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at RimWorld.Bill..ctor (Verse.RecipeDef recipe) [0x00043] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at RimWorld.Bill_Production..ctor (Verse.RecipeDef recipe) [0x00042] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at RimWorld.BillUtility.MakeNewBill (Verse.RecipeDef recipe) [0x0000f] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at RimWorld.ITab_Bills+<>c__DisplayClass10_0.<FillTab>b__1 () [0x0004b] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at Verse.FloatMenuOption.Chosen (System.Boolean colonistOrdering, Verse.FloatMenu floatMenu) [0x00028] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at Verse.FloatMenuOption.DoGUI (UnityEngine.Rect rect, System.Boolean colonistOrdering, Verse.FloatMenu floatMenu) [0x0030e] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at Verse.FloatMenu.DoWindowContents (UnityEngine.Rect rect) [0x000fb] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
  at Verse.Window.InnerWindowOnGUI (System.Int32 x) [0x00165] in <33b99ab6cf5748ec8fe371b3321b9db6>:0
Verse.Log:Error(String, Boolean)
Verse.Window:InnerWindowOnGUI(Int32)
UnityEngine.GUI:CallWindowDelegate(WindowFunction, Int32, Int32, GUISkin, Int32, Single, Single, GUIStyle)

Also, does someone have a link to a tutorial or a good example of how to have C# do this through XML perhaps? Can't I just apply an XML patch instead through C#? I think that would be easier. I'd still like to know how to do both though.

Also, is there an option to inspect the XML database in the game to verify that everything went okay?
#23
Help / Re: [Solved] Patch operations only for Royalty DLC
February 29, 2020, 01:33:25 PM
Perhaps this will also work:
if (ModLister.RoyaltyInstalled) {}
#24
Help / Re: Simple XPath Replace failing
February 29, 2020, 04:30:10 AM
Oh, I assumed that an abstract section would also inherit the base nodes but apparently it doesn't. Meaning there is no way for me to alter the stats at this level, meaning I have no choice but to do it on all individual ThingDef-objects instead. Ouch.

Thanks for the solution.
#25
Help / Re: Simple XPath Replace failing
February 28, 2020, 06:18:28 PM
Yes, that's just a section of it. The XML I'm trying to replace is from Misc Robots++ (from the 1.1 folder). Here is the full xml: https://pastebin.com/Sz3txUPL

- It's so weird because this code worked in 1.0 but in 1.1 it breaks.
- My patch is located in: <mymod>/Patches/Patch.xml which should be correct.
- The only thing that is different from 1.0 as far as I could find is that Misc Robots put everything inside a "1.1" folder.
- My mod loads after the original mod.
I have no idea what I'm doing wrong. Maybe the Assembly file from that mod alters the XML-database before my patch is being applied? That would also be odd.

XPathing the non-abstract objects works, it just does not work for the abstract ones for me. This works:

...
<xpath>Defs/ThingDef[defName="AIRobot_RechargeStation_Hauler"]/statBases/MaxHitPoints</xpath>
...

This does not:
...
<xpath>Defs/ThingDef[@Name="RPP_RechargeStation_II"]/statBases/MaxHitPoints</xpath>
...



It's probably some really stupid mistake somewhere but I can't locate it.
#26
Help / [Solved] Simple XPath Replace failing
February 28, 2020, 09:39:56 AM
The XPath surgery topic seems to be death so I'll post here.

Original XML:
<ThingDef Abstract="True" Name="RPP_RechargeStation" ParentName="Base_X2_AIRobotRechargeStation" Class="AIRobot.X2_ThingDef_AIRobot_Building_RechargeStation">
<minifiedDef>AIRobot_MinifiedRechargeStation</minifiedDef>
<thingCategories>
<li>BuildingsFurniture</li>
</thingCategories>
<fillPercent>0.25</fillPercent>
<costList>
<Steel>20</Steel>
<Plasteel>5</Plasteel>
<RPP_Component>1</RPP_Component>
</costList>
<statBases>
<Mass>13</Mass>
</statBases>
<!-- added abstraction for potential future use -->
</ThingDef>>

<ThingDef Abstract="True" Name="RPP_RechargeStation_II" ParentName="RPP_RechargeStation" Class="AIRobot.X2_ThingDef_AIRobot_Building_RechargeStation">
<statBases>
<MaxHitPoints>50</MaxHitPoints>
<Beauty>1</Beauty>
<MarketValue>1236</MarketValue>
<Flammability>0.8</Flammability>
</statBases>
<rechargeEfficiency>1.2</rechargeEfficiency>
</ThingDef>


XPath:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<Operation Class="PatchOperationReplace">
<xpath>Defs/ThingDef[@Name="RPP_RechargeStation_II"]/statBases/MaxHitPoints</xpath>
<value>
<MaxHitPoints>75</MaxHitPoints> <!-- default is 50 -->
</value>
</Operation>

</Patch>


Error:
QuotePatch operation Verse.PatchOperationReplace(Defs/ThingDef[@Name="RPP_RechargeStation_II"]/statBases/MaxHitPoints) failed.
Verse.Log:Error(String, Boolean)
Verse.PatchOperation:Complete(String)
Verse.LoadedModManager:ClearCachedPatches()
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.<>c:<Start>b__6_1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.<>c:<UpdateCurrentAsynchronousEvent>b__27_0()
System.Threading.ThreadHelper:ThreadStart_Context(Object)
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object)
System.Threading.ThreadHelper:ThreadStart()
#27
Help / Re: Stop traders carrying my buldings/items
February 28, 2020, 09:32:45 AM
Perhaps this will solve it:

           ...
   <tradeability>None</tradeability>
</ThingDef>
#28
Help / [Solved] About.xml Mod incompatibility elements?
February 28, 2020, 08:14:30 AM
QuoteMods can now define other mods that they are incompatible with. The interface will warn players about incompatibilities.
How?
#29
Sorry for the late reply.

Thanks, I added null-checks now.
Odd that we have to use such somewhat complex LINQ just to change a simple xml-value but so be it then.
".AllDefsForReading()" is indeed better.

I don't use Harmony, now idea how to anyway. I created my own helper-functions now for editing the database.
#30
Do all turret-top textures now have to point east instead of north? Or did I do something wrong? I couldn't find this in the patch notes but I probably missed it.

Also, my Vector2, Rect, etc. throw errors in 1.1:
QuoteThe type 'Rect' is defined in an assembly that is not referenced. You must add a reference to assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Does this mean we must reference CoreModule instead of the previous one now?

Mmm should we use a different .Net version now?
QuoteWarning      The primary reference "Assembly-CSharp" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.

The DesignatorDropdownGroupDef doesn't work anymore (it shows steel icons).

Etc.

Also wondering if there is an 1.0 --> 1.1 upgrade guide somewhere already?

UPDATE:
Nevermind, the 1.1 update contains an update guide.