Skip to content

Instantly share code, notes, and snippets.

@Myrkie
Created December 9, 2024 12:38
Show Gist options
  • Save Myrkie/4d80a2f9ca347c404f10f34ba0267b49 to your computer and use it in GitHub Desktop.
Save Myrkie/4d80a2f9ca347c404f10f34ba0267b49 to your computer and use it in GitHub Desktop.
Harmony patch to enable developer mode in unity editor requires harmony https://github.com/pardeike/Harmony
using System;
using HarmonyLib;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.Reflection.Emit;
[HarmonyPatch]
public static class PatchIsSourceBuild
{
private static IEnumerable<CodeInstruction> ReturnTrueTranspiler(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
codes.Clear();
codes.Add(new CodeInstruction(OpCodes.Ldc_I4_1));
codes.Add(new CodeInstruction(OpCodes.Ret));
return codes;
}
[HarmonyPatch(typeof(Unsupported), "IsSourceBuild", new Type[] { })]
public static class IsSourceBuildPatchNoParams
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return ReturnTrueTranspiler(instructions);
}
}
[HarmonyPatch(typeof(Unsupported), "IsSourceBuild", typeof(bool))]
public static class IsSourceBuildPatchWithBool
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return ReturnTrueTranspiler(instructions);
}
}
[HarmonyPatch(typeof(Unsupported), "IsDeveloperMode")]
public static class IsDeveloperModePatch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return ReturnTrueTranspiler(instructions);
}
}
}
[InitializeOnLoad]
public static class PatchDeveloperMode
{
static PatchDeveloperMode()
{
var harmony = new Harmony("com.myrkur.patchDevMode");
harmony.PatchAll();
Debug.Log("Harmony patch applied to Unsupported.Developer");
Debug.Log($"DeveloperMode?: {UnityEditor.Unsupported.IsDeveloperMode()}");
Debug.Log($"SourceBuild?: {UnityEditor.Unsupported.IsSourceBuild()}");
Debug.Log($"DeveloperBuild?: {UnityEditor.Unsupported.IsDeveloperBuild()}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment