Jump to content

[Issue] Whit mod :/ Crashing after load


Recommended Posts

Hello,

 

I have create mod for all power generators, started game, test it - ok. Added more mirror changes (some Battery, some CO2 Scrubber, and Wire). 

Started game, test it - ok works.

Add some more change. Starting game Crash. Cut my main big MOD to smaller portion's works to check witch part makes problem.

CO2ScrubberConfig , GasReservoirConfig and ElectrolyzerConfig stop working :/ I didn't change a thing in theme since first creation.

Can any one point what I do Wrong ?

 

namespace BalanceEnergy
{

    //-----------******* Decress Power Usage - LiquidPump  *******-----------

    [HarmonyPatch(typeof(LiquidPumpConfig), "CreateBuildingDef")]
    public static class LiquidPumpConfiggMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.EnergyConsumptionWhenActive = 60f;
        }
    }

    [HarmonyPatch(typeof(LiquidFilterConfig), "CreateBuildingDef")]
    public static class LiquidFilterConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.EnergyConsumptionWhenActive = 30f;
        }
    }

    [HarmonyPatch(typeof(LiquidHeaterConfig), "CreateBuildingDef")]
    public static class LiquidHeaterConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.EnergyConsumptionWhenActive = 1450f;
            __result.ExhaustKilowattsWhenActive = 6200f;
        }
    }

    [HarmonyPatch(typeof(SpaceHeaterConfig), "CreateBuildingDef")]
    public static class SpaceHeaterConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.EnergyConsumptionWhenActive = 420f;
            __result.ExhaustKilowattsWhenActive = 120f;
        }
    }

    //-----------*******      END       *******-----------


    //-----------******* POWER UP GRADE for all generateros - Hydro, Petrol, Methane, Wood and Coal (AKA Generator) *******-----------

    [HarmonyPatch(typeof(HydrogenGeneratorConfig), "CreateBuildingDef")]
    public static class HydrogenGeneratorConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.GeneratorWattageRating = 2000f;
            __result.GeneratorBaseCapacity = 4500f;

        }
    }

    [HarmonyPatch(typeof(PetroleumGeneratorConfig), "CreateBuildingDef")]
    public static class PetroleumGeneratorConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.GeneratorWattageRating = 3800f;
            __result.GeneratorBaseCapacity = 6200f;
        }
    }

    [HarmonyPatch(typeof(MethaneGeneratorConfig), "CreateBuildingDef")]
    public static class MethaneGeneratorConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.GeneratorWattageRating = 6400f;
            __result.GeneratorBaseCapacity = 9200f;
        }
    }

    [HarmonyPatch(typeof(WoodGasGeneratorConfig), "CreateBuildingDef")]
    public static class WoodGasGeneratorConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.GeneratorWattageRating = 600f;
        }
    }

    [HarmonyPatch(typeof(GeneratorConfig), "CreateBuildingDef")]
    public static class CoalGeneratorConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.GeneratorWattageRating = 1200f;
        }
    }

    //-----------*******      END       *******-----------

}

// <-------------------------------------------------------------------------------- THIS PART HAVE SOME PROBLEMS DON'T KNOW WAY --------------------------------------------------------------------------------------->
namespace BalanceEnergyPart2
{
    //-----------*******   Better Buliding stat - CO2Scraber, GasTank, Electroyzer      *******-----------


    [HarmonyPatch(typeof(CO2ScrubberConfig), "CreateBuildingDef")]
    public static class CO2ScrubberConfigMod
    {
        public static void Postfix(ref BuildingDef __result)
        {
            __result.EnergyConsumptionWhenActive = 60f;
        }
    }

