diff --git a/PMAPI.sln b/PMAPI.sln index b42b653..c6b2dec 100644 --- a/PMAPI.sln +++ b/PMAPI.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestMod", "TestMod\TestMod.csproj", "{8151CF37-9B54-4E83-893F-1065F73F61F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndustrialHorizons", "TestMod\IndustrialHorizons.csproj", "{8151CF37-9B54-4E83-893F-1065F73F61F9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PMAPI", "PMAPI\PMAPI.csproj", "{C984C145-F07A-405B-AF23-8C3BFB64CE08}" EndProject diff --git a/PMAPI/CustomSubstances/CustomSubstanceManager.cs b/PMAPI/CustomSubstances/CustomSubstanceManager.cs index 8f8a8c6..395ada8 100644 --- a/PMAPI/CustomSubstances/CustomSubstanceManager.cs +++ b/PMAPI/CustomSubstances/CustomSubstanceManager.cs @@ -25,8 +25,8 @@ internal static void Init() internal static Dictionary customParams = new(); internal static SubstanceParameters.Param errorSubParams; - private static int id = -1; - + //private static int id = -1; + private static Dictionary currentId = new(); /// /// Registers custom substance in game /// @@ -36,12 +36,26 @@ internal static void Init() /// ID of registered substance used by the game public static Substance RegisterSubstance(string eid, SubstanceParameters.Param substanceParams, CustomSubstanceParams cParams) { + var modAttrib = Assembly.GetCallingAssembly().GetCustomAttribute(); + if (!currentId.TryGetValue(modAttrib.id, out var id)) + { + id = modAttrib.substanceStart; + } + var guideKey = substanceParams.displayNameKey + "_GUIDE"; + + MelonLogger.Msg("current id" + id + " name " + eid); customSubstances.Add((Substance)id, substanceParams); customParams.Add((Substance)id, cParams); - var modAttrib = Assembly.GetCallingAssembly().GetCustomAttribute(); + EIDManager.eidDictionary.Add((Substance)id, $"{modAttrib.id}:{eid}"); - + CustomLocalizer.AddEnString(guideKey, cParams.enGuide); + CustomLocalizer.AddJpString(guideKey, cParams.jpGuide); + CustomLocalizer.AddZhHansString(guideKey, cParams.zhHansGuide); + CustomLocalizer.AddDeString(guideKey, cParams.deGuide); + CustomLocalizer.AddEsString(guideKey, cParams.esGuide); + CustomLocalizer.AddFrString(guideKey, cParams.frGuide); + CustomLocalizer.AddRuString(guideKey, cParams.ruGuide); CustomLocalizer.AddEnString(substanceParams.displayNameKey, cParams.enName); CustomLocalizer.AddJpString(substanceParams.displayNameKey, cParams.jpName); @@ -52,8 +66,9 @@ public static Substance RegisterSubstance(string eid, SubstanceParameters.Param CustomLocalizer.AddRuString(substanceParams.displayNameKey, cParams.ruName); MelonLogger.Msg("Substance registered: " + EIDManager.eidDictionary[(Substance)id]); - id--; - return (Substance)id + 1; + currentId[modAttrib.id] = id + 1; + + return (Substance)id; } private static void CreateErrorSubstance() @@ -92,36 +107,71 @@ public class CustomSubstanceParams /// public string enName; + /// + /// Name in English + /// + public string enGuide; + /// /// Name in Japanese /// public string jpName; + /// + /// Name in Japanese + /// + public string jpGuide; + /// /// Name in Simplified Chinese /// public string zhHansName; + /// + /// Name in Simplified Chinese + /// + public string zhHansGuide; + /// /// Name in German /// public string deName; + /// + /// Name in German + /// + public string deGuide; + /// /// Name in Spanish /// public string esName; + /// + /// Name in Spanish + /// + public string esGuide; + /// /// Name in French /// public string frName; + /// + /// Name in French + /// + public string frGuide; + /// /// Name in Russian /// public string ruName; + /// + /// Name in Russian + /// + public string ruGuide; + /// /// Delegate that is called whenever object is initalizing its script /// diff --git a/PMAPI/PMAPIModAttribute.cs b/PMAPI/PMAPIModAttribute.cs index 144185a..f15a75a 100644 --- a/PMAPI/PMAPIModAttribute.cs +++ b/PMAPI/PMAPIModAttribute.cs @@ -13,13 +13,15 @@ namespace PMAPI public sealed class PMAPIModAttribute : Attribute { public readonly string id; + public readonly int substanceStart; /// /// Attribute that tells PMAPI mod id for use in extended IDs (EID) /// /// Mod id - public PMAPIModAttribute(string id) + public PMAPIModAttribute(string id, int substanceStart) { + this.substanceStart = substanceStart; this.id = id; } } diff --git a/PMAPI/Patches/CubeGeneratorPatches.cs b/PMAPI/Patches/CubeGeneratorPatches.cs index 66e6ee0..b57a54f 100644 --- a/PMAPI/Patches/CubeGeneratorPatches.cs +++ b/PMAPI/Patches/CubeGeneratorPatches.cs @@ -13,14 +13,17 @@ namespace PMAPI.Patches { [HarmonyPatch(typeof(CubeGenerator), nameof(CubeGenerator.GenerateGroup))] internal static class CubeGeneratorGenerateSavedChunkPatch + { private static void Postfix(SaveAndLoad.GroupData groupData) { + var maxSubstance = Enum.GetValues(typeof(Substance)).Cast().Select(x => (int)x).Max(); foreach (var req in CustomSaveManager.loadRequests) { foreach (var cube in groupData.cubes) { - if (cube.substance >= 0 || req.done || cube.pos != req.beh.transform.localPosition || cube.substance != req.cubeBase.substance) + + if ((int)cube.substance <= maxSubstance || req.done || cube.pos != req.beh.transform.localPosition || cube.substance != req.cubeBase.substance) continue; req.beh.GetType().GetMethod("Load").Invoke(req.beh, new string[] { cube.states[0] }); @@ -45,7 +48,7 @@ private static void Postfix() namespace PMAPI.OreGen.Patches { [HarmonyPatch(typeof(CubeGenerator), nameof(CubeGenerator.GenerateOre), typeof(Substance), typeof(float), typeof(float), typeof(float), typeof(Vector3))] - internal static class CubeGeneratorGenerateOrePatch + internal static class CubeGeneratorGenerateOrePatch { private static void Prefix(ref Substance substance, ref float minSize, ref float maxSize, ref float alpha) { diff --git a/PMAPI/Patches/SubstanceManagerGetParameterPatch.cs b/PMAPI/Patches/SubstanceManagerGetParameterPatch.cs index c7c4991..1e557c4 100644 --- a/PMAPI/Patches/SubstanceManagerGetParameterPatch.cs +++ b/PMAPI/Patches/SubstanceManagerGetParameterPatch.cs @@ -14,7 +14,8 @@ internal static class SubstanceManagerGetParameterPatch { private static bool Prefix(ref SubstanceParameters.Param __result, Substance substance) { - if (substance >= 0) + var maxSubstance = Enum.GetValues(typeof(Substance)).Cast().Select(x => (int)x).Max(); + if ((int)substance <= maxSubstance) return true; if (CustomSubstanceManager.customSubstances.TryGetValue(substance, out SubstanceParameters.Param val)) diff --git a/TestMod/CentrifugeBeh.cs b/TestMod/CentrifugeBeh.cs new file mode 100644 index 0000000..a8d351e --- /dev/null +++ b/TestMod/CentrifugeBeh.cs @@ -0,0 +1,45 @@ +using Il2Cpp; +using UnityEngine; + +//namespace IndustrialHorizons; + +public class CentrifugeBeh : MonoBehaviour +{ + public CentrifugeBeh(System.IntPtr ptr) + : base(ptr) + { + } + + public Substance refinedSubstance { get; set; } + //public double meltTemperature { get; set; } = 600; + + private void OnInitialize() + { + this.cubeBase = base.GetComponent(); + this.cubeBase.enabled = true; + } + + private void Start() + { + } + + private void Update() + { + bool flag = !this.updated; + if (flag) + { + bool flag2 = this.cubeBase.heat.GetCelsiusTemperature() > 100; + if (flag2) + { + this.cubeBase.ChangeSubstance(this.refinedSubstance); + this.updated = true; + } + } + } + + // Token: 0x04000009 RID: 9 + private CubeBase cubeBase; + + // Token: 0x0400000B RID: 11 + private bool updated = false; +} \ No newline at end of file diff --git a/TestMod/IndustrialHorizons.cs b/TestMod/IndustrialHorizons.cs new file mode 100644 index 0000000..0572eb3 --- /dev/null +++ b/TestMod/IndustrialHorizons.cs @@ -0,0 +1,559 @@ +using MelonLoader; +using Il2Cpp; +using Il2CppInterop.Runtime.Injection; +using Il2CppSystem; +using System; +using PMAPI; +using UnityEngine; +using PMAPI.CustomSubstances; +using PMAPI.OreGen; +using UnityEngine.SceneManagement; +using System.Text.Json; + +namespace IndustrialHorizons +{ + public class IndustrialHorizons : MelonMod + { + // Mod data class + public class OurData + { + public int Test { get; set; } + + public OurData(int test) + { + Test = test; + } + } + + Substance chalcocite; + Substance copper; + Substance ilmenite; + Substance titaniumoxide; + Substance titanium; + Substance chromite; + Substance chromium; + Substance bauxite; + Substance aluminum; + Substance coal; + Substance steel; + Substance stainlesssteel; + public override void OnInitializeMelon() + { + // Init PMAPI + PMAPIModRegistry.InitPMAPI(this); + + // Register in our behaviour in IL2CPP so the game knows about it + ClassInjector.RegisterTypeInIl2Cpp(new RegisterTypeOptions + { + Interfaces = new System.Type[] { typeof(ICubeBehavior)} + }); + + // Registering modded substances + this.RegisterChalcocite(); + this.RegisterCopper(); + this.RegisterIlmenite(); + this.RegisterTitaniumoxide(); + this.RegisterTitanium(); + this.RegisterChromite(); + this.RegisterChromium(); + this.RegisterBauxite(); + this.RegisterAluminum(); + this.RegisterCoal(); + this.RegisterSteel(); + this.RegisterStainlessSteel(); + CubeMerge.compoundablePairs.Add(new Il2CppSystem.ValueTuple(this.chromite, Substance.Niter), new Il2CppSystem.ValueTuple(1f, this.chromium, 0.6f)); + CubeMerge.compoundablePairs.Add(new Il2CppSystem.ValueTuple(this.coal, Substance.Iron), new Il2CppSystem.ValueTuple(0.5f, this.steel, 1f)); + CubeMerge.compoundablePairs.Add(new Il2CppSystem.ValueTuple(this.chromium, this.steel), new Il2CppSystem.ValueTuple(0.2f, this.stainlesssteel, 1f)); + CubeMerge.compoundablePairs.Add(new Il2CppSystem.ValueTuple(this.ilmenite, Substance.Sulfur), new Il2CppSystem.ValueTuple(0.8f, this.titaniumoxide, 0.7f)); + + // Registering our substances in ore generation + CustomOreManager.RegisterCustomOre(this.chalcocite, new CustomOreManager.CustomOreParams + { + chance = 0.2f, + substanceOverride = Substance.Sulfur, + maxSize = 0.3f, + minSize = 0.1f, + alpha = 1f + }); + CustomOreManager.RegisterCustomOre(this.ilmenite, new CustomOreManager.CustomOreParams + { + chance = 0.03f, + substanceOverride = Substance.TungstenOre, + maxSize = 0.6f, + minSize = 0.4f, + alpha = 1f + }); + CustomOreManager.RegisterCustomOre(this.chromite, new CustomOreManager.CustomOreParams + { + chance = 0.06f, + substanceOverride = Substance.Niter, + maxSize = 0.5f, + minSize = 0.1f, + alpha = 1f + }); + CustomOreManager.RegisterCustomOre(this.bauxite, new CustomOreManager.CustomOreParams + { + chance = 0.05f, + substanceOverride = Substance.Clay, + maxSize = 0.8f, + minSize = 0.2f, + alpha = 1f + }); + CustomOreManager.RegisterCustomOre(this.coal, new CustomOreManager.CustomOreParams + { + chance = 0.05f, + substanceOverride = Substance.Stone, + maxSize = 1.4f, + minSize = 0.8f, + alpha = 1f + }); + } + + // Gets called just when the world was loaded + public void OnWorldWasLoaded() + { + // Outputting mod data. The question mark means that nothing will be outputted if mod data doesn't exist (data == null) + MelonLogger.Msg("Mod data is {0}", ExtDataManager.GetData()?.Test); + } + + void RegisterChalcocite() + { + Material cmat = new(SubstanceManager.GetMaterial("Stone")) + { + name = "Chalcocite (Cu2S)", + color = new Color(0.35f, 0.71f, 0.51f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Sulfur).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_CALCOCITE"; + param.material = cmat.name; + param.density = 5.65f; + param.strength = 90f; + param.stiffness = 30f; + param.hardness = 2.5f; + // Registering our substance as custom substance + this.chalcocite = CustomSubstanceManager.RegisterSubstance("chalcocite", param, new CustomSubstanceParams + { + enName = "Chalcocite (Cu2S)", + jpName = "Chalcocite (Cu2S)", + enGuide = "Heat it to 600 degree to make copper", + jpGuide = "Heat it to 600 degree to make copper", + + behInit = delegate (CubeBase cb) + { + // Adding test behavior + OreBeh oreBeh = cb.gameObject.AddComponent(); + oreBeh.meltTemperature = 600; + oreBeh.refinedSubstance = this.copper; + return oreBeh; + } + }); + + } + + void RegisterCopper() + { + // Getting material + Material cmat = new(SubstanceManager.GetMaterial("AncientAlloy")) + { + name = "Copper (Cu)", + color = new Color(1.00f,0.73f,0.20f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.AncientAlloy).MemberwiseClone().Cast(); + + // Should be unique + param.displayNameKey = "SUB_COPPER"; + param.material = cmat.name; + param.density = 5.65f; + param.strength = 900f; + param.stiffness = 85f; + param.hardness = 2.5f; + param.thermalConductivity = 401f; + param.softeningPoint = 600f; + + // Registering our substance as custom substance + this.copper = CustomSubstanceManager.RegisterSubstance("Copper", param, new CustomSubstanceParams + { + enName = "Copper (Cu)", + jpName = "Copper (Cu)", + enGuide = "Good heat conductibility/electric conductor, can be forged at 600 degrees", + jpGuide = "Good heat conductibility/electric conductor, can be forged at 600 degrees", + + }); + } + + void RegisterIlmenite() + { + Material cmat = new(SubstanceManager.GetMaterial("Stone")) + { + name = "Ilmenite (FeTiO3)", + color = new Color(1f, 0.53f, 0.3f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Stone).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_ILMENITE"; + param.material = cmat.name; + param.density = 5.65f; + param.strength = 300f; + param.stiffness = 40f; + param.hardness = 5.6f; + + // Registering our substance as custom substance + this.ilmenite = CustomSubstanceManager.RegisterSubstance("ilmenite", param, new CustomSubstanceParams + { + enName = "Ilmenite (FeTiO3)", + jpName = "Ilmenite (FeTiO3)", + enGuide = "Combine with sulfur to make TitaniumOxide", + jpGuide = "Combine with sulfur to make TitaniumOxide", + + }); + } + + void RegisterTitaniumoxide() + { + Material cmat = new(SubstanceManager.GetMaterial("QuartzSand")) + + { + name = "Titanium oxide (TiO2)", + color = new Color(0.97f,0.97f,1f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Pyrite).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_TITANIUMOXIDE"; + param.material = cmat.name; + param.density = 4.9f; + param.strength = 120f; + param.stiffness = 120f; + param.hardness = 5.6f; + + // Registering our substance as custom substance + this.titaniumoxide = CustomSubstanceManager.RegisterSubstance("titaniumoxide", param, new CustomSubstanceParams + { + enName = "Titanium oxide (TiO2)", + jpName = "Titanium oxide (TiO2)", + enGuide = "Heat it to 1400 degrees to make Titanium", + jpGuide = "Heat it to 1400 degrees to make Titanium", + behInit = delegate(CubeBase cb) + { + // Adding test behavior + OreBeh oreBeh = cb.gameObject.AddComponent(); + oreBeh.refinedSubstance = this.titanium; + oreBeh.meltTemperature = 1400f; + return oreBeh; + } + }); + } + + void RegisterTitanium() + { + Material cmat = new(SubstanceManager.GetMaterial("Tungsten")) + { + name = "Titanium (Ti)", + color = new Color(0.70f,0.75f,0.71f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Tungsten).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_TITANIUM"; + param.material = cmat.name; + param.density = 4.5f; + param.strength = 2000f; + param.stiffness = 100f; + param.hardness = 6f; + param.softeningPoint = 1200f; + + // Registering our substance as custom substance + this.titanium = CustomSubstanceManager.RegisterSubstance("titanium", param, new CustomSubstanceParams + { + enName = "Titanium (Ti)", + jpName = "Titanium (Ti)", + enGuide = "A lightweight but durable material, can be forged at 1200 degrees", + jpGuide = "A lightweight but durable material, can be forged at 1200 degrees", + + }); + } + + void RegisterChromite() + { + Material cmat = new(SubstanceManager.GetMaterial("Ice")) + { + name = "Chromite (FeCr2O4)", + color = new Color(0.90f,1.00f,0.70f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Pyrite).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_CHROMITE"; + param.material = cmat.name; + param.density = 5.0f; + param.strength = 100f; + param.stiffness = 90f; + param.hardness = 5.4f; + + // Registering our substance as custom substance + this.chromite = CustomSubstanceManager.RegisterSubstance("chromite", param, new CustomSubstanceParams + { + enName = "Chromite (FeCr2O4)", + jpName = "Chromite (FeCr2O4)", + enGuide = "Combine with Niter to make Chromium", + jpGuide = "Combine with Niter to make Chromium", + + }); + } + + void RegisterChromium() + { + Material cmat = new(SubstanceManager.GetMaterial("Iron")) + { + name = "Chromium (Cr)", + color = new Color(0.4f,0.6f,1f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Iron).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_CHROMIUM"; + param.material = cmat.name; + param.density = 7.2f; + param.strength = 1650f; + param.stiffness = 190f; + param.hardness = 8.5f; + + // Registering our substance as custom substance + this.chromium = CustomSubstanceManager.RegisterSubstance("chromium", param, new CustomSubstanceParams + { + enName = "Chromium (Cr)", + jpName = "Chromium (Cr)", + enGuide = "Combine with Steel to make Stainless Steel", + jpGuide = "Combine with Steel to make Stainless Steel", + + }); + } + + void RegisterBauxite() + { + Material cmat = new(SubstanceManager.GetMaterial("QuartzSand")) + { + name = "Bauxite (Al(OH)3)", + color = new Color(0.97f,0.51f,0.47f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.QuartzSand).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_BAUXITE"; + param.material = cmat.name; + param.density = 3f; + param.strength = 40f; + param.stiffness = 20f; + param.hardness = 1f; + + // Registering our substance as custom substance + this.bauxite = CustomSubstanceManager.RegisterSubstance("bauxite", param, new CustomSubstanceParams + { + enName = "Bauxite (Al(OH)3)", + jpName = "Bauxite (Al(OH)3)", + enGuide = "Heat it to 850 degrees to make aluminum", + jpGuide = "Heat it to 850 degrees to make aluminum", + behInit = delegate(CubeBase cb) + { + // Adding test behavior + OreBeh oreBeh = cb.gameObject.AddComponent(); + oreBeh.refinedSubstance = this.aluminum; + oreBeh.meltTemperature = 850f; + return oreBeh; + } + }); + } + + void RegisterAluminum() + { + Material cmat = new(SubstanceManager.GetMaterial("AncientPlastic")) + { + name = "Aluminum (Al)", + color = new Color(0.75f,0.76f,0.76f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.AncientPlastic).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_ALUMINUM"; + param.material = cmat.name; + param.density = 2.7f; + param.strength = 1200f; + param.stiffness = 70f; + param.hardness = 2.75f; + param.softeningPoint = 700f; + + // Registering our substance as custom substance + this.aluminum = CustomSubstanceManager.RegisterSubstance("aluminum", param, new CustomSubstanceParams + { + enName = "Aluminum (Al)", + jpName = "Aluminum (Al)", + enGuide = "Lightweight metal excellent for aircraft, can be forged at 700 degrees", + jpGuide = "Lightweight metal excellent for aircraft, can be forged at 700 degrees", + + }); + } + + private void RegisterCoal() + { + Material material = new Material(SubstanceManager.GetMaterial("Stone")) + { + name = "Coal (C)", + color = new Color(0.2f, 0.1f, 0.1f) + }; + CustomMaterialManager.RegisterMaterial(material); + SubstanceParameters.Param param = SubstanceManager.GetParameter(Substance.Wood).MemberwiseClone().Cast(); + param.displayNameKey = "SUB_COAL"; + param.material = material.name; + param.collisionSound = "stone1"; + param.density = 0.9f; + param.combustionHeat = 14000f; + param.kindlingPoint = 600f; + param.combustionSpeed = 1E-04f; + param.defaultPitch = 0.8f; + param.strength = 55f; + param.stiffness = 20f; + param.hardness = 4f; + + + this.coal = CustomSubstanceManager.RegisterSubstance("coal", param, new CustomSubstanceParams + { + enName = "Coal (C)", + jpName = "Coal (C)", + enGuide = "Fuel, burns stronger than wood and for longer. Combine with iron to make steel.", + jpGuide = "Fuel, burns stronger than wood and for longer. Combine with iron to make steel.", + }); + } + + void RegisterSteel() + { + Material cmat = new(SubstanceManager.GetMaterial("Ice")) + { + name = "Steel (Fe)", + color = new Color(0.80f,0.8f,1f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Iron).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_STEEL"; + param.material = cmat.name; + param.density = 7.8f; + param.strength = 2400f; + param.stiffness = 130f; + param.hardness = 6.2f; + param.softeningPoint = 3000f; + + // Registering our substance as custom substance + this.steel = CustomSubstanceManager.RegisterSubstance("steel", param, new CustomSubstanceParams + { + enName = "Steel (Fe)", + jpName = "Steel (Fe)", + enGuide = "Durable material combine with chromium to make stainless steel, can be forged at 3000 degrees", + jpGuide = "Durable material combine with chromium to make stainless steel, can be forged at 3000 degrees", + }); + } + + void RegisterStainlessSteel() + { + Material cmat = new(SubstanceManager.GetMaterial("Silver")) + { + name = "StainlessSteel (Fe)", + color = new Color(0.70f,0.9f,1f) + }; + // Registering material + CustomMaterialManager.RegisterMaterial(cmat); + + // Getting substance params that our substance is based on and modifying them + var param = SubstanceManager.GetParameter(Substance.Silver).MemberwiseClone().Cast(); + + // overwriteDeez + param.displayNameKey = "SUB_STAINLESSSTEEL"; + param.material = cmat.name; + param.density = 7.8f; + param.strength = 2600f; + param.stiffness = 140f; + param.hardness = 6.5f; + param.softeningPoint = 4000f; + + // Registering our substance as custom substance + this.stainlesssteel = CustomSubstanceManager.RegisterSubstance("stainlesssteel", param, new CustomSubstanceParams + { + enName = "StainlessSteel (Fe)", + jpName = "StainlessSteel (Fe)", + enGuide = "Extremely Durable material immune to water and slime, can be forged at 4000 degrees", + jpGuide = "Extremely Durable material immune to water and slime, can be forged at 4000 degrees", + }); + } + /* public override void OnUpdate() + { + // Spawning stuff above our head + if (Input.GetKeyDown(KeyCode.L)) + { + // Getting player position + var mv = GameObject.Find("XR Origin").GetComponent(); + + // Generating the cube + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(-5f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), Substance.Tungsten); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(-4f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), Substance.Iron); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(-3f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.coal); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(-2f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.chalcocite); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(-1f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.ilmenite); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(0f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.titanium); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(1f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.chromite); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(2f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.chromium); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(3f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.titaniumoxide); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(4f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.bauxite); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(5f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), Substance.Sulfur); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(6f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.steel); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(7f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.stainlesssteel); + CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(7f, 5f, 1f), new Vector3(0.2f, 0.2f, 0.2f), this.copper); + } + + // Writing test data that will be stored in save file + if (Input.GetKeyDown(KeyCode.X)) + ExtDataManager.SetData(new OurData(UnityEngine.Random.RandomRangeInt(1, 100))); + } */ + } +} \ No newline at end of file diff --git a/TestMod/TestMod.csproj b/TestMod/IndustrialHorizons.csproj similarity index 75% rename from TestMod/TestMod.csproj rename to TestMod/IndustrialHorizons.csproj index fbc42d5..8dfcede 100644 --- a/TestMod/TestMod.csproj +++ b/TestMod/IndustrialHorizons.csproj @@ -1,42 +1,53 @@ - - - - net6.0 - enable - - - - - - - - - $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll - false - - - $(PRIMITIER_DIR)\MelonLoader\net6\Il2CppInterop.Runtime.dll - false - - - $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\Il2Cppmscorlib.dll - false - - - $(PRIMITIER_DIR)\MelonLoader\net6\MelonLoader.dll - false - - - $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\UnityEngine.CoreModule.dll - false - - - $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\UnityEngine.InputLegacyModule.dll - false - - - - - - - + + + + net6.0 + enable + + + + + + + + + $(PRIMITIER_DIR)\MelonLoader\net6\0Harmony.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\net6\Il2CppInterop.Runtime.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\Il2Cppmscorlib.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\net6\MelonLoader.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\UnityEngine.CoreModule.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\UnityEngine.InputLegacyModule.dll + false + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\Unity.TextMeshPro.dll + False + + + $(PRIMITIER_DIR)\MelonLoader\Il2CppAssemblies\UnityEngine.UI.dll + False + + + + + + diff --git a/TestMod/OreBeh.cs b/TestMod/OreBeh.cs new file mode 100644 index 0000000..563d4bb --- /dev/null +++ b/TestMod/OreBeh.cs @@ -0,0 +1,48 @@ +using Il2Cpp; +using UnityEngine; +using MelonLoader; + +namespace IndustrialHorizons; + +public class OreBeh : MonoBehaviour +{ + public OreBeh(System.IntPtr ptr) + : base(ptr) + { + } + + public Substance refinedSubstance { get; set; } + public double meltTemperature { get; set; } = 600; + + private void OnInitialize() + { + this.cubeBase = base.GetComponent(); + this.cubeBase.enabled = true; + } + + private void Start() + { + } + + private void Update() + { + bool flag = !this.updated; + // Remove later + //MelonLogger.Msg("velocity" + this.cubeBase.pit); + if (flag) + { + bool flag2 = this.cubeBase.heat.GetCelsiusTemperature() > meltTemperature; + if (flag2) + { + this.cubeBase.ChangeSubstance(this.refinedSubstance); + this.updated = true; + } + } + } + + // Token: 0x04000009 RID: 9 + private CubeBase cubeBase; + + // Token: 0x0400000B RID: 11 + private bool updated = false; +} \ No newline at end of file diff --git a/TestMod/Properties/AssemblyInfo.cs b/TestMod/Properties/AssemblyInfo.cs index b27a40a..31dba23 100644 --- a/TestMod/Properties/AssemblyInfo.cs +++ b/TestMod/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ using MelonLoader; using PMAPI; -[assembly: MelonInfo(typeof(TestMod.TestMod), "Test Mod", "1.0.0", "Seva167")] +[assembly: MelonInfo(typeof(IndustrialHorizons.IndustrialHorizons), "Industrial Horizons", "1.0.0", "UnrivalledSuperHottie")] [assembly: MelonGame("PrimitierDev", "Primitier")] [assembly: MelonAdditionalDependencies("PMAPI")] [assembly: MelonPriority(1)] -[assembly: PMAPIMod("testmod")] +[assembly: PMAPIMod("IndustrialHorizons", substanceStart:1024)] diff --git a/TestMod/TestMod.cs b/TestMod/TestMod.cs deleted file mode 100644 index 9ff58b3..0000000 --- a/TestMod/TestMod.cs +++ /dev/null @@ -1,196 +0,0 @@ -using MelonLoader; -using Il2Cpp; -using PMAPI; -using UnityEngine; -using Il2CppInterop.Runtime.Injection; -using PMAPI.CustomSubstances; -using PMAPI.OreGen; -using UnityEngine.SceneManagement; -using System.Text.Json; - -namespace TestMod -{ - public class TestMod : MelonMod - { - // Mod data class - public class OurData - { - public int Test { get; set; } - - public OurData(int test) - { - Test = test; - } - } - - Substance blud; - Substance rood; - - public override void OnInitializeMelon() - { - // Init PMAPI - PMAPIModRegistry.InitPMAPI(this); - - // Register in our behaviour in IL2CPP so the game knows about it - ClassInjector.RegisterTypeInIl2Cpp(new RegisterTypeOptions - { - Interfaces = new[] { typeof(ICubeBehavior), typeof(ISavable) } - }); - - // Registering modded substances - RegisterBlud(); - RegisterRood(); - - // Registering our substances in ore generation - CustomOreManager.RegisterCustomOre(blud, new CustomOreManager.CustomOreParams - { - chance = 0.1f, - substanceOverride = Substance.Stone, - maxSize = 0.3f, - minSize = 0.3f, - alpha = 1f - }); - CustomOreManager.RegisterCustomOre(rood, new CustomOreManager.CustomOreParams - { - chance = 0.1f, - substanceOverride = Substance.Stone | Substance.MoonRock, - maxSize = 0.3f, - minSize = 0.3f, - alpha = 1f - }); - } - - // Gets called just when the world was loaded - public void OnWorldWasLoaded() - { - // Outputting mod data. The question mark means that nothing will be outputted if mod data doesn't exist (data == null) - MelonLogger.Msg("Mod data is {0}", ExtDataManager.GetData()?.Test); - } - - // Omg!!1!!11 Blue wood leaf - void RegisterBlud() - { - // Getting wood material and coloring it BLUE - Material cmat = new(SubstanceManager.GetMaterial("Wood")) - { - name = "Blud", - color = Color.blue - }; - // Registering material - CustomMaterialManager.RegisterMaterial(cmat); - - // Getting substance params that our substance is based on and modifying them - var param = SubstanceManager.GetParameter(Substance.Leaf).MemberwiseClone().Cast(); - - // Should be unique - param.displayNameKey = "SUB_BLUD"; - param.material = cmat.name; - - // Registering our substance as custom substance - blud = CustomSubstanceManager.RegisterSubstance("blud", param, new CustomSubstanceParams - { - enName = "Blud", - ruName = "Синево", - zhHansName = "zhHansName", - deName = "deName", - esName = "esName", - frName = "frName", - jpName = "name2", - behInit = (cb) => - { - // Adding test behavior - var beh = cb.gameObject.AddComponent(); - return beh; - } - }); - } - - // Red wood bruh - void RegisterRood() - { - Material cmat = new(SubstanceManager.GetMaterial("Wood")) - { - name = "Rood", - color = Color.red - }; - CustomMaterialManager.RegisterMaterial(cmat); - - var param = SubstanceManager.GetParameter(Substance.Wood).MemberwiseClone().Cast(); - param.displayNameKey = "SUB_ROOD"; - param.material = cmat.name; - rood = CustomSubstanceManager.RegisterSubstance("rood", param, new CustomSubstanceParams - { - enName = "Rood", - ruName = "Кререво", - jpName = "name3" - }); - - // Make rood and blue slime compoundable to form blud - CubeMerge.compoundablePairs.Add(new Il2CppSystem.ValueTuple(rood, Substance.Slime), new Il2CppSystem.ValueTuple(1f, blud, 1f)); - } - - public override void OnUpdate() - { - // Spawning blud above our head - if (Input.GetKeyDown(KeyCode.L)) - { - // Getting player position - var mv = GameObject.Find("XR Origin").GetComponent(); - - // Generating the cube - CubeGenerator.GenerateCube(mv.cameraTransform.position + new Vector3(0f, 10f, 1f), Vector3.one, blud); - } - - // Writing test data that will be stored in save file - if (Input.GetKeyDown(KeyCode.X)) - ExtDataManager.SetData(new OurData(UnityEngine.Random.RandomRangeInt(1, 100))); - } - } - - public class TestBeh : MonoBehaviour - { - public TestBeh(IntPtr ptr) : base(ptr) - { - // Requesting load of cube save data - CustomSaveManager.RequestLoad(this); - } - - CubeBase cubeBase; - - void OnInitialize() - { - // Get the cube base - cubeBase = GetComponent(); - - // Make it hooooooot - cubeBase.heat.AddHeat(1000000f); - } - - // Saved variable - Data data = new("test123"); - - // When cube is going to save it's data return the data that we want to save - public string Save() - { - // Serialize into JSON - return JsonSerializer.Serialize(data); - } - - // When cube is loaded set our variable to loaded data - public void Load(string json) - { - // From JSON to Data - data = JsonSerializer.Deserialize(json); - } - - public class Data - { - public string SomeString { get; set; } - - public Data(string someString) - { - SomeString = someString; - } - } - } -} \ No newline at end of file