mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-03-23 05:33:35 +08:00
WIP: LabOpt
This commit is contained in:
44
LabOptPreloader/LabOptPreloader.cs
Normal file
44
LabOptPreloader/LabOptPreloader.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using MonoMod.Utils;
|
||||
|
||||
namespace LabOptPreloader;
|
||||
|
||||
public static class Preloader
|
||||
{
|
||||
private static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("ModFixerOne Preloader");
|
||||
public static IEnumerable<string> TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" };
|
||||
|
||||
public static void Patch(AssemblyDefinition assembly)
|
||||
{
|
||||
AddMemebers(assembly);
|
||||
}
|
||||
|
||||
private static void AddMemebers(AssemblyDefinition assembly)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gameModule = assembly.MainModule;
|
||||
// Add field: int LabComponent.rootLabId;
|
||||
gameModule.GetType("LabComponent").AddFied("rootLabId", gameModule.TypeSystem.Int32);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Failed to add `int LabComponent.rootLabId`!");
|
||||
Logger.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddFied(this TypeDefinition typeDefinition, string fieldName, TypeReference fieldType)
|
||||
{
|
||||
var newField = new FieldDefinition(fieldName, FieldAttributes.Public, fieldType);
|
||||
typeDefinition.Fields.Add(newField);
|
||||
Logger.LogDebug("Add " + newField);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user