    [HarmonyPatch(typeof(CO2ScrubberConfig))]
    [HarmonyPatch("ConfigureBuildingTemplate")]
    public class CO2ScrubberTamplateMod
    {
        public static void Postfix(ref GameObject go)
        {
            go.GetComponent<PassiveElementConsumer>().consumptionRate = 3.6f;
            go.GetComponent<PassiveElementConsumer>().capacityKG = 3.6f;
            go.GetComponent<PassiveElementConsumer>().consumptionRadius = 8;

            go.GetComponent<ElementConverter>().consumedElements = new ElementConverter.ConsumedElement[]
                {
                    new ElementConverter.ConsumedElement(GameTagExtensions.Create(SimHashes.Water), 1f),
                    new ElementConverter.ConsumedElement(GameTagExtensions.Create(SimHashes.CarbonDioxide), 1.8f)
                };

            go.GetComponent<ElementConverter>().outputElements = new ElementConverter.OutputElement[]
            {
               new ElementConverter.OutputElement(2.5f, SimHashes.DirtyWater, 0f, false, true, 0f, 0.5f, 1f, byte.MaxValue, 0)
            };
            go.GetComponent<ConduitConsumer>().consumptionRate = 2f;
            go.GetComponent<ConduitConsumer>().capacityKG = 6f;
        }

    }

    [HarmonyPatch(typeof(GasReservoirConfig))]
    [HarmonyPatch("ConfigureBuildingTemplate")]
    public class GasResrvoirConfigMod
    {
        public static void Prefix(ref GameObject go)
        {
            go.GetComponent<Storage>().capacityKg = 25000f;

        }
    }


    [HarmonyPatch(typeof(ElectrolyzerConfig))]
    [HarmonyPatch("ConfigureBuildingTemplate")]
    public class ElectrolyzerConfigTamplateMod
    {
        public static void Prefix(ref GameObject go)
        {
            go.GetComponent<Electrolyzer>().maxMass = 3.6f;
            go.GetComponent<ConduitConsumer>().consumptionRate = 1.5f;
            go.GetComponent<Storage>().capacityKg = 4f;
            go.GetComponent<ElementConverter>().consumedElements = new ElementConverter.ConsumedElement[]
            {
                new ElementConverter.ConsumedElement(new Tag("Water"),1.5f)
            };
            go.GetComponent<ElementConverter>().outputElements = new ElementConverter.OutputElement[]
            {
                new ElementConverter.OutputElement(1.366f, SimHashes.Oxygen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0),
                new ElementConverter.OutputElement(0.666333323f, SimHashes.Hydrogen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0)
            };

        }
        public const float WATER2OXYGEN_RATIO = 0.744f;
    }

    //-----------*******      END       *******-----------
}


namespace BalanceEnergyPart3
{

    //-----------******* Incress Power Storage fot Batteies - Nomrla, Medium, Smart  *******-----------
    //-----------******* And power rating for wire's - Nomrla, Hevy, isulated  *******-----------

    [HarmonyPatch(typeof(BatteryConfig))]
    [HarmonyPatch("DoPostConfigureComplete")]
    public class BatteryConfigPostConfigMod
    {
        public static void Postfix(ref GameObject go)
        {
            go.GetComponent<Battery>().capacity = 20000f;
            go.GetComponent<Battery>().joulesLostPerSecond = go.GetComponent<Battery>().capacity * 0.1f / 3200f;
        }
    }

    [HarmonyPatch(typeof(BatteryMediumConfig))]
    [HarmonyPatch("DoPostConfigureComplete")]
    public class BatteryMediumConfigPostConfigMod
    {
        public static void Postfix(ref GameObject go)
        {
            go.GetComponent<Battery>().capacity = 80000f;
            go.GetComponent<Battery>().joulesLostPerSecond = go.GetComponent<Battery>().capacity * 0.1f / 3200f;
        }

    }

    [HarmonyPatch(typeof(BatterySmartConfig))]
    [HarmonyPatch("DoPostConfigureComplete")]
    public class BatterySmartConfigPostConfigMod
    {
        public static void Postfix(ref GameObject go)
        {
            go.GetComponent<Battery>().capacity = 100000f;
            go.GetComponent<Battery>().joulesLostPerSecond = go.GetComponent<Battery>().capacity * 0.2f / 9200f;
        }

    }

