156 lines
5.9 KiB
C#

using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using BepInEx.Logging;
using BepInEx.Configuration;
using UnityEngine;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Networking;
using System.Collections;
using LethalLib.Modules;
using LethalLevelLoader;
using ScarletMansion.GamePatch;
using ScarletMansion.ModPatch;
using ScarletMansion.DunGenPatch;
using ScarletMansion.GamePatch.Managers;
namespace ScarletMansion {
[BepInPlugin(modGUID, modName, modVersion)]
[BepInDependency("imabatby.lethallevelloader", "1.2.0.3")]
[BepInDependency("evaisa.lethallib", "0.13.2")]
[BepInDependency("dev.ladyalice.dungenplus", "1.1.0")]
//[BepInDependency(ModCompability.advancedCompanyGuid, BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(ModCompability.lethalConfigGuid, BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(ModCompability.facilityMeldownGuid, BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(ModCompability.reserveFlashlightGuid, BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency(ModCompability.reserveKeyGuid, BepInDependency.DependencyFlags.SoftDependency)]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin {
public const string modGUID = "dev.ladyalice.scarletmansion";
private const string modName = "Scarlet Mansion";
private const string modVersion = "1.3.26";
public readonly Harmony harmony = new Harmony(modGUID);
public static Plugin Instance {get; private set;}
public static PluginConfig MyConfig { get; internal set; }
public static ManualLogSource logger { get; internal set; }
void Awake(){
if (Instance == null) Instance = this;
logger = BepInEx.Logging.Logger.CreateLogSource(modGUID);
logger.LogInfo($"Plugin {modName} has been added!");
MyConfig = new PluginConfig(Config);
//MyConfig.SerializerTest();
ModCompability.GetActiveMods();
ModCompability.ActivateActiveMods();
//harmony.PatchAll(typeof(MenuManagerPatch));
harmony.PatchAll(typeof(InitPatch));
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(LoadAssetsIntoLevelPatch));
harmony.PatchAll(typeof(EnemyVentPatch));
harmony.PatchAll(typeof(JesterAIPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(DoorLockPatch));
harmony.PatchAll(typeof(ShotgunItemPatch));
harmony.PatchAll(typeof(ShovelPatch));
harmony.PatchAll(typeof(GeneratePathPatch));
harmony.PatchAll(typeof(PluginConfig));
SetupForNetcodePatcher();
Assets.LoadAssetBundle();
var dungeonMatchPropeties = ScriptableObject.CreateInstance<DungeonMatchingProperties>();
dungeonMatchPropeties.authorNames.Add(new StringWithRarity("Alice", 10));
/*
var itemLevelMatchProperties = ScriptableObject.CreateInstance<LevelMatchingProperties>();
foreach(var item in Assets.items){
item.stringWithRarity = new StringWithRarity("Alice", 0);
itemLevelMatchProperties.authorNames.Add(item.stringWithRarity);
}
*/
var sdmLevelMatchProperties = ScriptableObject.CreateInstance<LevelMatchingProperties>();
sdmLevelMatchProperties.planetNames.Add(new StringWithRarity("Dine", 300));
sdmLevelMatchProperties.planetNames.Add(new StringWithRarity("Rend", 300));
sdmLevelMatchProperties.planetNames.Add(new StringWithRarity("Titan", 69));
sdmLevelMatchProperties.planetNames.Add(new StringWithRarity("Sanguine", 900));
var extendedContent = new List<ExtendedContent>();
var extendedDungeon = ScriptableObject.CreateInstance<ExtendedDungeonFlow>();
extendedDungeon.name = "Scarlet Devil Mansion";
extendedDungeon.DungeonName = "Scarlet Devil Mansion";
extendedDungeon.DungeonFlow = Assets.dungeon;
extendedDungeon.FirstTimeDungeonAudio = Assets.entranceAudioClip;
extendedDungeon.LevelMatchingProperties = sdmLevelMatchProperties;
extendedDungeon.DynamicDungeonSizeMinMax = new Vector2(1f, 2f);
extendedDungeon.DynamicDungeonSizeLerpRate = 0f;
extendedDungeon.GenerateAutomaticConfigurationOptions = true;
extendedContent.Add(extendedDungeon);
// items
/*
foreach(var item in Assets.items){
var extendedItem = ScriptableObject.CreateInstance<ExtendedItem>();
extendedItem.Item = item.item;
extendedItem.DungeonMatchingProperties = dungeonMatchPropeties;
//extendedItem.LevelMatchingProperties = itemLevelMatchProperties;
extendedContent.Add(extendedItem);
}
*/
var extendedMod = ExtendedMod.Create("Scarlet Devil Mansion", "Alice", extendedContent.ToArray());
PatchedContent.RegisterExtendedMod(extendedMod);
Assets.extendedMod = extendedMod;
Assets.dungeonExtended = extendedDungeon;
extendedDungeon.DungeonEvents.onBeforeDungeonGenerate.AddListener(GeneratePathPatch.GeneratePatch);
//DoorwayManager.onMainEntranceTeleportSpawnedEvent.AddEvent("DoorwayCleanup", DoorwayManager.onMainEntranceTeleportSpawnedFunction);
DunGenPlus.API.AddDunGenExtender(Assets.dungeon, Assets.dunGenExtender);
Assets.dunGenExtender.Events.OnModifyDunGenExtenderProperties.AddListener(DunGenPatch.Patch.UpdateDunGenExtenderProperties);
}
void SetupForNetcodePatcher(){
var types = Assembly.GetExecutingAssembly().GetTypes();
foreach (var type in types) {
//Debug.Log(type);
var methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (var method in methods) {
var attributes = method.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), false);
if (attributes.Length > 0)
{
method.Invoke(null, null);
}
}
}
}
}
}