using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NpcModels")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NpcModels")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("FB9EF952-D30A-4D2E-B86D-90BAD3DE0269")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace NpcModels
{
[BepInPlugin("kg.MarketplaceNpcModels", "kg.MarketplaceNpcModels", "1.1.0")]
public class NpcModels : BaseUnityPlugin
{
[HarmonyPatch(typeof(FejdStartup), "Start")]
private static class FejdStartup_Start_Patch
{
[UsedImplicitly]
private static void Postfix(FejdStartup __instance)
{
if (CustomCreature == null)
{
CustomCreature = ((IEnumerable<Shader>)Resources.FindObjectsOfTypeAll<Shader>()).FirstOrDefault((Func<Shader, bool>)((Shader s) => ((Object)s).name == "Custom/Creature"));
}
}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
private static class ZNetScene_Awake_Patch
{
[UsedImplicitly]
private static void Postfix(ZNetScene __instance)
{
ToLoad.ForEach(delegate(GameObject p)
{
__instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)p).name)] = p;
IEnumerable<Renderer> source = p.GetComponentsInChildren<MeshRenderer>(true).Cast<Renderer>().Concat((IEnumerable<Renderer>)(object)p.GetComponentsInChildren<SkinnedMeshRenderer>());
foreach (Material item in source.SelectMany((Renderer m) => m.materials))
{
item.shader = CustomCreature;
}
});
}
}
private const string GUID = "kg.MarketplaceNpcModels";
private const string VERSION = "1.1.0";
private static List<GameObject> ToLoad;
private static Shader CustomCreature;
private static AssetBundle GetAssetBundle(string filename)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(filename));
using Stream stream = executingAssembly.GetManifestResourceStream(name);
return AssetBundle.LoadFromStream(stream);
}
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
ToLoad = GetAssetBundle("npcmodels").LoadAllAssets<GameObject>().ToList();
new Harmony("kg.MarketplaceNpcModels").PatchAll();
}
}
}