    [HarmonyPatch(typeof(Wire))]
    [HarmonyPatch("GetMaxWattageAsFloat")]
    public class WireConfigPostConfigMod
    {
        private static bool Prefix(Wire.WattageRating rating, ref float __result)
        {
            float num;
            switch (rating)
            {
                case Wire.WattageRating.Max500:
                    num = 1000f;
                    break;
                case Wire.WattageRating.Max1000:
                    num = 2000f;
                    break;
                case Wire.WattageRating.Max2000:
                    num = 4000f;
                    break;
                case Wire.WattageRating.Max20000:
                    num = 40000f;
                    break;
                case Wire.WattageRating.Max50000:
                    num = 100000f;
                    break;
                default:
                    num = 0f;
                    break;
            }
            __result = num;
            return false;
        }

    }


    //-----------*******      END       *******-----------

}

 

Link to comment
Share on other sites

First and foremost, i have NO idea what i am talking about OR looking at ...yet, I am just starting to look at this stuff, and the more i ask I learn .

 

The thing i SEE in the above text is weirdness with a "semicolon" ?sp

 {
            go.GetComponent<Electrolyzer>().maxMass = 3.6f;
            go.GetComponent<ConduitConsumer>().consumptionRate = 1.5f;
            go.GetComponent<Storage>().capacityKg = 4f;
            go.GetComponent<ElementConverter>().consumedElements = new ElementConverter.ConsumedElement[]
            {
                new ElementConverter.ConsumedElement(new Tag("Water"),1.5f)
            };
            go.GetComponent<ElementConverter>().outputElements = new ElementConverter.OutputElement[]
            {
                new ElementConverter.OutputElement(1.366f, SimHashes.Oxygen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0),
                new ElementConverter.OutputElement(0.666333323f, SimHashes.Hydrogen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0)
            };

        }

DO the "semicolons belong INside the bracket thingy..??

This could be the way it is suppose to be, but if I don't ask i won't learn..lol

Besides this will put it back up so others can look and give you real advice...lol

???

 

Link to comment
Share on other sites

They are required as you start you "Matrix" table using [ ] after that you start defining table with {  } inside each "entry" need's to be separate by , so you can define something like 3x3 or 5x5 but Klein sue it different like passing parameter to function witch is defined in ElementConverter.Output.

So following hey "way of thinking" I have change what i liked it work unlit I add'ed more changes. Now the "MOD" I create have is almost done but this part still make some problems.

This how Klein did it (Original Code):

public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
	{
		go.GetComponent<KPrefabID>().AddTag(RoomConstraints.ConstraintTags.IndustrialMachinery, false);
		Electrolyzer electrolyzer = go.AddOrGet<Electrolyzer>();
		electrolyzer.maxMass = 1.8f;
		electrolyzer.hasMeter = true;
		ConduitConsumer conduitConsumer = go.AddOrGet<ConduitConsumer>();
		conduitConsumer.conduitType = ConduitType.Liquid;
		conduitConsumer.consumptionRate = 1f;
		conduitConsumer.capacityTag = ElementLoader.FindElementByHash(SimHashes.Water).tag;
		conduitConsumer.wrongElementResult = ConduitConsumer.WrongElementResult.Dump;
		Storage storage = go.AddOrGet<Storage>();
		storage.capacityKg = 2f;
		storage.showInUI = true;
		ElementConverter elementConverter = go.AddOrGet<ElementConverter>();
		elementConverter.consumedElements = new ElementConverter.ConsumedElement[]
		{
			new ElementConverter.ConsumedElement(new Tag("Water"), 1f)
		};
		elementConverter.outputElements = new ElementConverter.OutputElement[]
		{
			new ElementConverter.OutputElement(0.888f, SimHashes.Oxygen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0),
			new ElementConverter.OutputElement(0.111999989f, SimHashes.Hydrogen, 343.15f, false, false, 0f, 1f, 1f, byte.MaxValue, 0)
		};
		Prioritizable.AddRef(go);
	}

What I wanted to achieve is to change ratio form 0.888f Oxygen to 1.366 and 01111... Hydrogen to 0.6666 also change intake from 1 Water to 1.5.

Kind Regards

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...