Help with error System.TypeLoadException

Started by xyq565861, December 05, 2016, 10:26:49 AM

Previous topic - Next topic

xyq565861

I have created a build mod ,but it's someting wrong with the  GetGizmos()
The game always call my with

I think the issue in line
command_Action.action = new Action(this.switchshowb);
because if I notes it ,the mod works well


namespace STLIGHT
{
    [StaticConstructorOnStartup]
    public class Building_Humidifier : Building
    {
        public static Texture2D UION = ContentFinder<Texture2D>.Get("UI/ON", true);
        public static Texture2D UIOFF = ContentFinder<Texture2D>.Get("UI/OFF", true);
        bool isshow = false;
        private float radius;
        float cred;
        float cgreen;
        float cblue;
        float areasize = 0;
        float areasize1 = 0;
        public Material currentMatrialColour;
        private CompPowerTrader PowerValue;
        private HediffDef hediffDef;
        public override void SpawnSetup()
        {
            this.PowerValue = base.GetComp<CompPowerTrader>();
            base.SpawnSetup();
            Comp_HumidifierBuilding comp = base.GetComp<Comp_HumidifierBuilding>();
            bool flag = comp.props is CompProperties_HumidifierBuilding;
            if (flag)
            {
                this.hediffDef = ((CompProperties_HumidifierBuilding)comp.props).hediffDef;
                this.radius = ((CompProperties_HumidifierBuilding)comp.props).radius;
                this.cred = ((CompProperties_HumidifierBuilding)comp.props).cred;
                this.cgreen = ((CompProperties_HumidifierBuilding)comp.props).cgreen;
                this.cblue = ((CompProperties_HumidifierBuilding)comp.props).cblue;
            }
            else
            {
                CheckAndGive();
                Log.Error("Shield definition not of type \"HumidifierBuildingThingDef\"");
            }

        }
        public override IEnumerable<Gizmo> GetGizmos()
        {
            List<Gizmo> list = new List<Gizmo>();
            Command_Action command_Action = new Command_Action();
            if (!this.isshow)
            {
                command_Action.icon = Building_Humidifier.UIOFF;
                command_Action.defaultDesc = "close";
                command_Action.defaultLabel = "Visual effect";
                command_Action.action = () =>
                {
                    this.switchshowb();
                };
                //command_Action.action = new System.Action(this.switchshow1);

            }
            else
            {
                Log.Message("asasdd");
                command_Action.icon = Building_Humidifier.UION;
                command_Action.defaultDesc = "open";
                command_Action.defaultLabel = "Visual effect";
                command_Action.action = () =>
                    {
                        this.switchshowa();
                    };
                //command_Action.action = new System.Action(this.switchshow1);

            }
            command_Action.activateSound = SoundDefOf.Click;
            command_Action.groupKey = 887767441;
            list.Add(command_Action);
            return list.AsEnumerable<Gizmo>();
        }
        public bool IsPowerOn()
        {
            if (this.PowerValue != null)
            {
                if (this.PowerValue.PowerOn)
                {
                    return true;
                }
            }
            return false;
        }
        public override void Tick()
        {
            base.Tick();
            if (IsPowerOn())
            {
                this.DrawSubField(Vectors.IntVecToVec(base.Position), (float)this.areasize, 0.15f);
                this.DrawSubField(Vectors.IntVecToVec(base.Position), (float)this.radius, 0.25f);
                this.areasize1++;
                if (areasize1 % 3 == 0)
                {
                    areasize1 = 0;
                    areasize += 0.08f;
                }
                if (this.areasize > this.radius)
                {
                    areasize = 0;
                }
                CheckAndGive();

            }

        }
        public void switchshowa()
        {
            this.isshow = true;
        }
        public void switchshowb()
        {
            this.isshow = false;
        }



