New Hediff

Started by robotguy4, August 05, 2016, 09:28:33 PM

Previous topic - Next topic

robotguy4

I'm currently working on a mod that would accelerate aging. Am I correct in assuming that you need to use an injector to do this? Could I do it with CCL?

I'm having problems compiling my code with CCL in monodevelop. Looks like it's not setting up references correctly with CCL (CCL doesn't seem to be able to load UnityEngine or Assembly-CSharp, even though I have them referenced for the main project. My non-injector code compiles fine without referencing CCL.)

CallMeDio

Have you checked allow unsafe code on the solution properties?
Because CCL detour is a unsafe method

edit: also,  see if your solution is set up for framework 3.5
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

robotguy4

#2
Quote from: CallMeDio on August 05, 2016, 10:00:18 PM
Have you checked allow unsafe code on the solution properties?

No, I didn't.

Checked it under project options (not solution options. On Monodevelop, it's "<Insert Project Name here> Options". This is for anyone who is reading for answers) and now it compiles. Looks like that worked. Thanks.

robotguy4

#3
Question: in Detours.TryDetourFromTo(method1, method2), is method 1 effectively replaced or is method 2 patched in?

Also, do I have to replace a method or can I define a new one? Can I replace an override? I'm still pretty new to modding.

robotguy4

#4
I've been banging my head against the wall for a while and have been trying to implement this hediff that would cause accelerated aging. Here's the basic code I made:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;// Always needed
using RimWorld;
using Verse;
//using Verse.AI;

namespace Senexium
{
public class Hediff_AccellAge: Hediff
{


//
// Fields
//
public int accellageduration
{
get
{
return 3;
}
}

public int accellageadd
{
get
{
return 10;
}
}

public float accellageProgress
{
get
{
return this.Severity;
}
private set
{
this.Severity = value;
}
}

//
// Methods
//

#region Ticker

public override void Tick ()
{
base.Tick ();
this.accellageProgress += 1 / accellageduration * 60000f;
this.pawn.ageTracker.AgeBiologicalTicks += accellageadd;
}

#endregion

}

}


This was based off the other Hediffs. Here's my XML file for Accelerated_aging:

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

<Defs>
<HediffDef>
<defName>Accellerated_Aging</defName>
<hediffClass>Senexium.Hediff_AccellAge</hediffClass>
<label>accellerated aging</label>
<defaultLabelColor>(0.3,0.65,0.55)</defaultLabelColor>
<initialSeverity>1</initialSeverity>
        <comps>
            <li>
                <compClass>HediffComp_Immunizable</compClass>
                <severityPerDayNotImmune>-1</severityPerDayNotImmune>
                <severityPerDayNotImmuneRandomFactor>
                    <min>0.5</min>
                    <max>1</max>
                </severityPerDayNotImmuneRandomFactor>
            </li>
        </comps>
        <stages>
            <li>
                <label>initial-hidden</label>
                <everVisible>false</everVisible>
            </li>
            <li>
                <minSeverity>0.01</minSeverity>
                <label>active</label>
            </li>
        </stages>
</HediffDef>
</Defs>

Of course, this doesn't work. Whenever I run it I get the error:
Could not find a type named Hediff_AccellAge (I can post the full error log here if you want, but I'm not sure it will help.)

I'm having problems trying to figure out what I need to detour to get it to work. I know I need to detour something, but I'm not sure what. Anyone have any suggestions?

I may be in over my head on this. I'm still pretty new to C#.

Actually does this need a detour? I may have confused myself. My head hurts.

EDIT: I think I see what I did wrong. Need to do some edits. Nope, still doesn't work. I updated the code here, though.

CallMeDio

#5
I know how you feel.. my first detour took me about 30 hours of work until it detoured(because i derped, but its true anyways), So... what I notice looking at what you are doing is that you are trying to add a <compClass>HediffComp_Immunizable</compClass> on your xml but the C# you are doing says Hediff_AccellAge: Hediff. Im not a master at this but my guess is that if you are adding a comp to it, it should be Hediff_AccellAge: HediffWithComps, of course this will change some stuff about how to reference objects on the rest of the code.
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

1000101

You don't need to allow unsafe code in your project because you are using detours.  CCL needs to allow unsafe code because it's doing unsafe things, your code is just calling a method.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

robotguy4

#7
Ok, so I finally felt like going over everything. Long story short, I got it to work.

Turns out I didn't need a detour. All I had to do was fix some things in the code that weren't set up correctly. I don't remember 100% what I fixed, but I fixed it. I remember among other things I named the "Assemblies" folder "Assembly". I also remade my c# solution so it would automatically put the dll into the Assemblies folder.

Quote from: CallMeDio on August 09, 2016, 02:31:52 PM
what I notice looking at what you are doing is that you are trying to add a <compClass>HediffComp_Immunizable</compClass> on your xml but the C# you are doing says Hediff_AccellAge: Hediff.

AFAIK, compClass refers to hediff "modifier" classes that change the hediff's behavior. In this case, Immunizable. Other compClasses in hediff include things like wether its discoverable, visible, tendable, etc. I remember I did not change this part to get it to work, but I may need to change it for the final version.

I kept confusing hediff, hediffcomp and hediffwithcomp with each other.

Quote from: 1000101 on August 10, 2016, 02:40:27 AM
You don't need to allow unsafe code in your project because you are using detours.  CCL needs to allow unsafe code because it's doing unsafe things, your code is just calling a method.
True, but, at least on Monodevelop, you will still need to allow unsafe code to get it to compile with CCL as a reference.

Thank you for your help. Once I get some good graphics and polish a few things, I'll release it.

1000101

Quote from: robotguy4 on August 10, 2016, 03:41:20 AM
Quote from: 1000101 on August 10, 2016, 02:40:27 AM
You don't need to allow unsafe code in your project because you are using detours.  CCL needs to allow unsafe code because it's doing unsafe things, your code is just calling a method.

True, but, at least on Monodevelop, you will still need to allow unsafe code to get it to compile with CCL as a reference.

Sounds like there is something broken with monoDevelop then.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

robotguy4

Quote from: 1000101 on August 10, 2016, 07:06:23 AM
Sounds like there is something broken with monoDevelop then.

Either that or I'm describing/explaining it wrong. Or it does things differently.

All I know is that if I include CCL as a reference it won't compile without allowing unsafe code in the project.

CallMeDio

To help you not confuse it: Hediff is like a hot dog(the main thing), comp is like mustard(something you can put on it) and hediffwithcomps is a hot dog with mustard.
As for the error I repplied last time I had the same error a little bit after you posted it, and even without any comps on the hediff it was fixed by changing it to : HediffWithComps. I have no idea why. but hey! it worked. lol
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

robotguy4

Quote from: CallMeDio on August 10, 2016, 07:18:47 PM
To help you not confuse it: Hediff is like a hot dog(the main thing), comp is like mustard(something you can put on it) and hediffwithcomps is a hot dog with mustard.
That's a nice analogy. I had a feeling it was something like that.

Quote from: CallMeDio on August 10, 2016, 07:18:47 PM
As for the error I repplied last time I had the same error a little bit after you posted it, and even without any comps on the hediff it was fixed by changing it to : HediffWithComps. I have no idea why. but hey! it worked. lol
If I remember correctly, that's what I eventually did. I got it to work as a Hediff, but then realized that I had to change it to HediffWithComps in order for comps to work.

Would anyone want me to make a tutorial dedicated to Hediffs? I mean, you can figure this stuff out on your own, but it feels like a tutorial would save new modders a lot of time.