using MelonLoader;
using HarmonyLib;
using UnityEngine;
using System.Collections.Generic;
using System.Reflection.Emit;
[assembly: MelonInfo(typeof(Class1), "UncensoringBirth", "1.0.0", "JT909HxoB")]
[assembly: MelonGame("WegildDev", "The Outcast Tribe")]
public class Class1 : MelonMod
{
public override void OnInitializeMelon()
{
HarmonyInstance.PatchAll();
MelonLogger.Msg("Patch initialized: Censorship disabled, birth UI restored.");
}
}
[HarmonyPatch(typeof(BirthingStatus), "PlayNextBirthingAnimationStage")]
public static class BirthingStatusPatch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
var setActiveMethod = AccessTools.Method(typeof(GameObject), "SetActive");
var censorshipField = AccessTools.Field(typeof(BirthingStatus), "birthingCensorshipObject");
for (int i = 0; i < codes.Count - 3; i++)
{
// Match: ldarg.0 → ldfld birthingCensorshipObject → ldc.i4.1 → callvirt SetActive
if (codes[i].opcode == OpCodes.Ldarg_0 &&
codes[i + 1].opcode == OpCodes.Ldfld &&
codes[i + 1].operand == censorshipField &&
codes[i + 2].opcode == OpCodes.Ldc_I4_1 &&
codes[i + 3].Calls(setActiveMethod))
{
codes[i + 2] = new CodeInstruction(OpCodes.Ldc_I4_0); // Replace 'true' with 'false'
MelonLogger.Msg($"Censorship SetActive(true) replaced with false at index {i + 2}");
break; // Stop after first match to avoid touching other logic
}
}
return codes;
}
[HarmonyPostfix]
public static void Postfix(object __instance)
{
// Re-enable birthingButtonObject
var buttonField = AccessTools.Field(__instance.GetType(), "birthingButtonObject");
GameObject buttonObj = buttonField?.GetValue(__instance) as GameObject;
if (buttonObj == null)
{
MelonLogger.Msg("Postfix: birthingButtonObject is null.");
}
else
{
buttonObj.SetActive(true);
MelonLogger.Msg($"Postfix: birthingButtonObject re-enabled. Active state: {buttonObj.activeSelf}");
}
// Re-enable forwardButtonController
var controllerField = AccessTools.Field(__instance.GetType(), "forwardButtonController");
var controllerObj = controllerField?.GetValue(__instance);
if (controllerObj == null)
{
MelonLogger.Msg("Postfix: forwardButtonController is null.");
}
else
{
var activateMethod = AccessTools.Method(controllerObj.GetType(), "ActivateButton");
activateMethod?.Invoke(controllerObj, null);
MelonLogger.Msg("Postfix: forwardButtonController.ActivateButton() called.");
}
}
}