internal static void Patch(Harmony harmony) { harmony.Patch(AccessTools.Method(typeof(LootDistributionData), nameof(LootDistributionData.Initialize)), postfix: new HarmonyMethod(AccessTools.Method(typeof(LootDistributionPatcher), nameof(LootDistributionPatcher.InitializePostfix)))); Logger.Log("LootDistributionPatcher is done.", LogLevel.Debug); }
internal static void Patch(HarmonyInstance harmony) { harmony.Patch(AccessTools.Method(typeof(PrefabDatabase), nameof(PrefabDatabase.LoadPrefabDatabase)), postfix: new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(PrefabDatabasePatcher.LoadPrefabDatabase_Postfix)))); harmony.Patch(AccessTools.Method(typeof(PrefabDatabase), nameof(PrefabDatabase.GetPrefabForFilename)), prefix: new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(PrefabDatabasePatcher.GetPrefabForFilename_Prefix)))); harmony.Patch(AccessTools.Method(typeof(PrefabDatabase), nameof(PrefabDatabase.GetPrefabAsync)), prefix: new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(PrefabDatabasePatcher.GetPrefabAsync_Prefix)))); Logger.Log("PrefabDatabasePatcher is done.", LogLevel.Debug); }
internal static void PrePatch(Harmony harmony) { PatchUtils.PatchClass(harmony); #if !SUBNAUTICA_STABLE // patching iterator method ProtobufSerializer.DeserializeObjectsAsync MethodInfo DeserializeObjectsAsync = typeof(ProtobufSerializer).GetMethod( nameof(ProtobufSerializer.DeserializeObjectsAsync), BindingFlags.NonPublic | BindingFlags.Instance); harmony.Patch(PatchUtils.GetIteratorMethod(DeserializeObjectsAsync), transpiler: new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(DeserializeObjectsAsync_Transpiler)))); #endif Logger.Log("PrefabDatabasePatcher is done.", LogLevel.Debug); }
internal static void Patch(HarmonyInstance harmony) { Type prefabDatabaseType = typeof(PrefabDatabase); MethodInfo loadPrefabDatabase = prefabDatabaseType.GetMethod("LoadPrefabDatabase", BindingFlags.Public | BindingFlags.Static); MethodInfo getPrefabForFilename = prefabDatabaseType.GetMethod("GetPrefabForFilename", BindingFlags.Public | BindingFlags.Static); MethodInfo getPrefabAsync = prefabDatabaseType.GetMethod("GetPrefabAsync", BindingFlags.Public | BindingFlags.Static); harmony.Patch(loadPrefabDatabase, null, new HarmonyMethod(typeof(PrefabDatabasePatcher).GetMethod("LoadPrefabDatabase_Postfix", BindingFlags.NonPublic | BindingFlags.Static))); harmony.Patch(getPrefabForFilename, new HarmonyMethod(typeof(PrefabDatabasePatcher).GetMethod("GetPrefabForFilename_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), null); harmony.Patch(getPrefabAsync, new HarmonyMethod(typeof(PrefabDatabasePatcher).GetMethod("GetPrefabAsync_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), null); Logger.Log("PrefabDatabasePatcher is done.", LogLevel.Debug); }
internal static void PrePatch(Harmony harmony) { PatchUtils.PatchClass(harmony); var obsoleteInstantiatePrefabAsync = AccessTools.Method(typeof(ProtobufSerializer), nameof(ProtobufSerializer.InstantiatePrefabAsync), new[] { typeof(ProtobufSerializer.GameObjectData) }); if (obsoleteInstantiatePrefabAsync == null) // it means that we have async-only prefabs now, otherwise patch will fail { // patching iterator method ProtobufSerializer.DeserializeObjectsAsync MethodInfo DeserializeObjectsAsync = typeof(ProtobufSerializer).GetMethod( nameof(ProtobufSerializer.DeserializeObjectsAsync), BindingFlags.NonPublic | BindingFlags.Instance); harmony.Patch(PatchUtils.GetIteratorMethod(DeserializeObjectsAsync), transpiler: new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(DeserializeObjectsAsync_Transpiler)))); } Logger.Log("PrefabDatabasePatcher is done.", LogLevel.Debug); }
/// <summary> /// Creates a new <see cref="Texture2D" /> from an image file. /// </summary> /// <param name="filePathToImage">The path to the image file.</param> /// <param name="format"> /// <para>The texture format. By default, this uses <see cref="TextureFormat.BC7" />.</para> /// <para>https://docs.unity3d.com/ScriptReference/TextureFormat.BC7.html</para> /// <para>Don't change this unless you really know what you're doing.</para> /// </param> /// <returns>Will return a new <see cref="Texture2D"/> instance if the file exists; Otherwise returns null.</returns> /// <remarks> /// Ripped from: https://github.com/RandyKnapp/SubnauticaModSystem/blob/master/SubnauticaModSystem/Common/Utility/ImageUtils.cs /// </remarks> public static Texture2D LoadTextureFromFile(string filePathToImage, TextureFormat format = TextureFormat.BC7) { if (File.Exists(filePathToImage)) { byte[] imageBytes = File.ReadAllBytes(filePathToImage); Texture2D texture2D = new Texture2D(2, 2, format, false); if (texture2D.LoadImage(imageBytes)) { return(texture2D); } else { Logger.Log("Error on LoadTextureFromFile call. Texture cannot be loaded: " + filePathToImage, LogLevel.Error); } } else { Logger.Log("Error on LoadTextureFromFile call. File not found at " + filePathToImage, LogLevel.Error); } return(null); }
internal static void PostPatch(Harmony harmony) { PatchUtils.PatchClass(harmony, typeof(PostPatches)); Logger.Log("PrefabDatabasePostPatcher is done.", LogLevel.Debug); }