        public bool CheckAndGive()
        {

            List<Thing> enumerable = Find.ListerThings.ThingsOfDef(ThingDefOf.Human);
            bool flag2 = enumerable != null;
            if (flag2)
            {
                Log.Message(base.Position.ToString());
                Log.Message(radius.ToString());
                List<Thing> enumerable2 = new List<Thing>();
                for (int z = 0; z < enumerable.Count; z++)
                {

                    if (enumerable[z].Position.InHorDistOf(base.Position, radius))
                    {
                        enumerable2.Add(enumerable[z]);
                    }

                }
                bool flag3 = enumerable2 != null;
                if (flag3)
                {
                    for (int g = 0; g < enumerable2.Count; g++)
                    {
                        Pawn pawn = enumerable2[g] as Pawn;
                        if (pawn != null)
                        {
                            HealthUtility.AdjustSeverity(pawn, this.hediffDef, 0.1f);
                        }
                    }
                }
            }
            return false;
        }
        public void DrawSubField(Vector3 position, float Radius, float dreeg)
        {
            position += new Vector3(0.5f, 0f, 0.5f);
            Vector3 s = new Vector3(Radius, 1f, Radius);
            Matrix4x4 matrix = default(Matrix4x4);
            matrix.SetTRS(position, Quaternion.identity, s);
            bool flag = this.currentMatrialColour == null;
            if (flag)
            {
                Log.Message(cred.ToString());
                this.currentMatrialColour = SolidColorMaterials.NewSolidColorMaterial(new Color(this.cred, this.cgreen, this.cblue, dreeg), ShaderDatabase.MetaOverlay);
            }
            UnityEngine.Graphics.DrawMesh(Graphics.CircleMesh, matrix, this.currentMatrialColour, 0);
        }
    }
    public class Comp_HumidifierBuilding : ThingComp
    {
    }
    public class CompProperties_HumidifierBuilding : CompProperties
    {
        public HediffDef hediffDef;
        public float radius;
        public float cred;
        public float cgreen;
        public float cblue;
        public CompProperties_HumidifierBuilding()
        {
            this.compClass = typeof(Comp_HumidifierBuilding);
        }
    }
    public class Vectors
    {
        public static double EuclDist(IntVec3 a, IntVec3 b)
        {
            return Math.Sqrt((double)((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)));
        }

        public static double VectorSize(IntVec3 a)
        {
            return Math.Sqrt((double)(a.x * a.x + a.y * a.y + a.z * a.z));
        }

        public static IntVec3 vecFromAngle(float angle1, float angle2, float r)
        {
            IntVec3 result = new IntVec3((int)((double)r * Math.Sin((double)angle1) * Math.Cos((double)angle2)), (int)((double)r * Math.Sin((double)angle1) * Math.Sin((double)angle2)), (int)((double)r * Math.Cos((double)angle1)));
            return result;
        }

        public static double vectorAngleA(IntVec3 a)
        {
            double num = Vectors.VectorSize(a);
            return Math.Acos((double)a.z / num);
        }

        public static IntVec3 randomDirection(float r)
        {
            return Vectors.vecFromAngle((float)UnityEngine.Random.Range(0, 360), 0f, r);
        }

        public static Vector3 IntVecToVec(IntVec3 from)
        {
            return new Vector3((float)from.x, (float)from.y, (float)from.z);
        }

        public static IntVec3 VecToIntVec(Vector3 from)
        {
            return new IntVec3((int)from.x, (int)from.y, (int)from.z);
        }
    }
    public static class Graphics
    {
        private static Mesh CircleMesh_cache;

        public static Mesh CircleMesh
        {
            get
            {
                bool flag = Graphics.CircleMesh_cache != null;
                Mesh circleMesh_cache;
                if (flag)
                {
                    circleMesh_cache = Graphics.CircleMesh_cache;
                }
                else
                {
                    double num = 1.0;
                    List<Vector2> list = new List<Vector2>();
                    list.Add(new Vector2(0f, 0f));
                    for (int i = 0; i <= 360; i += 4)
                    {
                        double num2 = (double)((float)i / 180f) * 3.1415926535897931;
                        list.Add(new Vector2(0f, 0f)
                        {
                            x = (float)(num * Math.Cos(num2)),
                            y = (float)(num * Math.Sin(num2))
                        });
                    }
                    Vector3[] array = new Vector3[list.Count];
                    for (int j = 0; j < array.Length; j++)
                    {
                        array[j] = new Vector3(list[j].x, 0f, list[j].y);
                    }
                    Triangulator triangulator = new Triangulator(list.ToArray());
                    int[] triangles = triangulator.Triangulate();
                    Graphics.CircleMesh_cache = new Mesh();
                    Graphics.CircleMesh_cache.vertices = array;
                    Graphics.CircleMesh_cache.uv = new Vector2[list.Count];
                    Graphics.CircleMesh_cache.triangles = triangles;
                    Graphics.CircleMesh_cache.RecalculateNormals();
                    Graphics.CircleMesh_cache.RecalculateBounds();
                    circleMesh_cache = Graphics.CircleMesh_cache;
                }
                return circleMesh_cache;
            }
        }
    }
}

1000101

Please show the entire class.  There isn't enough there to go on.
(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

ChJees

I think you need to do a yield return; in order for it to return properly. Also ensure you reference the System libraries in the Managed folder in Rimworld.

Had similar issues today when i never linked to the Rimworld managed libraries. Fixed itself after i did though. Had problems with the delegate Action<T1,T2> there though :P.

xyq565861

thank you ,I think I found the problem.
When i linked the system lib in vs2013, the ide always redirect it to .NETFramework 4.5.1 lib.
I tired to redirect the system namespace to system lib in rimworld.
can you help me with that ?
thanks

1000101

You don't need to link specifically with the RW supplied libraries (except Assembly-CSharp and Unity as applicable), but you do need to use [ code ][ /code ] tags in your posts...err...I mean target .Net 3.5, NOT 4.5.
(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