Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PMAPI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 56 additions & 6 deletions PMAPI/CustomSubstances/CustomSubstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ internal static void Init()
internal static Dictionary<Substance, CustomSubstanceParams> customParams = new();
internal static SubstanceParameters.Param errorSubParams;

private static int id = -1;

//private static int id = -1;
private static Dictionary<string, int> currentId = new();
/// <summary>
/// Registers custom substance in game
/// </summary>
Expand All @@ -36,12 +36,26 @@ internal static void Init()
/// <returns>ID of registered substance used by the game</returns>
public static Substance RegisterSubstance(string eid, SubstanceParameters.Param substanceParams, CustomSubstanceParams cParams)
{
var modAttrib = Assembly.GetCallingAssembly().GetCustomAttribute<PMAPIModAttribute>();
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<PMAPIModAttribute>();

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);

Expand All @@ -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()
Expand Down Expand Up @@ -92,36 +107,71 @@ public class CustomSubstanceParams
/// </summary>
public string enName;

/// <summary>
/// Name in English
/// </summary>
public string enGuide;

/// <summary>
/// Name in Japanese
/// </summary>
public string jpName;

/// <summary>
/// Name in Japanese
/// </summary>
public string jpGuide;

/// <summary>
/// Name in Simplified Chinese
/// </summary>
public string zhHansName;

/// <summary>
/// Name in Simplified Chinese
/// </summary>
public string zhHansGuide;

/// <summary>
/// Name in German
/// </summary>
public string deName;

/// <summary>
/// Name in German
/// </summary>
public string deGuide;

/// <summary>
/// Name in Spanish
/// </summary>
public string esName;

/// <summary>
/// Name in Spanish
/// </summary>
public string esGuide;

/// <summary>
/// Name in French
/// </summary>
public string frName;

/// <summary>
/// Name in French
/// </summary>
public string frGuide;

/// <summary>
/// Name in Russian
/// </summary>
public string ruName;

/// <summary>
/// Name in Russian
/// </summary>
public string ruGuide;

/// <summary>
/// Delegate that is called whenever object is initalizing its script
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion PMAPI/PMAPIModAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace PMAPI
public sealed class PMAPIModAttribute : Attribute
{
public readonly string id;
public readonly int substanceStart;

/// <summary>
/// Attribute that tells PMAPI mod id for use in extended IDs (EID)
/// </summary>
/// <param name="id">Mod id</param>
public PMAPIModAttribute(string id)
public PMAPIModAttribute(string id, int substanceStart)
{
this.substanceStart = substanceStart;
this.id = id;
}
}
Expand Down
7 changes: 5 additions & 2 deletions PMAPI/Patches/CubeGeneratorPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Substance>().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] });
Expand All @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion PMAPI/Patches/SubstanceManagerGetParameterPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Substance>().Select(x => (int)x).Max();
if ((int)substance <= maxSubstance)
return true;

if (CustomSubstanceManager.customSubstances.TryGetValue(substance, out SubstanceParameters.Param val))
Expand Down
45 changes: 45 additions & 0 deletions TestMod/CentrifugeBeh.cs
Original file line number Diff line number Diff line change
@@ -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<CubeBase>();
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;
}
Loading