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

#1
Help / Finding vanilla allow sowing gizmo
November 26, 2016, 11:54:27 PM
When I detour Zone_Growing.GetGizmos(), the allow sowing button disappears. Even when I use the exact code from decompiled source, the button is not there: vanilla code (using Zhentar's ILSpy):

[DebuggerHidden]
public override IEnumerable<Gizmo> GetGizmos()
{
IEnumerator<Gizmo> enumerator = base.GetGizmos().GetEnumerator();
while (enumerator.MoveNext())
{
Gizmo current = enumerator.Current;
yield return current;
}
yield return PlantToGrowSettableUtility.SetPlantToGrowCommand(this);
yield break;
}


I investigated whether Zone_Growing.GetGizmos() should return the allow sowing button and it does;
I commented out the Zone_Growing.GetGizmos() detour and detoured Zone_Growing.SetPlantDefToGrow() with this:

        public void SetPlantDefToGrow(ThingDef plantDef)
        {
            plantDefToGrow = plantDef;


            MethodInfo method = GetType().GetMethod("GetGizmos", BindingFlags.Instance | BindingFlags.Public);
            if (method != null)
            {
                foreach (Gizmo g in (IEnumerable<Gizmo>)method.Invoke(this, null))
                {
                    if (g == null)
                    {
                        Log.Message("Test: gizmo was null");
                        continue;
                    }
                    if (g.ToString() != null)
                    {
                        Log.Message("ToString: " + g.ToString());
                    }
                    if (g.GetType() != null)
                    {
                        Log.Message("GetType: " + g.GetType());
                    }
                }

            }
            else
            {
                Log.Message("Test: can't get method");
            }
            Log.Message("Test: Only SetPlantToGrowCommand");
            Command_SetPlantToGrow but = PlantToGrowSettableUtility.SetPlantToGrowCommand(this);
            if (but.ToString() != null)
            {
                Log.Message("ToString: " + but.ToString());
            }
            if (but.GetType() != null)
            {
                Log.Message("GetType: " + but.GetType());
            }
        }

Which gave this:

ToString: Command(label=Rename, defaultDesc=Rename this zone.)
GetType: Verse.Command_Action
ToString: Command(label=Hide, defaultDesc=Hide/unhide this zone.)
GetType: Verse.Command_Toggle
ToString: Command(label=Delete, defaultDesc=Delete this zone.)
GetType: Verse.Command_Action
ToString: Command(label=Plant: rice plant, defaultDesc=Determine which plant should be sown here.)
GetType: Verse.Command_SetPlantToGrow
ToString: Command(label=Allow sowing, defaultDesc=When disabled, colonists will never sow plants in this zone. They will still harvest.)
GetType: Verse.Command_Toggle
Test: Only SetPlantToGrowCommand
ToString: Command(label=Plant: rice plant, defaultDesc=Determine which plant should be sown here.)
GetType: Verse.Command_SetPlantToGrow


Searching RimWorld's language translations for "allow sowing" gives:

  <CommandAllowSow>Allow sowing</CommandAllowSow>
  <CommandAllowSowDesc>When disabled, colonists will never sow plants in this zone. They will still harvest.</CommandAllowSowDesc>

But searching for CommandAllowSow or allow sowing in Core/Defs or decompiled Assembly-CSharp.dll gives nothing.
Interestingly when you analyse Zone_Growing.allowSow with ILSpy and expand Read By or Assigned By, it does list RimWorld.Zone_Growing.GetGizmos(), but when you look at RimWorld.Zone_Growing.GetGizmos(), it doesn't use Zone_Growing.allowSow as far as I can tell.

I tried JetBrains dotPeek, which gave this:

    [DebuggerHidden]
    public override IEnumerable<Gizmo> GetGizmos()
    {
      // ISSUE: object of a compiler-generated type is created
      // ISSUE: variable of a compiler-generated type
      Zone_Growing.\u003CGetGizmos\u003Ec__IteratorAC gizmosCIteratorAc = new Zone_Growing.\u003CGetGizmos\u003Ec__IteratorAC()
      {
        \u003C\u003Ef__this = this
      };
      // ISSUE: reference to a compiler-generated field
      gizmosCIteratorAc.\u0024PC = -2;
      return (IEnumerable<Gizmo>) gizmosCIteratorAc;
    }

Telerik JustDecompile, which gave this XD:

        [DebuggerHidden]
        public override IEnumerable<Gizmo> GetGizmos()
        {
            Zone_Growing.<GetGizmos>c__IteratorAC variable = null;
            return variable;
        }

ILSpy Version 2.4

[DebuggerHidden]
public override IEnumerable<Gizmo> GetGizmos()
{
Zone_Growing.<GetGizmos>c__IteratorAC <GetGizmos>c__IteratorAC = new Zone_Growing.<GetGizmos>c__IteratorAC();
<GetGizmos>c__IteratorAC.<>f__this = this;
Zone_Growing.<GetGizmos>c__IteratorAC expr_0E = <GetGizmos>c__IteratorAC;
expr_0E.$PC = -2;
return expr_0E;
}



Is the decompiler just missing the code for the button or is the button magicked in somewhere else?
#2
What is the best way of replacing JobGiver_Haul in Animal ThinkTreeDefs?

I have thought of the following options:

  • Do the detour thing with JobGiver_Haul.TryGiveJob(), the only method it has.
  • Do the detour thing with JobGiver_Haul.TryGiveJob(), BUT always give null job. Make a SubTree with insertTab Animal_PreWander to handle hauling.
  • Make a SubTree thing with insertTag Animal_PreMain, make its treeRoot class to always give true and then subNodes are the same thing following the modder hook Animal_PreMain in Animal ThinkTreeDefs until after <!-- Trained behavior: Haul--> and just replace the class in our SubTree. Look at my prototype here: http://pastebin.com/QVKYYyDn

Edit: alternatively to 3, do the same thing but make each a separate SubTree instead of subNodes.
#3
Alpha 17 conversion progress: JTBetterCrashedShips, JTBetterhauling, JTDrill5Eva, JTExport, JTHomemadeBionics, JTMoreAreas, JTMoreHydroponicOptions, JTSavagePrisoners, JTWeRAnimals, JTZoneButtons.
Alpha 16 conversion progress: JTExport, JTReplaceWalls, JTZoneButtons.

JTBetterHauling
Prioritises hauling degradable items then undegradable. You can create areas (humanlike or animal, doesn't matter) with the word "haul" in it to prioritise items in the area, multiple "haul" areas are sorted alphabetical; aHaul will be hauled before dHaul. Then items in the Home area are hauled before items in no areas. Comes with source.

JTBetterHaulingAnimalsJoke
This is meant to be a joke mod. Makes all the animals on the map instantly haul for you. Accidently made this when redoing JTBetterhauling and thought it was pretty funny seeing a bunch of different animals compete to haul all the items for you. Comes with sauce.

JTMoreAreas
Removes area limit and modifies AreaManager GUI to handle more than 5.  Implements an Area Manager/Hub where you can easily edit areas. Comes with source.

JTCopyBills
Copy production table bills and surgery bills. You can mix copy and pasting with similar tables (e.g. electric and fueled smithies). Copy values last until you close the game (i.e. even after loading another save). Supports Crafting Hysteresis. Comes with source.

JTExport
Export and import worktable bills and stockpile settings. Supports Crafting Hysteresis and Enhanced Crafting. Comes with source.

JTReplaceWalls
Replace wall type and doors on the fly. No need to deconstruct and then build another. Features smart building where it won't try to replace walls that are already that type. You can replace mineable things with walls and doors; it will set the mineable to be mined and your constructors will prioritise mining anything in the way of blueprints, then construct. Comes with source.
Mod makers can look into the Vaccine class comments to see how to make new walls/doors/conduits replaceable without this mod updating to support them.

JTZoneButtons
Adds buttons for creating/expanding and deleting/shrinking stockpiles and growing zones when selecting a stockpile or growing zone. Comes with source.

JTHomemadeBionics
Make prosthetics and bionics at the machining table. Requires you to research Simple Prosthetics and then Bionics. Tried to balance the material cost and work needed against vanilla weapons. Yes the unfinished items look like guns, I'm lazy. I will probably expand to include stupid stuff like peg arms when I have time.

JTMedicinePlus
Make MedicinePlus which is normal medicine with a homemade copy of "Doctoring for Dummies"; it has a potency of 1.25. You can make and deconstruct MedicinePlus at workbenches that doesn't require electricity or fuel.
Making MedicinePlus gives XP to medicine. Requires medicine production research and a colonist with medicine level 12 and crafting level 3.
Another feature in this mod is when you use MedicinePlus or Glitterworld medicine to tend/heal someone, the XP gained is 2x the potency; more info here: https://www.reddit.com/r/RimWorld/comments/54lcx4/til_medicine_type_affects_medicine_xp_from/
Note: Unintentially changes all pawns that start with Glitterworld preference (humanlike) to MedicinePlus. When removing this mod, please restart Rimworld and if any pawns have Glitterworld preference, you will need to reselect a treatment level or they will not get treated and the doctor trying to treat will be idle.

JTSavagePrisoners
Lowers mood impact to -3 on selling/harvesting/accidentally killing prisoners and limits stacking to 1 (aka no mood debuff stacks). They tried to kill us, no mercy. Ok just a little mercy, they're human as well after all.
If you use the Psychology mod, use JTSavagePrisonersCompatPsychology instead (more info in Conflicts down bellow). No longer needed in A17.

JTMeleeXP
Allows gaining melee XP from attacking inanimate things (like sleeping spots) at half the normal rate. You might have to do a new save; the mod doesn't seem to work with my current save, but would with a save that was near the beginning of the same game. Comes with source.
Correction: requires you to make/obtain a new weapon for changes to take place. The save file actually saves the verb class the item is associated with at the time of creation.
CORRECTION: newest version (one with assemblies folder) uses some code from CCL to magically replace the vanilla method with mine; this means new save/new item is no longer required for JTMeleeXP to take effect. You can use the newest JTMeleeXP with a save that used the old JTMeleeXP with no problem, just don't try to run both at the same time somehow.

JTCampfireCremate
Cremate bodies at a campfire, takes more work than electric crematorium, scaled according to burning apparel (1.75x more work).

JTMoreHydroponicOptions
Grow more vanilla stuff in hydroponics (corn, haygrass, devil strand). Hydroponics default is now rice (corn is better if you don't need food right now). Keep in mind devil strand takes a long ass time to grow and solar flares/power failures will kill devil strand growing in hydroponics.

JTExtendedPowerArmor
Powered power armor removes penalties; requires additional research and reactor ship research. Powered power armor helmet has no move penalty and psychic sensitivity reduction similar to foil hat.
Super armor gives bonus opposite to power armor penalties; requires Powered power armor and ship engine research. Super armor helmet is like powered power armor helmet, but also has a light for when you're under a mountain or mining and not drafted.

JTDrill5Eva
Drill spots don't run out. Uninstalling feature removed, get Miniaturisation Overloaded by notfood instead. Comes with sauce.

JTWeRAnimals
Lowers mood impact (-3) and length (6 days) on killing bonded animals and no debuff stacking.

JTBetterCrashedShips
Crashed ship incidents when destroyed all give AI cores (poison did not, now does), plasteel (psychic 210, poison 172) and components (psychic 20, poison 18) (still gives vanilla steel and silver). Ship chunks also give plasteel (30) when deconstructed. Roughly balanced against buildable ship buildings.

JTBetterShipReactor
Ship reactor outputs 10,000 power because it's awesome and endgame.

JTEfficientBatteries
Batteries more efficient (0.75).

JTOrbital
Orbital trade beacon power consumption lowered to 5. I CBF making rules to put things I want to trade around the beacon, so usually I make beacons everywhere, but that's a lot of power.

JTSarcophagus
Sarcophagus mood benefit increased to 6 days (matches neutral colonist death), stack multiplier decreased to match colonist death multiplier.

Download
https://onedrive.live.com/?authkey=%21AOJkr-l_lBwwAJw&id=D3374FA891C72E6%212308&cid=0D3374FA891C72E6
After opening that link:
To download a mod, RIGHTclick on the folder and press download.

All the mods should also be on steam workshop.
Alpha 17:
https://steamcommunity.com/workshop/filedetails/?id=939624099
Alpha 16:
https://steamcommunity.com/sharedfiles/filedetails/?id=818135819
Alpha 15:
https://steamcommunity.com/sharedfiles/filedetails/?id=765623484

Install
For steam RimWorld, extract zip folder contents to "C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods"
For non-steam Rimworld, no idea, good luck.

Uninstalling
Mods that add new items will not load if you don't remove the new items from the map before saving.
My mods that add new items are: JTExtendedPowerArmor, JTMedicinePlus.

Mods that use a MapComponent class will throw an error on load, but will be fine and will stop throwing that error after another save-load cycle. Alternatively, you can edit out the MapComponent in the save file by deleting the LineToRemove listed bellow: incorrectly editing the save file can break the save, back up the file first.
My mods that use a MapComponent class are: (modName: LineToRemove)
JTMoreAreas: <li Class="JTMoreAreas.MapComponent_AreaUpdate" />

Source
I think most/all of my mods that have Assemblies folder have source included. I sometimes forget to update source before uploading to steam workshop, so the Onedrive download would have the most recent stuff.

Conflicts
Psychology with JTSavagePrisoners: use JTSavagePrisonersCompatPsychology and put it under/after Psychology. Not applicable for A17.
What my shit overrides:
JTBetterHauling: JobGiver_Work.TryGiveJob() and JobGiver_Haul.TryGiveJob().
JTBetterHaulingAnimalsJoke: JobGiver_Haul.TryGiveJob().
JTMoreAreas: AreaManager.CanMakeNewAllowed() and Dialog_ManageAreas.DoWindowContents().
JTCopyBills: Building.GetGizmos() and Pawn_DraftController.GetGizmos().
JTExport: Building.GetGizmos() and Zone_Stockpile.GetGizmos().
JTReplaceWalls: Designator_Build.CanDesignateCell(), GenConstruct.PlaceBlueprintForBuild() and GenConstruct.BlocksFramePlacement().
JTZoneButtons: Zone_Stockpile.getGizmos() and Zone_Growing.getGizmos().
JTHomemadeBionics: (A15) Bionics.
JTMedicinePlus: MedicalCareUtility methods with JTMedicinePlus methods, Toils_Tend.FinalizeTend().
JTSavagePrisoners: (A15) Thoughtdefs for KnowGuestExecuted, KnowPrisonerDiedInnocent, KnowPrisonerSold, KnowGuestOrganHarvested.
JTMeleeXP: Verb_MeleeAttack.TryCastShot().
JTCampfireCremate: Nothing.
JTMoreHydroponicOptions: (A15) Thingdef for HydroponicsBasin, PlantCorn, PlantHaygrass, PlantDevilstrand.
JTExtendedPowerArmor: Nothing.
JTDrill5Eva: CompDeepDrill.ProduceLump().
JTWeRAnimals: Thoughtdefs for BondedAnimalDied.
JTBetterCrashedShips: (A15) Thingdef for Buildings_Exotic.
JTBetterShipReactor: Thingdef for Ship_Reactor.
JTEfficientBatteries: Thingdef for Battery.
JTOrbital: Thingdef for OrbitalTradeBeacon
JTSarcophagus: Thoughtdef for KnowBuriedInSarcophagus.

License
You can do whatever. Though if you use/improve my code, please link me so I can have a look and learn.

Changedog
http://pastebin.com/81YyB9MS

Acknowledgements:
Onedrive download improvements: Adventurer