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

#1
Mods / Re: Need guidance in creating a more advanced mod
September 12, 2019, 04:56:13 PM
Interesting mod idea.

QuoteI really just need someone to give me a solid explanation of how the defs and dlls interact and work with each other.

Since you're proficient in C#: Defs are simply classes, which get their fields filled using reflection. The values in these fields are in the XML files. Every Def is an instance, and there's one instance of the Def per Type of Def (e.g. there's one ThingDef named Beer). If you change the Beer ThingDef, you change it for all Things which share the single Beer ThingDef.

To create your mod, you'll need to find a way to lift along with the "raid was defeated" functionality. There's no clear cut "raid defeated" thing, but I'd wager LordToil_PanicFlee comes pretty close, with the caveat that it doesn't apply to mechanoids. Its UpdateAllDuties() method gets triggered when a human raid is defeated.

You can use Harmony to lift along with that method. Try a Postfix on the aforementioned method with a Log.Message as a start.
#2
<earliestDay>15</earliestDay>
#3
When you start Visual Studio you have the option to create a new project. Do so. You'll get a screen like so:



That is the type of project you need. If Visual Studio does not have anything for "Class Library Framework", click the "Install more tools and features" go to "Individual Component" and then install "Development tools for Framework .NET 3.5" (or something similarly named).

That is the type of project you need: A class library for .NET Framework using C#.
Not .NET Core, not Visual Basic.

Then, click next. You'll get a screen like this:


Select .NET Framework 3.5. If you do not have 3.5 available, go back one step and click the "Install more tools and features" -- follow above instructions.

If you had already started a project which targets .NET Core instead of .NET Framework, you cannot change back easily. Just start a new project. If you had set it to a different version of .NET Framework, Project => Properties => Application => Target Framework.
#4
The code you posted points to WorkGiver_FillHoneyBarrel's JobOnThing method.

public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
{
    Building_HoneyBarrel building_HoneyBarrel = (Building_HoneyBarrel)t;
    Thing t2 = this.FindPollen(pawn, building_HoneyBarrel);
    return new Job(JobDefOf.ArthropodFillHoneyBarrel, t, t2)
    {
        count = building_HoneyBarrel.SpaceLeftForPollen
    };
}


You're casting Thing t to a Building_HoneyBarrel, but t isn't a Building_HoneyBarrel.

Your HasJobOnThing method does it better:

public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
{
    Building_HoneyBarrel building_HoneyBarrel = t as Building_HoneyBarrel;
    if (building_HoneyBarrel == null || building_HoneyBarrel.Fermented || building_HoneyBarrel.SpaceLeftForPollen <= 0)
    {
        return false;
    }
    //snip


One of them is an explicit cast, the other implicit.

FWIW I think you're reinventing the wheel here. There's a Universal Fermenter framework mod.
#5
Unfinished / Re: [1.0] Lets Go Explore!
June 28, 2019, 05:02:19 AM
Quote from: Canute on June 24, 2019, 07:11:32 AM
World road building event.
Once a faction got allied with you and got 100 standing for about a while.
They offer you chance to build a road between their closest city and your colony.
You need to deliver the resources, while the other faction offer the manpower.
(...)

MFI has a more basic version of this, and there's Roads of the Rim as well.

I'm excited for the mod Albion! You always make good stuff :)
#6
Help / Re: Help with new trait
June 27, 2019, 02:33:17 AM
The StatDefOf.PlantHarvestYield sounds promising. It doesn't do what you want.

QuoteYou think you know what the stat "Plant Harvest Yield" does? Well, let me surprise you - it does NOT increase the amount you get when you harvest plants, like "Mining Yield" does for ores.

It merely gives you a chance to fail below 100%, above 100% you do not gain anything.

Yes it can be done, and yes it'll need C#.

It's a patch on the toils in JobDriver_PlantWork, specifically the part where it uses plant.YieldNow(). That gets you both the pawn and the plant yield.

Guess what? There's already a mod for that.

https://steamcommunity.com/sharedfiles/filedetails/?id=1461790308&searchtext=syrchalis
#7
Hi. Thank you for the log and savefile. The error you've encountered happens in a bit of code where MFI looks at the RaceProperties for an animal, to see if they can do a HerdMigration and their wildness. That's the basic selector for the event in question.

Your log has a lot of errors like

QuoteHash collision between ZombieCorythosaurus and  SculptureSmall: both have short hash 56905

so when MFI tries to access the RaceProperties of the ZombieCorythosaurus, it gets the RaceProperties from the SculptureSmall. Since sculptures aren't animals, you get an error.

That zombie mod has about 80 of these hash collisions. I don't know why. What I do know is that your artist is going to be *very* surprised when they suddenly get a zombie dinosaur instead of a small sculpture.
#8
Help / Re: Best way to call debug function in code
June 17, 2019, 03:48:36 AM
Those are protected methods, so you'll run into some issues there. The correct way of triggering an event is through the Worker in the Def.


//IncidentDef def = IncidentDefOf.RaidEnemy;
// or
//IncidentDef def = DefDatabase<IncidentDef>.GetNamed("MyDefName");

def.Worker.TryExecute();
#9
Good job. One addition to the source I saw on GitHub:

When you're adding Labels, you should use the ILGenerator shared through Harmony. Adding your own labels might cause your code to jump to unexpected places. With Harmony's ILGenerator, labels are in their proper place even with multiple patches.

Your method signature would then be
static IEnumerable<CodeInstruction> Transpiler (IEnumerable<CodeInstruction> instructions, ILGenerator generator)
rather than
static IEnumerable<CodeInstruction> Transpiler (IEnumerable<CodeInstruction> instructions)

How you name the ILGenerator parameter has no influence, according to Harmony's wiki.
#10
Help / Re: Help with animal .dll
June 07, 2019, 02:01:34 PM
No C# is needed to make an animal. Pure XML.
#11
Quote from: bionicjoethehat on June 07, 2019, 11:26:12 AM
Your first code is taken from 1.0 but I am adapting a 1.0 mod for B18.

oh ffs -- I only now realise it. You're downgrading a mod? well screw the transpiler then -- who cares about compatibility within B18. Just prefix it and return false. Amount of users affected: You.
#12
You want to turn
// Page_ConfigureStartingPawns
using Verse;

private void RandomizeCurPawn()
{
if (TutorSystem.AllowAction("RandomizePawn"))
{
int num = 0;
do
{
curPawn = StartingPawnUtility.RandomizeInPlace(curPawn);
num++;
}
while (num <= 20 && !StartingPawnUtility.WorkTypeRequirementsSatisfied());
TutorSystem.Notify_Event("RandomizePawn");
}
}


into

// Page_ConfigureStartingPawns
using Verse;

private void RandomizeCurPawn()
{
if (TutorSystem.AllowAction("RandomizePawn"))
{
do
{
curPawn = StartingPawnUtility.RandomizeInPlace(curPawn);
}
while (!RandomSettings.CheckPawnIsSatisfiedMethodInfo);
TutorSystem.Notify_Event("RandomizePawn");
}
}


Those are a few changes too many. Keep the "num". You can elect to change it to a higher value, but removing it is too invasive. Payoff vs effort. Not to mention the side-effects.

Changing !StartingPawnUtility.WorkTypeRequirementsSatisfied() to !RandomSettings.CheckPawnIsSatisfiedMethodInfo is good, but you'll need to keep labels in mind. Those IL_003e: brfalse IL_0017 can't be used easily in a transpiler. You'll need to find those labels manually -- it's much easier to avoid that entirely.

      IL_002f: ble IL_0039

      // (no C# code)
      IL_0034: br IL_0043

      IL_0039: call bool Verse.StartingPawnUtility::WorkTypeRequirementsSatisfied()
      IL_003e: brfalse IL_0017

IL_0039 is what we're after, but there's a jump label to it. We're going to recycle it.

here's some (pseudo) code

foreach codeinstruction in instructions
{
    if (codeinstruction == call bool Verse.StartingPawnUtility::WorkTypeRequirementsSatisfied())
    {
        codeinstruction.operand = null;
        codeinstruction.opcode = OpCodes.Ldarg_0;
        yield return codeinstruction;
        yield return new CodeInstruction(OpCodes.Ldfld, curPawnFieldInfo);
        yield return new CodeInstruction(OpCodes.Call, CheckPawnIsSatisfiedMethodInfo);       
    }
    else
        yield return codeinstruction;
}


Note that this removes StartingPawnUtility.WorkTypeRequirementsSatisfied(). The good news is that it's a static public method, so you can move the call to it into the CheckPawnIsSatisfiedMethodInfo method.
#13
It's only activated as part of the XML ThinkTree.
#14
Help / Re: Custom Melee Audio
June 07, 2019, 07:13:36 AM
if you ahve a single file, use clipPath and appropriate li Class =

Search forums, you're not the first to run into the issue.
#15
have a guide with pictures https://imgur.com/a/uHzxewm