Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of balrond humanoidRandomizer v1.5.0
plugins/BalrondHumanoidRandomizer.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using Balrond.Shared; using BalrondHumanoidRandomizer.Config; using BalrondHumanoidRandomizer.Monsters; using BalrondHumanoidRandomizer.Networking; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.Audio; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("BalrondHumanoidRandomizer")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BalrondHumanoidRandomizer")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("f405ea1c-ac25-47a3-9aa2-a8f56c14bfd6")] [assembly: AssemblyFileVersion("1.5.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.5.0.0")] [module: UnverifiableCode] namespace Balrond.Shared { public static class AudioRoutingService { public enum AudioRoute { SFX, Ambient, Music, Master } private enum TargetKind { Route, NamedRuntimeGroup } private sealed class AudioTarget { public TargetKind Kind; public AudioRoute Route; public string RuntimeGroupName; public string Reason; } private sealed class AudioBinding { public AudioSource Source; public AudioTarget Target; } private sealed class ProcessedNode { public GameObject Root; public readonly List<AudioBinding> AudioBindings = new List<AudioBinding>(); public readonly List<GameObject> ReferencedRoots = new List<GameObject>(); public readonly HashSet<GameObject> ReferencedRootSet = new HashSet<GameObject>(ReferenceComparer<GameObject>.Instance); } private sealed class ExplicitOverride { public bool UsesNamedGroup; public AudioRoute Route; public string RuntimeGroupName; } private sealed class RuntimeMixerCatalog { private readonly Dictionary<string, AudioMixerGroup> _groupsByName = new Dictionary<string, AudioMixerGroup>(StringComparer.OrdinalIgnoreCase); private AudioMixer _mixer; private AudioMixerGroup _master; private AudioMixerGroup _ambient; private AudioMixerGroup _music; private AudioMixerGroup _sfx; public bool IsReady => (Object)(object)_mixer != (Object)null || (Object)(object)_master != (Object)null || (Object)(object)_ambient != (Object)null || (Object)(object)_music != (Object)null; public void Rebuild(AudioMan audioMan) { _groupsByName.Clear(); _mixer = null; _master = null; _ambient = null; _music = null; _sfx = null; if ((Object)(object)audioMan == (Object)null) { return; } _master = ReadAudioManGroup(audioMan, "m_masterMixer"); _ambient = ReadAudioManGroup(audioMan, "m_ambientMixer"); _music = ReadAudioManGroup(audioMan, "m_musicMixer"); _mixer = GetMixer(_master) ?? GetMixer(_ambient) ?? GetMixer(_music); AddGroup(_master); AddGroup(_ambient); AddGroup(_music); if ((Object)(object)_mixer != (Object)null) { try { AudioMixerGroup[] array = _mixer.FindMatchingGroups(string.Empty); if (array != null) { for (int i = 0; i < array.Length; i++) { AddGroup(array[i]); } } } catch (Exception ex) { Warn("Could not enumerate runtime AudioMixer groups: " + ex.Message); } } _sfx = FindNamedGroup("SFX"); if ((Object)(object)_sfx == (Object)null) { _sfx = QueryExactGroup("SFX"); } if ((Object)(object)_sfx == (Object)null) { AudioMixerGroup val = FindNamedGroup("Effects"); if ((Object)(object)val == (Object)null) { val = QueryExactGroup("Effects"); } _sfx = val; } if ((Object)(object)_sfx == (Object)null) { _sfx = _master; WarnOnce("sfx-group-fallback", "Runtime SFX mixer group was not found. Falling back to the AudioMan master output group."); } } public AudioMixerGroup Resolve(AudioTarget target) { if (target == null) { return ResolveRoute(AudioRoute.SFX); } if (target.Kind == TargetKind.NamedRuntimeGroup) { AudioMixerGroup val = FindNamedGroup(target.RuntimeGroupName); if ((Object)(object)val == (Object)null) { val = QueryExactGroup(target.RuntimeGroupName); } if ((Object)(object)val != (Object)null) { return val; } return ResolveRoute(AudioRoute.SFX); } return ResolveRoute(target.Route); } public bool HasNamedGroup(string groupName) { if (string.IsNullOrEmpty(groupName)) { return false; } return (Object)(object)FindNamedGroup(groupName) != (Object)null || (Object)(object)QueryExactGroup(groupName) != (Object)null; } private AudioMixerGroup ResolveRoute(AudioRoute route) { return (AudioMixerGroup)(route switch { AudioRoute.Ambient => _ambient ?? _sfx ?? _master, AudioRoute.Music => _music ?? _sfx ?? _master, AudioRoute.Master => _master ?? _sfx ?? _ambient ?? _music, _ => _sfx ?? _master ?? _ambient ?? _music, }); } private AudioMixerGroup FindNamedGroup(string groupName) { if (!string.IsNullOrEmpty(groupName) && _groupsByName.TryGetValue(groupName, out var value)) { return value; } return null; } private AudioMixerGroup QueryExactGroup(string groupName) { if ((Object)(object)_mixer == (Object)null || string.IsNullOrEmpty(groupName)) { return null; } try { AudioMixerGroup[] array = _mixer.FindMatchingGroups(groupName); if (array == null) { return null; } foreach (AudioMixerGroup val in array) { AddGroup(val); if ((Object)(object)val != (Object)null && string.Equals(((Object)val).name, groupName, StringComparison.OrdinalIgnoreCase)) { return val; } } } catch (Exception ex) { WarnOnce("query-group-" + groupName, "Could not query runtime AudioMixer group '" + groupName + "': " + ex.Message); } return null; } private void AddGroup(AudioMixerGroup group) { if (!((Object)(object)group == (Object)null) && !string.IsNullOrEmpty(((Object)group).name) && !_groupsByName.ContainsKey(((Object)group).name)) { _groupsByName.Add(((Object)group).name, group); } } private static AudioMixer GetMixer(AudioMixerGroup group) { try { return ((Object)(object)group != (Object)null) ? group.audioMixer : null; } catch { return null; } } private static AudioMixerGroup ReadAudioManGroup(AudioMan audioMan, string fieldName) { try { FieldInfo field = typeof(AudioMan).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return null; } object value = field.GetValue(audioMan); AudioMixerGroup val = (AudioMixerGroup)((value is AudioMixerGroup) ? value : null); if ((Object)(object)val != (Object)null) { return val; } AudioSource val2 = (AudioSource)((value is AudioSource) ? value : null); if ((Object)(object)val2 != (Object)null) { return val2.outputAudioMixerGroup; } } catch (Exception ex) { WarnOnce("audioman-field-" + fieldName, "Could not read AudioMan." + fieldName + ": " + ex.Message); } return null; } } private sealed class ReferenceComparer<T> : IEqualityComparer<T> where T : class { public static readonly ReferenceComparer<T> Instance = new ReferenceComparer<T>(); public bool Equals(T x, T y) { return x == y; } public int GetHashCode(T obj) { return RuntimeHelpers.GetHashCode(obj); } } private const int MaxManagedDepth = 24; private const int MaxCollectionEntries = 4096; private static readonly RuntimeMixerCatalog MixerCatalog = new RuntimeMixerCatalog(); private static readonly Dictionary<string, ExplicitOverride> Overrides = new Dictionary<string, ExplicitOverride>(StringComparer.Ordinal); private static readonly Dictionary<GameObject, ProcessedNode> ProcessedNodes = new Dictionary<GameObject, ProcessedNode>(ReferenceComparer<GameObject>.Instance); private static readonly Dictionary<AudioSource, AudioBinding> SourceBindings = new Dictionary<AudioSource, AudioBinding>(ReferenceComparer<AudioSource>.Instance); private static readonly Dictionary<Type, FieldInfo[]> TraversalFields = new Dictionary<Type, FieldInfo[]>(); private static readonly HashSet<GameObject> RegisteredRootSet = new HashSet<GameObject>(ReferenceComparer<GameObject>.Instance); private static readonly List<GameObject> RegisteredRoots = new List<GameObject>(); private static readonly HashSet<GameObject> ActiveProcessing = new HashSet<GameObject>(ReferenceComparer<GameObject>.Instance); private static readonly HashSet<string> WarnedKeys = new HashSet<string>(StringComparer.Ordinal); private static Action<string> _infoLogger; private static Action<string> _warningLogger; private static Action<string> _errorLogger; private static int _debugMixerChanges; private static int _debugMixerAlreadyCorrect; public static bool DebugLogging { get; set; } public static void ConfigureLogging(Action<string> infoLogger, Action<string> warningLogger, Action<string> errorLogger) { _infoLogger = infoLogger; _warningLogger = warningLogger; _errorLogger = errorLogger; } public static void SetOverride(string gameObjectName, AudioRoute route) { if (!string.IsNullOrWhiteSpace(gameObjectName)) { Overrides[gameObjectName] = new ExplicitOverride { UsesNamedGroup = false, Route = route, RuntimeGroupName = null }; InvalidateClassificationCaches(); } } public static void SetOverrides(AudioRoute route, params string[] gameObjectNames) { if (gameObjectNames == null) { return; } bool flag = false; foreach (string text in gameObjectNames) { if (!string.IsNullOrWhiteSpace(text)) { Overrides[text] = new ExplicitOverride { UsesNamedGroup = false, Route = route, RuntimeGroupName = null }; flag = true; } } if (flag) { InvalidateClassificationCaches(); } } public static void SetMixerGroupOverride(string gameObjectName, string runtimeMixerGroupName) { if (!string.IsNullOrWhiteSpace(gameObjectName) && !string.IsNullOrWhiteSpace(runtimeMixerGroupName)) { Overrides[gameObjectName] = new ExplicitOverride { UsesNamedGroup = true, Route = AudioRoute.SFX, RuntimeGroupName = runtimeMixerGroupName }; InvalidateClassificationCaches(); } } public static void RemoveOverride(string gameObjectName) { if (!string.IsNullOrWhiteSpace(gameObjectName) && Overrides.Remove(gameObjectName)) { InvalidateClassificationCaches(); } } public static void Process(GameObject root) { if (IsUsable((Object)(object)root)) { RegisterRoot(root); if (MixerCatalog.IsReady) { ResetDebugCounters(); ProcessRoot(root); LogDebugSummary(); } } } public static void Process(IEnumerable<GameObject> roots) { if (roots == null) { return; } foreach (GameObject root in roots) { if (IsUsable((Object)(object)root)) { RegisterRoot(root); } } if (!MixerCatalog.IsReady) { return; } ResetDebugCounters(); for (int i = 0; i < RegisteredRoots.Count; i++) { GameObject val = RegisteredRoots[i]; if (IsUsable((Object)(object)val)) { ProcessRoot(val); } } LogDebugSummary(); } public static void OnAudioManAwake(AudioMan audioMan) { if ((Object)(object)audioMan == (Object)null) { return; } ResetDebugCounters(); MixerCatalog.Rebuild(audioMan); if (!MixerCatalog.IsReady) { Error("AudioMan was available, but no usable runtime mixer group could be resolved."); return; } HashSet<GameObject> visited = new HashSet<GameObject>(ReferenceComparer<GameObject>.Instance); for (int i = 0; i < RegisteredRoots.Count; i++) { GameObject val = RegisteredRoots[i]; if (IsUsable((Object)(object)val)) { if (ProcessedNodes.TryGetValue(val, out var value)) { ValidateNodeGraph(value, visited); } else { ProcessRoot(val); } } } LogDebugSummary(); } private static void RegisterRoot(GameObject root) { if (RegisteredRootSet.Add(root)) { RegisteredRoots.Add(root); } } private static void ProcessRoot(GameObject root) { if (!MixerCatalog.IsReady || !IsUsable((Object)(object)root)) { return; } if (ProcessedNodes.TryGetValue(root, out var value)) { ValidateNodeGraph(value, new HashSet<GameObject>(ReferenceComparer<GameObject>.Instance)); } else { if (!ActiveProcessing.Add(root)) { return; } ProcessedNode processedNode = new ProcessedNode { Root = root }; ProcessedNodes[root] = processedNode; try { ScanAudioSources(root, processedNode); ScanBehaviourReferences(root, processedNode); } catch (Exception ex) { Error("Failed to process audio graph for '" + SafeName((Object)(object)root) + "': " + ex); } finally { ActiveProcessing.Remove(root); } } } private static void ScanAudioSources(GameObject root, ProcessedNode node) { AudioSource[] componentsInChildren; try { componentsInChildren = root.GetComponentsInChildren<AudioSource>(true); } catch (Exception ex) { Warn("Could not enumerate AudioSources under '" + SafeName((Object)(object)root) + "': " + ex.Message); return; } if (componentsInChildren == null) { return; } foreach (AudioSource val in componentsInChildren) { if (IsUsable((Object)(object)val)) { if (!SourceBindings.TryGetValue(val, out var value)) { value = new AudioBinding { Source = val, Target = ClassifySource(root, val) }; SourceBindings[val] = value; } if (!node.AudioBindings.Contains(value)) { node.AudioBindings.Add(value); } ApplyBinding(value, root); } } } private static void ScanBehaviourReferences(GameObject root, ProcessedNode node) { MonoBehaviour[] componentsInChildren; try { componentsInChildren = root.GetComponentsInChildren<MonoBehaviour>(true); } catch (Exception ex) { Warn("Could not enumerate MonoBehaviours under '" + SafeName((Object)(object)root) + "': " + ex.Message); return; } if (componentsInChildren == null) { return; } HashSet<object> managedVisited = new HashSet<object>(ReferenceComparer<object>.Instance); foreach (MonoBehaviour val in componentsInChildren) { if (IsUsable((Object)(object)val) && !(val is ZSFX)) { TraverseManagedObject(val, root, node, managedVisited, 0, isComponentRoot: true); } } } private static void TraverseManagedObject(object value, GameObject ownerRoot, ProcessedNode node, HashSet<object> managedVisited, int depth, bool isComponentRoot) { if (value == null || depth > 24) { return; } Type type = value.GetType(); if (!type.IsValueType && !managedVisited.Add(value)) { return; } FieldInfo[] traversalFields = GetTraversalFields(type, isComponentRoot); foreach (FieldInfo fieldInfo in traversalFields) { object value2; try { value2 = fieldInfo.GetValue(value); } catch { continue; } TraverseValue(value2, ownerRoot, node, managedVisited, depth + 1); } } private static void TraverseValue(object value, GameObject ownerRoot, ProcessedNode node, HashSet<object> managedVisited, int depth) { if (value == null || depth > 24) { return; } EffectList val = (EffectList)((value is EffectList) ? value : null); if (val != null) { TraverseEffectList(val, ownerRoot, node); return; } GameObject val2 = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val2 != (Object)null) { HandleReferencedGameObject(val2, ownerRoot, node); return; } Component val3 = (Component)((value is Component) ? value : null); if ((Object)(object)val3 != (Object)null) { if (IsUsable((Object)(object)val3)) { HandleReferencedGameObject(val3.gameObject, ownerRoot, node); } return; } AudioClip val4 = (AudioClip)((value is AudioClip) ? value : null); if ((Object)(object)val4 != (Object)null) { return; } Object val5 = (Object)((value is Object) ? value : null); if (val5 != (Object)null) { ScriptableObject val6 = (ScriptableObject)((value is ScriptableObject) ? value : null); if ((Object)(object)val6 != (Object)null) { TraverseManagedObject(val6, ownerRoot, node, managedVisited, depth, isComponentRoot: false); } return; } if (value is IDictionary dictionary) { int num = 0; { foreach (DictionaryEntry item in dictionary) { TraverseValue(item.Value, ownerRoot, node, managedVisited, depth + 1); num++; if (num >= 4096) { break; } } return; } } if (value is IEnumerable enumerable && !(value is string)) { int num2 = 0; { foreach (object item2 in enumerable) { TraverseValue(item2, ownerRoot, node, managedVisited, depth + 1); num2++; if (num2 >= 4096) { break; } } return; } } Type type = value.GetType(); if (ShouldTraverseManagedType(type)) { TraverseManagedObject(value, ownerRoot, node, managedVisited, depth, isComponentRoot: false); } } private static void TraverseEffectList(EffectList effectList, GameObject ownerRoot, ProcessedNode node) { EffectData[] effectPrefabs = effectList.m_effectPrefabs; if (effectPrefabs == null) { return; } for (int i = 0; i < effectPrefabs.Length; i++) { GameObject prefab = effectPrefabs[i].m_prefab; if (IsUsable((Object)(object)prefab)) { HandleReferencedGameObject(prefab, ownerRoot, node); } } } private static void HandleReferencedGameObject(GameObject referenced, GameObject ownerRoot, ProcessedNode ownerNode) { if (IsUsable((Object)(object)referenced) && IsUsable((Object)(object)ownerRoot) && !IsInsideHierarchy(referenced, ownerRoot)) { if (ownerNode.ReferencedRootSet.Add(referenced)) { ownerNode.ReferencedRoots.Add(referenced); } ProcessRoot(referenced); } } private static bool IsInsideHierarchy(GameObject candidate, GameObject root) { if (candidate == root) { return true; } try { Transform transform = candidate.transform; Transform transform2 = root.transform; return (Object)(object)transform != (Object)null && (Object)(object)transform2 != (Object)null && transform.IsChildOf(transform2); } catch { return false; } } private static AudioTarget ClassifySource(GameObject root, AudioSource source) { AudioTarget audioTarget = FindExplicitOverride(((Component)source).gameObject, root); if (audioTarget != null) { return audioTarget; } if (HierarchyHasSfxPrefix(((Component)source).gameObject, root)) { return RouteTarget(AudioRoute.SFX, "sfx_/vfx_/fx_ GameObject name"); } if (HierarchyHasZSFX(((Component)source).gameObject, root)) { return RouteTarget(AudioRoute.SFX, "ZSFX context"); } AudioMixerGroup val = null; try { val = source.outputAudioMixerGroup; } catch { val = null; } AudioTarget audioTarget2 = ClassifyOldMixerGroup(val); if (audioTarget2 != null) { return audioTarget2; } return RouteTarget(AudioRoute.SFX, "default SFX fallback"); } private static AudioTarget FindExplicitOverride(GameObject sourceObject, GameObject root) { Transform val = null; Transform val2 = null; try { val = (((Object)(object)sourceObject != (Object)null) ? sourceObject.transform : null); val2 = (((Object)(object)root != (Object)null) ? root.transform : null); } catch { return null; } while ((Object)(object)val != (Object)null) { string text = (((Object)(object)((Component)val).gameObject != (Object)null) ? ((Object)((Component)val).gameObject).name : null); if (!string.IsNullOrEmpty(text) && Overrides.TryGetValue(text, out var value)) { if (value.UsesNamedGroup) { return NamedTarget(value.RuntimeGroupName, "explicit mixer-group override on '" + text + "'"); } return RouteTarget(value.Route, "explicit route override on '" + text + "'"); } if (val == val2) { break; } val = val.parent; } return null; } private static bool HierarchyHasSfxPrefix(GameObject sourceObject, GameObject root) { Transform val = null; Transform val2 = null; try { val = (((Object)(object)sourceObject != (Object)null) ? sourceObject.transform : null); val2 = (((Object)(object)root != (Object)null) ? root.transform : null); } catch { return false; } while ((Object)(object)val != (Object)null) { string name = (((Object)(object)((Component)val).gameObject != (Object)null) ? ((Object)((Component)val).gameObject).name : null); if (HasSfxPrefix(name)) { return true; } if (val == val2) { break; } val = val.parent; } return false; } private static bool HierarchyHasZSFX(GameObject sourceObject, GameObject root) { Transform val = null; Transform val2 = null; try { val = (((Object)(object)sourceObject != (Object)null) ? sourceObject.transform : null); val2 = (((Object)(object)root != (Object)null) ? root.transform : null); } catch { return false; } while ((Object)(object)val != (Object)null) { try { if ((Object)(object)((Component)val).GetComponent<ZSFX>() != (Object)null) { return true; } } catch { } if (val == val2) { break; } val = val.parent; } return false; } private static AudioTarget ClassifyOldMixerGroup(AudioMixerGroup oldGroup) { if ((Object)(object)oldGroup == (Object)null || string.IsNullOrEmpty(((Object)oldGroup).name)) { return null; } string name = ((Object)oldGroup).name; if (IsGenericMasterName(name)) { return null; } if (ContainsInvariant(name, "ambient")) { return RouteTarget(AudioRoute.Ambient, "old mixer-group name: " + name); } if (ContainsInvariant(name, "music")) { return RouteTarget(AudioRoute.Music, "old mixer-group name: " + name); } if (ContainsInvariant(name, "sfx") || ContainsInvariant(name, "vfx") || ContainsInvariant(name, "effect")) { return RouteTarget(AudioRoute.SFX, "old mixer-group name: " + name); } if (MixerCatalog.HasNamedGroup(name)) { return NamedTarget(name, "matching runtime mixer-group name"); } return null; } private static bool HasSfxPrefix(string name) { if (string.IsNullOrEmpty(name)) { return false; } return name.StartsWith("sfx_", StringComparison.OrdinalIgnoreCase) || name.StartsWith("vfx_", StringComparison.OrdinalIgnoreCase) || name.StartsWith("fx_", StringComparison.OrdinalIgnoreCase); } private static bool IsGenericMasterName(string name) { return string.Equals(name, "Master", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "MasterAudio", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "Master Mixer", StringComparison.OrdinalIgnoreCase); } private static bool ContainsInvariant(string text, string fragment) { return text != null && fragment != null && text.IndexOf(fragment, StringComparison.OrdinalIgnoreCase) >= 0; } private static AudioTarget RouteTarget(AudioRoute route, string reason) { return new AudioTarget { Kind = TargetKind.Route, Route = route, RuntimeGroupName = null, Reason = reason }; } private static AudioTarget NamedTarget(string groupName, string reason) { return new AudioTarget { Kind = TargetKind.NamedRuntimeGroup, Route = AudioRoute.SFX, RuntimeGroupName = groupName, Reason = reason }; } private static void ApplyBinding(AudioBinding binding, GameObject semanticRoot) { if (binding == null || !IsUsable((Object)(object)binding.Source)) { return; } AudioMixerGroup val = MixerCatalog.Resolve(binding.Target); if ((Object)(object)val == (Object)null) { return; } AudioMixerGroup val2 = null; try { val2 = binding.Source.outputAudioMixerGroup; } catch { val2 = null; } string text = SafeName((Object)(object)val2); bool flag = val2 != val; if (flag) { try { binding.Source.outputAudioMixerGroup = val; if (DebugLogging) { _debugMixerChanges++; } } catch (Exception ex) { Warn("Could not route AudioSource '" + SafeName((Object)(object)((Component)binding.Source).gameObject) + "' under '" + SafeName((Object)(object)semanticRoot) + "': " + ex.Message); return; } } else if (DebugLogging) { _debugMixerAlreadyCorrect++; } if (DebugLogging) { Info("[" + (flag ? "CHANGED" : "OK") + "] AudioSource '" + SafeName((Object)(object)((Component)binding.Source).gameObject) + "' under '" + SafeName((Object)(object)semanticRoot) + "': '" + text + "' -> '" + SafeName((Object)(object)val) + "' (" + ((binding.Target != null) ? binding.Target.Reason : "unknown") + ")."); } } private static void ResetDebugCounters() { if (DebugLogging) { _debugMixerChanges = 0; _debugMixerAlreadyCorrect = 0; } } public static void LogDebugSummary() { if (DebugLogging) { Info("SUMMARY: registeredRoots=" + RegisteredRoots.Count + ", processedNodes=" + ProcessedNodes.Count + ", uniqueAudioSources=" + SourceBindings.Count + ", mixerChanges=" + _debugMixerChanges + ", alreadyCorrect=" + _debugMixerAlreadyCorrect + "."); } } private static void ValidateNodeGraph(ProcessedNode node, HashSet<GameObject> visited) { if (node == null || !IsUsable((Object)(object)node.Root) || !visited.Add(node.Root)) { return; } for (int i = 0; i < node.AudioBindings.Count; i++) { ApplyBinding(node.AudioBindings[i], node.Root); } for (int j = 0; j < node.ReferencedRoots.Count; j++) { GameObject val = node.ReferencedRoots[j]; if (IsUsable((Object)(object)val)) { if (ProcessedNodes.TryGetValue(val, out var value)) { ValidateNodeGraph(value, visited); } else { ProcessRoot(val); } } } } private static FieldInfo[] GetTraversalFields(Type type, bool isComponentRoot) { if (TraversalFields.TryGetValue(type, out var value)) { return value; } List<FieldInfo> list = new List<FieldInfo>(); Type type2 = type; while (type2 != null && type2 != typeof(object) && !(type2 == typeof(MonoBehaviour)) && !(type2 == typeof(Behaviour)) && !(type2 == typeof(Component)) && !(type2 == typeof(ScriptableObject)) && !(type2 == typeof(Object))) { FieldInfo[] array; try { array = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } catch { array = null; } if (array != null) { foreach (FieldInfo fieldInfo in array) { if (ShouldInspectField(fieldInfo)) { list.Add(fieldInfo); } } } type2 = type2.BaseType; } value = list.ToArray(); TraversalFields[type] = value; return value; } private static bool ShouldInspectField(FieldInfo field) { if (field == null || field.IsStatic || field.IsLiteral || field.IsNotSerialized) { return false; } Type fieldType = field.FieldType; if (fieldType == null) { return false; } if (typeof(EffectList).IsAssignableFrom(fieldType) || typeof(GameObject).IsAssignableFrom(fieldType) || typeof(Component).IsAssignableFrom(fieldType) || typeof(ScriptableObject).IsAssignableFrom(fieldType)) { return true; } if (fieldType.IsArray || typeof(IEnumerable).IsAssignableFrom(fieldType)) { return true; } if (fieldType == typeof(object) || fieldType.IsInterface || fieldType.IsAbstract) { return HasSerializeReferenceAttribute(field); } return ShouldTraverseManagedType(fieldType); } private static bool HasSerializeReferenceAttribute(FieldInfo field) { try { object[] customAttributes = field.GetCustomAttributes(inherit: false); if (customAttributes == null) { return false; } foreach (object obj in customAttributes) { if (obj != null) { string fullName = obj.GetType().FullName; if (string.Equals(fullName, "UnityEngine.SerializeReference", StringComparison.Ordinal)) { return true; } } } } catch { } return false; } private static bool ShouldTraverseManagedType(Type type) { if (type == null || type.IsPrimitive || type.IsEnum || type.IsPointer) { return false; } if (type == typeof(string) || type == typeof(decimal) || type == typeof(DateTime) || type == typeof(TimeSpan) || type == typeof(Guid) || type == typeof(IntPtr) || type == typeof(UIntPtr) || type == typeof(Type)) { return false; } if (typeof(Delegate).IsAssignableFrom(type)) { return false; } if (typeof(Object).IsAssignableFrom(type)) { return typeof(ScriptableObject).IsAssignableFrom(type); } string text = type.Namespace ?? string.Empty; if (text.StartsWith("System", StringComparison.Ordinal) || text.StartsWith("UnityEngine", StringComparison.Ordinal)) { return false; } return type.IsClass || type.IsValueType; } private static void InvalidateClassificationCaches() { ProcessedNodes.Clear(); SourceBindings.Clear(); ActiveProcessing.Clear(); if (!MixerCatalog.IsReady) { return; } for (int i = 0; i < RegisteredRoots.Count; i++) { GameObject val = RegisteredRoots[i]; if (IsUsable((Object)(object)val)) { ProcessRoot(val); } } } private static bool IsUsable(Object obj) { if (obj == null) { return false; } try { return obj != (Object)null; } catch { return false; } } private static string SafeName(Object obj) { if (!IsUsable(obj)) { return "<null>"; } try { return obj.name ?? "<unnamed>"; } catch { return "<unavailable>"; } } private static void Info(string message) { if (_infoLogger != null) { _infoLogger("[AudioRoutingService] " + message); } } private static void Warn(string message) { if (_warningLogger != null) { _warningLogger("[AudioRoutingService] " + message); } } private static void Error(string message) { if (_errorLogger != null) { _errorLogger("[AudioRoutingService] " + message); } } private static void WarnOnce(string key, string message) { if (WarnedKeys.Add(key)) { Warn(message); } } } } namespace BalrondHumanoidRandomizer { public class FxReplacment { private List<GameObject> allPrefabs; private string projectName = "[BalrondHumanoidRandomizer]"; public void setInstance(List<GameObject> gameObjects) { allPrefabs = gameObjects; } public void ReplaceOnObject(GameObject gameObject) { if ((Object)(object)gameObject == (Object)null) { return; } SpawnArea component = gameObject.GetComponent<SpawnArea>(); if ((Object)(object)component != (Object)null) { EffectList spawnEffects = component.m_spawnEffects; if (spawnEffects != null) { findEffectsAndChange(spawnEffects.m_effectPrefabs); } } Destructible component2 = gameObject.GetComponent<Destructible>(); if ((Object)(object)component2 != (Object)null) { EffectList hitEffect = component2.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } EffectList destroyedEffect = component2.m_destroyedEffect; if (destroyedEffect != null) { findEffectsAndChange(destroyedEffect.m_effectPrefabs); } } Projectile component3 = gameObject.GetComponent<Projectile>(); if ((Object)(object)component3 != (Object)null) { EffectList hitEffects = component3.m_hitEffects; if (hitEffects != null) { findEffectsAndChange(hitEffects.m_effectPrefabs); } EffectList hitWaterEffects = component3.m_hitWaterEffects; if (hitWaterEffects != null) { findEffectsAndChange(hitWaterEffects.m_effectPrefabs); } EffectList spawnOnHitEffects = component3.m_spawnOnHitEffects; if (spawnOnHitEffects != null) { findEffectsAndChange(spawnOnHitEffects.m_effectPrefabs); } } } public void ReplaceOnVegetation(GameObject gameObject) { Pickable component = gameObject.GetComponent<Pickable>(); if ((Object)(object)component != (Object)null) { fixPlant(component); } Destructible component2 = gameObject.GetComponent<Destructible>(); if ((Object)(object)component2 != (Object)null) { fixPDestructable(component2); } MineRock5 component3 = gameObject.GetComponent<MineRock5>(); if ((Object)(object)component3 != (Object)null) { fixMineRock5(component3); } MineRock component4 = gameObject.GetComponent<MineRock>(); if ((Object)(object)component4 != (Object)null) { fixMineRock(component4); } } private void fixPlant(Pickable pickable) { EffectList pickEffector = pickable.m_pickEffector; if (pickEffector != null) { findEffectsAndChange(pickEffector.m_effectPrefabs); } } private void fixPDestructable(Destructible minerock5) { EffectList hitEffect = minerock5.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } EffectList destroyedEffect = minerock5.m_destroyedEffect; if (destroyedEffect != null) { findEffectsAndChange(destroyedEffect.m_effectPrefabs); } } private void fixMineRock5(MineRock5 minerock5) { EffectList hitEffect = minerock5.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } EffectList destroyedEffect = minerock5.m_destroyedEffect; if (destroyedEffect != null) { findEffectsAndChange(destroyedEffect.m_effectPrefabs); } } private void fixMineRock(MineRock minerock5) { EffectList hitEffect = minerock5.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } EffectList destroyedEffect = minerock5.m_destroyedEffect; if (destroyedEffect != null) { findEffectsAndChange(destroyedEffect.m_effectPrefabs); } } public void ReplaceOnMonster(GameObject gameObject) { if ((Object)(object)gameObject == (Object)null) { Debug.LogWarning((object)(projectName + ":: GameObject not found")); return; } Humanoid component = gameObject.GetComponent<Humanoid>(); if ((Object)(object)component == (Object)null) { Debug.LogWarning((object)(projectName + ":: GameObject not found")); return; } EffectList dropEffects = component.m_dropEffects; if (dropEffects != null) { findEffectsAndChange(dropEffects.m_effectPrefabs); } EffectList backstabHitEffects = ((Character)component).m_backstabHitEffects; if (backstabHitEffects != null) { findEffectsAndChange(backstabHitEffects.m_effectPrefabs); } EffectList consumeItemEffects = component.m_consumeItemEffects; if (consumeItemEffects != null) { findEffectsAndChange(consumeItemEffects.m_effectPrefabs); } EffectList critHitEffects = ((Character)component).m_critHitEffects; if (critHitEffects != null) { findEffectsAndChange(critHitEffects.m_effectPrefabs); } EffectList deathEffects = ((Character)component).m_deathEffects; if (deathEffects != null) { findEffectsAndChange(deathEffects.m_effectPrefabs); } EffectList hitEffects = ((Character)component).m_hitEffects; if (hitEffects != null) { findEffectsAndChange(hitEffects.m_effectPrefabs); } EffectList jumpEffects = ((Character)component).m_jumpEffects; if (jumpEffects != null) { findEffectsAndChange(jumpEffects.m_effectPrefabs); } EffectList perfectBlockEffect = component.m_perfectBlockEffect; if (perfectBlockEffect != null) { findEffectsAndChange(perfectBlockEffect.m_effectPrefabs); } EffectList pickupEffects = component.m_pickupEffects; if (pickupEffects != null) { findEffectsAndChange(pickupEffects.m_effectPrefabs); } EffectList slideEffects = ((Character)component).m_slideEffects; if (slideEffects != null) { findEffectsAndChange(slideEffects.m_effectPrefabs); } EffectList tarEffects = ((Character)component).m_tarEffects; if (tarEffects != null) { findEffectsAndChange(tarEffects.m_effectPrefabs); } EffectList waterEffects = ((Character)component).m_waterEffects; if (waterEffects != null) { findEffectsAndChange(waterEffects.m_effectPrefabs); } FootStep component2 = gameObject.GetComponent<FootStep>(); if (!((Object)(object)component2 != (Object)null)) { return; } List<StepEffect> effects = component2.m_effects; foreach (StepEffect item in effects) { GameObject[] effectPrefabs = item.m_effectPrefabs; List<GameObject> list = new List<GameObject>(); list.AddRange(effectPrefabs); for (int i = 0; i < list.Count; i++) { if ((Object)(object)list[i] != (Object)null) { string name = ((Object)list[i]).name; GameObject val = allPrefabs.Find((GameObject x) => ((Object)x).name == name); if (!((Object)(object)val == (Object)null)) { list[i] = val; } } } } } public void ReplaceOnItem(GameObject gameObject) { if ((Object)(object)gameObject == (Object)null) { return; } ItemDrop component = gameObject.GetComponent<ItemDrop>(); if (!((Object)(object)component == (Object)null)) { EffectList hitEffect = component.m_itemData.m_shared.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } EffectList hitTerrainEffect = component.m_itemData.m_shared.m_hitTerrainEffect; if (hitTerrainEffect != null) { findEffectsAndChange(hitTerrainEffect.m_effectPrefabs); } EffectList holdStartEffect = component.m_itemData.m_shared.m_holdStartEffect; if (holdStartEffect != null) { findEffectsAndChange(holdStartEffect.m_effectPrefabs); } EffectList trailStartEffect = component.m_itemData.m_shared.m_trailStartEffect; if (trailStartEffect != null) { findEffectsAndChange(trailStartEffect.m_effectPrefabs); } EffectList blockEffect = component.m_itemData.m_shared.m_blockEffect; if (blockEffect != null) { findEffectsAndChange(blockEffect.m_effectPrefabs); } } } public void ReplaceFxOnPiece(GameObject gameObject) { if ((Object)(object)gameObject == (Object)null) { return; } Piece component = gameObject.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { EffectList placeEffect = component.m_placeEffect; if (placeEffect != null) { findEffectsAndChange(placeEffect.m_effectPrefabs); } } WearNTear component2 = gameObject.GetComponent<WearNTear>(); if ((Object)(object)component2 != (Object)null) { EffectList hitEffect = component2.m_hitEffect; if (hitEffect != null) { findEffectsAndChange(hitEffect.m_effectPrefabs); } } } private void findEffectsAndChange(EffectData[] effects) { if (effects == null || effects.Length == 0) { return; } foreach (EffectData val in effects) { if ((Object)(object)val.m_prefab != (Object)null) { string name = ((Object)val.m_prefab).name; GameObject val2 = allPrefabs.Find((GameObject x) => ((Object)x).name == name); if (!((Object)(object)val2 == (Object)null)) { val.m_prefab = val2; } } } } } public class ShaderReplacment { public static List<GameObject> prefabsToReplaceShader = new List<GameObject>(); public static List<Material> materialsInPrefabs = new List<Material>(); public string[] shaderlist = new string[49] { "Custom/AlphaParticle", "Custom/Blob", "Custom/Bonemass", "Custom/Clouds", "Custom/Creature", "Custom/Decal", "Custom/Distortion", "Custom/Flow", "Custom/FlowOpaque", "Custom/Grass", "Custom/GuiScroll", "Custom/Heightmap", "Custom/icon", "Custom/InteriorSide", "Custom/LitGui", "Custom/LitParticles", "Custom/mapshader", "Custom/ParticleDecal", "Custom/Piece", "Custom/Player", "Custom/Rug", "Custom/ShadowBlob", "Custom/SkyboxProcedural", "Custom/SkyObject", "Custom/StaticRock", "Custom/Tar", "Custom/Trilinearmap", "Custom/UI/BGBlur", "Custom/Vegetation", "Custom/Water", "Custom/WaterBottom", "Custom/WaterMask", "Custom/Yggdrasil", "Custom/Yggdrasil/root", "Hidden/BlitCopyHDRTonemap", "Hidden/Dof/DepthOfFieldHdr", "Hidden/Dof/DX11Dof", "Hidden/Internal-Loading", "Hidden/Internal-UIRDefaultWorld", "Hidden/SimpleClear", "Hidden/SunShaftsComposite", "Lux Lit Particles/ Bumped", "Lux Lit Particles/ Tess Bumped", "Particles/Standard Surface2", "Particles/Standard Unlit2", "Standard TwoSided", "ToonDeferredShading2017", "Unlit/DepthWrite", "Unlit/Lighting" }; public static List<Shader> shaders = new List<Shader>(); private static readonly HashSet<Shader> CachedShaders = new HashSet<Shader>(); public static bool debug = true; public static Shader findShader(string name) { Shader[] array = Resources.FindObjectsOfTypeAll<Shader>(); if (array.Length == 0) { Debug.LogWarning((object)"SHADER LIST IS EMPTY!"); return null; } if (debug) { } return shaders.Find((Shader x) => ((Object)x).name == name); } public static Shader GetShaderByName(string name) { return shaders.Find((Shader x) => ((Object)x).name == name.Trim()); } public static void debugShaderList(List<Shader> shadersRes) { foreach (Shader shadersRe in shadersRes) { Debug.LogWarning((object)("SHADER NAME IS: " + ((Object)shadersRe).name)); } debug = false; } public static void Replace(GameObject gameObject) { prefabsToReplaceShader.Add(gameObject); GetMaterialsInPrefab(gameObject); } public static void GetMaterialsInPrefab(GameObject gameObject) { Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length == 0) { continue; } Material[] array2 = sharedMaterials; foreach (Material val2 in array2) { if ((Object)(object)val2 != (Object)null) { materialsInPrefabs.Add(val2); } } } } public static void getMeShaders() { AssetBundle[] array = Resources.FindObjectsOfTypeAll<AssetBundle>(); AssetBundle[] array2 = array; foreach (AssetBundle val in array2) { IEnumerable<Shader> enumerable3; try { IEnumerable<Shader> enumerable2; if (!val.isStreamedSceneAssetBundle || !Object.op_Implicit((Object)(object)val)) { IEnumerable<Shader> enumerable = val.LoadAllAssets<Shader>(); enumerable2 = enumerable; } else { enumerable2 = from shader in ((IEnumerable<string>)val.GetAllAssetNames()).Select((Func<string, Shader>)val.LoadAsset<Shader>) where (Object)(object)shader != (Object)null select shader; } enumerable3 = enumerable2; } catch (Exception) { continue; } if (enumerable3 == null) { continue; } foreach (Shader item in enumerable3) { CachedShaders.Add(item); } } } public static void runMaterialFix() { getMeShaders(); shaders.AddRange(CachedShaders); foreach (Material materialsInPrefab in materialsInPrefabs) { Shader shader = materialsInPrefab.shader; if (!((Object)(object)shader == (Object)null)) { string name = ((Object)shader).name; if (!(name == "Standard") && name.Contains("Balrond")) { setProperValue(materialsInPrefab, name); } } } } private static void setProperValue(Material material, string shaderName) { string name = shaderName.Replace("Balrond", "Custom"); name = checkNaming(name); Shader shaderByName = GetShaderByName(name); if (!((Object)(object)shaderByName == (Object)null)) { material.shader = shaderByName; } } private static string checkNaming(string name) { string result = name; if (name.Contains("Bumped")) { result = name.Replace("Custom", "Lux Lit Particles"); } if (name.Contains("Tess Bumped")) { result = name.Replace("Custom", "Lux Lit Particles"); } if (name.Contains("Standard Surface")) { result = name.Replace("Custom", "Particles"); result = result.Replace("Standard Surface2", "Standard Surface"); } if (name.Contains("Standard Unlit")) { result = name.Replace("Custom", "Particles"); result = result.Replace("Standard Unlit", "Standard Unlit2"); result = result.Replace("Standard Unlit22", "Standard Unlit2"); } return result; } } public class StatusEffectBuilder { public List<StatusEffect> statusEffects = new List<StatusEffect>(); public void setShieldStatus(SE_LevelShield statusEffect, Sprite icon) { ((StatusEffect)statusEffect).m_icon = icon; ((StatusEffect)statusEffect).m_ttl = 40f; ((Object)statusEffect).name = "SE_LevelShield"; ((StatusEffect)statusEffect).m_name = "Shield_MonsterRandomizer"; ((StatusEffect)statusEffect).m_tooltip = "You been shielded"; ((StatusEffect)statusEffect).m_activationAnimation = ""; statusEffects.Add((StatusEffect)(object)statusEffect); } public StatusEffect cloneShield(StatusEffect shield, int absorb, string name) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown SE_Shield val = (SE_Shield)shield.Clone(); val.m_absorbDamage = absorb; ((StatusEffect)val).m_name = name; ((Object)val).name = name; return (StatusEffect)(object)val; } public static void setupVisualsForStatus(StatusEffect statusEffect, List<GameObject> list) { if ((Object)(object)statusEffect == (Object)null) { Debug.LogWarning((object)"Status Effect is null!"); return; } string name = statusEffect.m_name; string text = name; if (text == "Shield_MonsterRandomizer") { List<EffectData> list2 = new List<EffectData>(); SE_LevelShield sE_LevelShield = (SE_LevelShield)(object)statusEffect; list2.Add(createEffectData(list, "fx_GoblinShieldBreak", attach: false, "", scale: true)); list2.RemoveAll((EffectData x) => (Object)(object)x.m_prefab == (Object)null); sE_LevelShield.m_breakEffects.m_effectPrefabs = list2.ToArray(); List<EffectData> list3 = new List<EffectData>(); list3.Add(createEffectData(list, "fx_GoblinShieldHit")); list3.RemoveAll((EffectData x) => (Object)(object)x.m_prefab == (Object)null); sE_LevelShield.m_hitEffects.m_effectPrefabs = list3.ToArray(); List<EffectData> list4 = new List<EffectData>(); list4.Add(createEffectData(list, "vfx_GoblinShield", attach: true, "", scale: true)); list4.RemoveAll((EffectData x) => (Object)(object)x.m_prefab == (Object)null); ((StatusEffect)sE_LevelShield).m_startEffects.m_effectPrefabs = list4.ToArray(); } } private static EffectData createEffectData(List<GameObject> list, string name, bool attach = false, string attachName = "", bool scale = false) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown EffectData val = new EffectData(); val.m_variant = -1; val.m_prefab = FindEffect(list, name); val.m_enabled = true; val.m_attach = attach; val.m_scale = scale; val.m_childTransform = attachName; return val; } private static GameObject FindEffect(List<GameObject> list, string name) { if (list == null) { return null; } GameObject val = list.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == name); if ((Object)(object)val != (Object)null) { return val; } return null; } } public class BaseLevelEffectSetupValue { public float scale = 1.1f; public float saturation = 0.5f; public float hue = -0.1f; public float value = -0.1f; public LevelSetup setup = null; public GameObject enabledObject = null; public GameObject enabledObjectLevel2 = null; public GameObject enabledObjectLevel3 = null; public bool setEmmisive = false; public Color emissive = Color.white; public float sumValue = 0.05f; public void getSetup(LevelEffects levelEffects) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)levelEffects == (Object)null) { return; } int num = 0; if (levelEffects.m_levelSetups != null && levelEffects.m_levelSetups.Count > 0) { num = levelEffects.m_levelSetups.Count; setup = levelEffects.m_levelSetups.Last(); } if (num != 0 && setup != null) { scale = setup.m_scale; saturation = setup.m_saturation; hue = setup.m_hue; value = setup.m_value; enabledObject = setup.m_enableObject; emissive = setup.m_emissiveColor; setEmmisive = setup.m_setEmissiveColor; enabledObjectLevel2 = enabledObject; enabledObjectLevel3 = enabledObject; } else { setValues(num, levelEffects); } if ((Object)(object)levelEffects.m_character != (Object)null) { if (((Object)((Component)levelEffects.m_character).gameObject).name == "Deer") { EditDeer(levelEffects); } if (((Object)((Component)levelEffects.m_character).gameObject).name == "Boar") { EditBoar(levelEffects); } } } private void EditDeer(LevelEffects levelEffects) { GameObject enableObject = levelEffects.m_levelSetups[0].m_enableObject; GameObject enableObject2 = levelEffects.m_levelSetups[1].m_enableObject; enabledObjectLevel2 = enableObject; enabledObjectLevel3 = enableObject2; Transform parent = enableObject.transform.parent; GameObject enableObject3 = (enabledObject = ((Component)parent.Find("Antler1")).gameObject); levelEffects.m_levelSetups[0].m_enableObject = enableObject3; levelEffects.m_levelSetups[1].m_enableObject = enableObject3; } private void EditBoar(LevelEffects gameObject) { } private void setValues(int levels, LevelEffects levelEffects) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) float y = ((Component)levelEffects).transform.localScale.y; if (levels == 0) { scale = y; saturation = 0f; hue = 0f; value = 0f; } if (levels == 1) { scale = y + 0.05f; saturation = 0.5f; hue = -0.05f; value = -0.05f; } if (levels == 2) { scale = y + 0.1f; saturation = 0.5f; hue = -0.1f; value = -0.1f; } } } public class HumanoidExtend : MonoBehaviour { private MonsterAI monster; private Humanoid humanoid; private ZNetView m_nview; private bool itemStolen = false; private int growthAmount = 1; private int maxLevel = 7; private int currentLevel; public bool canSteal = false; public bool levelingEnabled = true; public bool expOnKillEnabled = true; public bool bossLeveling = false; public int chanceToSteal = 25; public int currentGrowth = 0; public int growthToLevel = 40000; public int expForKill = 500; public GameObject levelUpEffect; public GameObject stealEffect; public ItemData stolenItem = null; public bool toggleReset = false; private SphereCollider collider; private void Awake() { humanoid = ((Component)this).GetComponent<Humanoid>(); monster = ((Component)this).GetComponent<MonsterAI>(); m_nview = ((Component)this).GetComponent<ZNetView>(); currentLevel = ((Character)humanoid).GetLevel(); if (!((BaseAI)monster).m_character.IsTamed()) { collider = ((Component)monster).gameObject.AddComponent<SphereCollider>(); collider.radius = 3f; ((Collider)collider).isTrigger = true; } m_nview.Register<string, int>("Steal", (Action<long, string, int>)RPC_StolenItem); if (((Character)humanoid).IsBoss() && bossLeveling && !levelingEnabled) { levelingEnabled = false; bossLeveling = false; } Character character = ((BaseAI)monster).m_character; character.m_onDeath = (Action)Delegate.Combine(character.m_onDeath, (Action)delegate { detectKill(((Component)monster).transform); }); Character character2 = ((BaseAI)monster).m_character; character2.m_onDeath = (Action)Delegate.Combine(character2.m_onDeath, (Action)delegate { DropStolen(); }); setMaxExpToLevel(); ((MonoBehaviour)this).InvokeRepeating("CheckLeveling", 1f, 1f); } private void CheckTamed() { if (((BaseAI)monster).m_character.IsTamed()) { Object.DestroyImmediate((Object)(object)collider); } } private void CheckLeveling() { ResetLevel(); CheckTamed(); if (((Component)this).gameObject.activeInHierarchy) { if (levelingEnabled) { currentGrowth += growthAmount; } if (currentGrowth >= growthToLevel && currentLevel < maxLevel) { TransferExpOnLevel(); setMaxExpToLevel(); monsterLevelUp(); } } } private void TransferExpOnLevel() { if (currentGrowth > growthToLevel) { int num = currentGrowth - growthToLevel; if (num > 0) { currentGrowth += num; } } else { currentGrowth = 0; } } private void setMaxExpToLevel() { growthToLevel *= currentLevel; } private void monsterLevelUp() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) currentLevel++; if ((Object)(object)levelUpEffect != (Object)null && ((Character)humanoid).GetLevel() < currentLevel) { Object.Instantiate<GameObject>(levelUpEffect, ((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null); } if (((Character)humanoid).GetLevel() < currentLevel) { ((Character)humanoid).SetLevel(currentLevel); ((Character)humanoid).RPC_Heal((long)((Object)humanoid).GetInstanceID(), ((Character)humanoid).GetMaxHealth(), false); } } public void detectKill(Transform transform) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (!expOnKillEnabled) { return; } Collider[] array = Physics.OverlapSphere(transform.position, 3f, LayerMask.GetMask(new string[1] { "character" })); Collider[] array2 = array; HumanoidExtend humanoidExtend = default(HumanoidExtend); foreach (Collider val in array2) { if (((Component)val).TryGetComponent<HumanoidExtend>(ref humanoidExtend)) { Humanoid component = ((Component)humanoidExtend).GetComponent<Humanoid>(); if (((Character)component).m_faction != ((Character)humanoid).m_faction) { addExpToFound(humanoidExtend); } } } } private void ResetLevel() { if (toggleReset) { ((Character)humanoid).SetLevel(1); toggleReset = false; } } private void addExpToFound(HumanoidExtend humanoidExtend) { humanoidExtend.currentGrowth += expForKill; } private void OnCollisionEnter(Collision collision) { int num = Random.Range(1, 100); Player val = default(Player); if (!itemStolen && num <= 33 && canSteal && collision.gameObject.TryGetComponent<Player>(ref val) && ((Character)val).m_nview.IsValid()) { CustomSteal(monster, val); itemStolen = true; } } private void CustomSteal(MonsterAI monster, Player player) { Inventory inventory = ((Humanoid)player).GetInventory(); FindItemToSteal(inventory, player); } private void FindItemToSteal(Inventory inventory, Player player) { List<ItemData> allItems = inventory.GetAllItems(); List<ItemData> list = allItems.FindAll((ItemData x) => (!x.m_equipped && x.m_quality == 1 && x.m_variant == 0 && !x.IsWeapon()) || ((Object)x.m_dropPrefab).name.Contains("Torch")); if (list.Count > 0) { int index = Random.Range(0, list.Count); GameObject dropPrefab = list[index].m_dropPrefab; string name = list[index].m_shared.m_name; Debug.Log((object)("STOLEN ITEM: " + ((Object)dropPrefab).name)); ((Character)player).Message((MessageType)2, name + " was stolen!", 0, (Sprite)null, false); stolenItem = list[index]; inventory.RemoveItem(list[index]); m_nview.InvokeRPC("Steal", new object[2] { ((Object)list[index].m_dropPrefab).name, list[index].m_stack }); } else { Debug.Log((object)"There was nothing to steal"); } } private void RPC_StolenItem(long sender, string name, int amount) { //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items == null) { return; } GameObject val = ObjectDB.instance.m_items.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == name); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null || val2.m_itemData == null) { Debug.LogWarning((object)("BalrondHumanoidRandomizer: Could not restore stolen item prefab: " + name)); return; } stolenItem = val2.m_itemData.Clone(); stolenItem.m_stack = amount; if ((Object)(object)stealEffect != (Object)null) { Object.Instantiate<GameObject>(stealEffect, ((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null); } } public void CustomDoorInteract(Transform character, Door door) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)character).transform.position - ((Component)this).transform.position; Vector3 normalized = ((Vector3)(ref val)).normalized; bool flag = Vector3.Dot(((Component)this).transform.forward, normalized) < 0f; door.m_nview.InvokeRPC("UseDoor", new object[2] { ((Object)((Component)humanoid).GetComponent<ZNetView>()).GetInstanceID(), flag }); } private void DropStolen() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (canSteal && itemStolen && stolenItem != null) { Object.Instantiate<GameObject>(stolenItem.m_dropPrefab, ((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null).GetComponent<ItemDrop>().m_itemData.m_stack = stolenItem.m_stack; } } } [Serializable] public class HumanoidRandomizer : MonoBehaviour { private ZNetView m_zview; private MonsterAI m_monsterAI; private Humanoid m_humanoid; private VisEquipment m_visEquipment; public string newName; public bool isNameSet = false; public List<ItemSet> itemSets; public string m_itemSetName = ""; public string m_itemSetSimplified = ""; public int m_weaponStance = 0; private Animator m_animator; public RuntimeAnimatorController sourceAnimator; public Biome spawnBiome = (Biome)1; public bool hasOriginalEquipmentSnapshot; public GameObject[] originalDefaultItems = (GameObject[])(object)new GameObject[0]; public GameObject[] originalRandomArmor = (GameObject[])(object)new GameObject[0]; public GameObject[] originalRandomShield = (GameObject[])(object)new GameObject[0]; public GameObject[] originalRandomWeapon = (GameObject[])(object)new GameObject[0]; public ItemSet[] originalRandomSets = (ItemSet[])(object)new ItemSet[0]; public ItemDrop originalUnarmedWeapon; private void Awake() { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) if (!validatePrefab()) { Debug.LogWarning((object)("I should not be randomized: " + ((Object)((Component)this).gameObject).name)); return; } m_zview = ((Component)this).GetComponent<ZNetView>(); m_monsterAI = ((Component)this).GetComponent<MonsterAI>(); m_humanoid = ((Component)this).GetComponent<Humanoid>(); m_animator = (((Object)(object)m_humanoid != (Object)null) ? ((Character)m_humanoid).m_animator : null); m_visEquipment = ((Component)this).GetComponent<VisEquipment>(); newName = (((Object)(object)m_humanoid != (Object)null) ? ((Character)m_humanoid).m_name : string.Empty); spawnBiome = GetBiome(); if ((Object)(object)m_visEquipment == (Object)null || (Object)(object)m_animator == (Object)null || (Object)(object)m_humanoid == (Object)null || (Object)(object)m_monsterAI == (Object)null || (Object)(object)m_zview == (Object)null || m_zview.m_zdo == null) { Debug.LogWarning((object)("[HUMANOID RANDOMIZER]Incomplete requirments for: " + ((Object)((Component)this).gameObject).name)); if ((Object)(object)m_visEquipment == (Object)null) { Debug.LogWarning((object)"missing: VisEquipment script"); } if ((Object)(object)m_animator == (Object)null) { Debug.LogWarning((object)"missing: animator"); } if ((Object)(object)m_humanoid == (Object)null) { Debug.LogWarning((object)"missing: Humanoid script"); } if ((Object)(object)m_monsterAI == (Object)null) { Debug.LogWarning((object)"missing: MonsterAi script"); } if ((Object)(object)m_zview == (Object)null) { Debug.LogWarning((object)"missing: ZNetView script"); } else if (m_zview.m_zdo == null) { Debug.LogWarning((object)"missing: ZDO"); } return; } string prefabName = editZnetName(((Object)((Component)this).gameObject).name); if (!RandomizerConfig.IsCreatureEnabled(prefabName)) { RestoreOriginalEquipment(); m_zview.m_zdo.Set("humanoidRandomizerActive", false); m_zview.m_zdo.Set("humanoidRandomizerSetName", string.Empty); return; } if (itemSets == null || itemSets.Count == 0) { setupItemSets(); } setAnimatorControler(); bool chosen = m_zview.m_zdo.GetBool("humanoidRandomizerActive", false); PickRandomSet(chosen); if (string.IsNullOrEmpty(m_itemSetName)) { RestoreOriginalEquipment(); return; } setWeaponState(m_itemSetName); m_monsterAI.m_minAttackInterval = 2f; clearMissingFiles(); } public void CaptureOriginalEquipment(Humanoid humanoid) { if (!hasOriginalEquipmentSnapshot && !((Object)(object)humanoid == (Object)null)) { originalDefaultItems = CloneArray(humanoid.m_defaultItems); originalRandomArmor = CloneArray(humanoid.m_randomArmor); originalRandomShield = CloneArray(humanoid.m_randomShield); originalRandomWeapon = CloneArray(humanoid.m_randomWeapon); originalRandomSets = (ItemSet[])((humanoid.m_randomSets != null) ? ((Array)(ItemSet[])humanoid.m_randomSets.Clone()) : ((Array)new ItemSet[0])); originalUnarmedWeapon = humanoid.m_unarmedWeapon; hasOriginalEquipmentSnapshot = true; } } private void RestoreOriginalEquipment() { if (hasOriginalEquipmentSnapshot && !((Object)(object)m_humanoid == (Object)null)) { m_humanoid.m_defaultItems = CloneArray(originalDefaultItems); m_humanoid.m_randomArmor = CloneArray(originalRandomArmor); m_humanoid.m_randomShield = CloneArray(originalRandomShield); m_humanoid.m_randomWeapon = CloneArray(originalRandomWeapon); m_humanoid.m_randomSets = (ItemSet[])((originalRandomSets != null) ? ((Array)(ItemSet[])originalRandomSets.Clone()) : ((Array)new ItemSet[0])); m_humanoid.m_unarmedWeapon = originalUnarmedWeapon; m_itemSetName = string.Empty; m_itemSetSimplified = string.Empty; } } private static GameObject[] CloneArray(GameObject[] source) { return (GameObject[])((source != null) ? ((Array)(GameObject[])source.Clone()) : ((Array)new GameObject[0])); } private void clearMissingFiles() { m_humanoid.m_defaultItems = FilterMissing(m_humanoid.m_defaultItems); m_humanoid.m_randomArmor = FilterMissing(m_humanoid.m_randomArmor); m_humanoid.m_randomShield = FilterMissing(m_humanoid.m_randomShield); } private static GameObject[] FilterMissing(GameObject[] source) { if (source == null || source.Length == 0) { return (GameObject[])(object)new GameObject[0]; } List<GameObject> list = new List<GameObject>(source.Length); foreach (GameObject val in source) { if ((Object)(object)val != (Object)null) { list.Add(val); } } return list.ToArray(); } private void setupItemSets() { switch (editZnetName(((Object)this).name)) { case "Skeleton_Meadows": case "Skeleton_Swamps": case "Skeleton_Mountains": case "Skeleton_DeepNorth": case "Skeleton_aspect": case "Skeleton_Friendly": case "Skeleton": itemSets = VariantTypeCheck.itemSetsSkeleton; break; case "Skeleton_Meadows_noarcher": case "Skeleton_Swamps_noarcher": case "Skeleton_Mountains_noarcher": case "Skeleton_NoArcher": itemSets = VariantTypeCheck.itemSetsSkeletonNoArcher; break; case "Skeleton_Poison": itemSets = VariantTypeCheck.itemSetsSkeletonPoison; break; case "Draugr": itemSets = VariantTypeCheck.itemSetsDraugr; break; case "Draugr_Elite": itemSets = VariantTypeCheck.itemSetsDraugrElite; break; case "Draugr_Ranged": itemSets = VariantTypeCheck.itemSetsDraugrRanged; break; case "Goblin": itemSets = VariantTypeCheck.itemSetsGoblin; break; case "GoblinArcher": itemSets = VariantTypeCheck.itemSetsGoblinArcher; break; case "GoblinShaman": itemSets = VariantTypeCheck.itemSetsGoblinShaman; break; } } private bool validatePrefab() { string[] array = new string[18] { "Skeleton", "Skeleton_NoArcher", "Skeleton_Poison", "Draugr", "Draugr_Elite", "Draugr_Ranged", "Goblin", "GoblinArcher", "GoblinShaman", "Skeleton_Meadows", "Skeleton_Meadows_noarcher", "Skeleton_Swamps", "Skeleton_Swamps_noarcher", "Skeleton_Mountains", "Skeleton_Mountains_noarcher", "Skeleton_DeepNorth", "Skeleton_aspect", "Skeleton_Friendly" }; bool flag = false; string[] array2 = array; foreach (string value in array2) { if (((Object)((Component)this).gameObject).name.Contains(value)) { flag = true; break; } } if (!flag) { return false; } string name = ((Object)((Component)this).gameObject).name; name = editZnetName(name); return array.Contains(name); } private string editZnetName(string name) { name = name.Replace("(Clone)", ""); int num = name.IndexOf("("); if (num >= 0) { name = name.Substring(0, num); } return name.Trim(); } private Biome GetBiome() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) return Heightmap.FindBiome(((Component)this).transform.position); } private void setAnimatorControler() { Animator componentInChildren = ((Component)this).gameObject.GetComponentInChildren<Animator>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.runtimeAnimatorController = sourceAnimator; } else { m_animator.runtimeAnimatorController = sourceAnimator; } } private void PickRandomSet(bool chosen = false) { if (itemSets == null || itemSets.Count == 0) { Debug.LogWarning((object)("[HUMANOID RANDOMIZER] No item sets available for " + ((Object)((Component)this).gameObject).name)); return; } string text = null; ItemSet val = null; if (chosen && (Object)(object)m_zview != (Object)null && m_zview.m_zdo != null) { text = m_zview.m_zdo.GetString("humanoidRandomizerSetName", ""); val = FindItemSet(text); } if (val == null) { text = getWeightedSetName(); val = FindItemSet(text); } if (val == null) { RestoreOriginalEquipment(); m_zview.m_zdo.Set("humanoidRandomizerSetName", string.Empty); m_zview.m_zdo.Set("humanoidRandomizerActive", false); Debug.LogWarning((object)("[HUMANOID RANDOMIZER] No enabled biome-eligible variant is available for " + editZnetName(((Object)((Component)this).gameObject).name) + "; restoring original equipment.")); } else { m_zview.m_zdo.Set("humanoidRandomizerSetName", text); m_itemSetName = text; m_itemSetSimplified = text; m_humanoid.m_randomSets = (ItemSet[])(object)new ItemSet[1] { val }; m_zview.m_zdo.Set("humanoidRandomizerActive", true); } } private ItemSet FindItemSet(string setName) { if (string.IsNullOrEmpty(setName) || itemSets == null) { return null; } for (int i = 0; i < itemSets.Count; i++) { ItemSet val = itemSets[i]; if (val != null && string.Equals(val.m_name, setName, StringComparison.Ordinal)) { return val; } } return null; } private string getWeightedSetName() { if (itemSets == null || itemSets.Count == 0) { return null; } string name = editZnetName(((Object)this).name); List<ItemSet> list = new List<ItemSet>(); List<int> list2 = new List<int>(); long num = 0L; for (int i = 0; i < itemSets.Count; i++) { ItemSet val = itemSets[i]; if (val != null && !string.IsNullOrEmpty(val.m_name) && (!VariantTypeCheck.biome.TryGetValue(val.m_name, out var value) || IsCorrectBiome(value, name))) { int variantWeight = RandomizerConfig.GetVariantWeight(val.m_name); if (variantWeight > 0) { list.Add(val); list2.Add(variantWeight); num += variantWeight; } } } if (list.Count == 0 || num <= 0) { return null; } int num2 = (int)((num > int.MaxValue) ? int.MaxValue : num); int num3 = Random.Range(0, num2); long num4 = 0L; for (int j = 0; j < list.Count; j++) { long val2 = ((num > int.MaxValue) ? ((long)((double)list2[j] / (double)num * 2147483647.0)) : list2[j]); num4 += Math.Max(1L, val2); if (num3 < num4) { return list[j].m_name; } } return list[list.Count - 1].m_name; } private bool IsCorrectBiome(int id, string name) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Invalid comparison between Unknown and I4 //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Invalid comparison between Unknown and I4 switch (name) { default: if (!(name == "Skeleton_Friendly")) { return true; } goto case "Skeleton"; case "Skeleton": case "Skeleton_NoArcher": case "Skeleton_Poison": case "Skeleton_DeepNorth": case "Skeleton_aspect": switch (id) { case 1: return true; case 2: if ((int)spawnBiome != 1) { return true; } break; } if (id == 3 && (int)spawnBiome != 1 && (int)spawnBiome != 8) { return true; } return false; } } private void setMonsterName() { if (((Character)m_humanoid).m_name != prototyepname() + " " + m_itemSetSimplified) { newName = prototyepname() + " " + m_itemSetSimplified; ((Character)m_humanoid).m_name = newName; } } private string prototyepname() { GameObject val = ZNetScene.instance.m_prefabs.Find((GameObject x) => ((Object)x).name == editZnetName(((Object)((Component)this).gameObject).name)); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)"Original not found"); return ((Character)m_humanoid).m_name; } string result = ((Character)val.GetComponent<Humanoid>()).m_name; if (((Object)((Component)this).gameObject).name == "Skeleton_Poison") { result = "Rancid"; } return result; } private string simplifyName(string setName) { if (m_itemSetName.Contains("Guardian")) { return "Guardian"; } if (m_itemSetName.Contains("Marauder")) { return "Marauder"; } if (m_itemSetName.Contains("Warrior")) { return "Warrior"; } return setName; } private void setWeaponState(string setName) { m_animator.SetFloat("weaponStance", 0f); switch (setName) { case "Sailor": case "Bonebreaker": case "Frozenhammer": case "Splasher": m_animator.SetFloat("weaponStance", 3f); break; case "Swordmaster": case "Blackblade": case "Soulcalibur": m_animator.SetFloat("weaponStance", 2f); break; case "Executioner": case "Reaper": case "Reaver": m_animator.SetFloat("weaponStance", 1f); break; case "Arbalist": m_animator.SetFloat("weaponStance", 4f); break; case "Stabber": case "Thief": case "Assassin": case "Savage": case "Corsair": case "Lightbringer": m_animator.SetFloat("weaponStance", 5f); break; default: m_animator.SetFloat("weaponStance", 0f); break; } } public void AddArmorPieces() { if (((Character)m_humanoid).m_level == 1 || (((Object)((Component)this).gameObject).name != "Goblin(Clone)" && ((Object)((Component)this).gameObject).name != "GoblinArcher(Clone)") || ((Character)m_humanoid).m_level == 1) { return; } List<GameObject> list = new List<GameObject>(); list.AddRange(m_humanoid.m_randomSets[0].m_items); GameObject helmet = ObjectDB.instance.m_items.Find((GameObject x) => ((Object)x).name == "GoblinHelmet"); GameObject arms = ObjectDB.instance.m_items.Find((GameObject x) => ((Object)x).name == "GoblinArmband"); GameObject sholders = ObjectDB.instance.m_items.Find((GameObject x) => ((Object)x).name == "GoblinShoulders"); GameObject boots = ObjectDB.instance.m_items.Find((GameObject x) => ((Object)x).name == "GoblinLegband"); switch (((Character)m_humanoid).m_level) { case 2: if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)arms).name) == (Object)null) { list.Add(arms); } break; case 3: if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)arms).name) == (Object)null) { list.Add(arms); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)boots).name) == (Object)null) { list.Add(boots); } break; case 4: if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)arms).name) == (Object)null) { list.Add(arms); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)boots).name) == (Object)null) { list.Add(boots); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)helmet).name) == (Object)null) { list.Add(helmet); } break; case 5: case 6: case 7: if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)arms).name) == (Object)null) { list.Add(arms); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)boots).name) == (Object)null) { list.Add(boots); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)helmet).name) == (Object)null) { list.Add(helmet); } if ((Object)(object)list.Find((GameObject x) => ((Object)x).name == ((Object)sholders).name) == (Object)null) { list.Add(sholders); } break; } m_humanoid.m_randomSets[0].m_items = list.ToArray(); } } public class LevelEffectGenerator { private BaseLevelEffectSetupValue baseLevelEffectSetupValue = new BaseLevelEffectSetupValue(); public void CreateVisuals(LevelEffects levelEffects) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) baseLevelEffectSetupValue.getSetup(levelEffects); int num = 0; if (levelEffects.m_levelSetups != null) { num = levelEffects.m_levelSetups.Count; } int num2 = 6 - num; for (int i = 0; i < num2; i++) { LevelSetup item = createSetup(baseLevelEffectSetupValue.scale, baseLevelEffectSetupValue.saturation, baseLevelEffectSetupValue.hue, baseLevelEffectSetupValue.value, baseLevelEffectSetupValue.setEmmisive, baseLevelEffectSetupValue.emissive, baseLevelEffectSetupValue.sumValue * (float)(i + 1), num2, i + 1); levelEffects.m_levelSetups.Add(item); } } public LevelEffects CreateLevelEffectAt(Transform visual, SkinnedMeshRenderer meshRenderer) { if ((Object)(object)meshRenderer == (Object)null) { return null; } if ((Object)(object)meshRenderer != (Object)null) { LevelEffects val = ((Component)visual).gameObject.AddComponent<LevelEffects>(); val.m_mainRender = (Renderer)(object)meshRenderer; val.m_character = (Character)(object)((Component)visual.parent).gameObject.GetComponent<Humanoid>(); return val; } return null; } public LevelEffects CreateLevelEffectComponent(Transform visual) { SkinnedMeshRenderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<SkinnedMeshRenderer>(); if (componentsInChildren.Length > 1) { return null; } if (componentsInChildren.Length == 1) { LevelEffects val = ((Component)visual).gameObject.AddComponent<LevelEffects>(); val.m_mainRender = (Renderer)(object)componentsInChildren[0]; val.m_character = (Character)(object)((Component)visual.parent).gameObject.GetComponent<Humanoid>(); return val; } return null; } private LevelSetup createSetup(float scale, float saturation, float hue, float value, bool isEmmisive, Color emission, float changeValue, int maxAmount, int lvl) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) LevelSetup val = new LevelSetup(); val.m_scale = scale; val.m_saturation = saturation + changeValue; val.m_hue = hue + changeValue; val.m_value = value + changeValue; val.m_enableObject = pickEnabledObject(maxAmount, lvl); val.m_setEmissiveColor = isEmmisive; val.m_emissiveColor = new Color(emission.r + changeValue, emission.g + changeValue, emission.b + changeValue, emission.a); return val; } private GameObject pickEnabledObject(int maxAmount, int lvl) { if (maxAmount == 6) { if (lvl > 4) { return baseLevelEffectSetupValue.enabledObjectLevel3; } if (lvl > 2) { return baseLevelEffectSetupValue.enabledObjectLevel2; } } if (maxAmount == 3) { if (lvl > 3) { return baseLevelEffectSetupValue.enabledObjectLevel3; } if (lvl > 2) { return baseLevelEffectSetupValue.enabledObjectLevel2; } } if (maxAmount < 3) { switch (lvl) { case 2: return baseLevelEffectSetupValue.enabledObjectLevel3; case 1: return baseLevelEffectSetupValue.enabledObjectLevel2; } } return baseLevelEffectSetupValue.enabledObject; } } public class BuildPieceTargeting { private static string[] names = new string[0]; public void changePieceTargeting(List<GameObject> gameObjects) { List<GameObject> list = gameObjects.FindAll((GameObject x) => (Object)(object)x.GetComponent<WearNTear>() != (Object)null); foreach (GameObject item in list) { Piece component = item.GetComponent<Piece>(); if ((Object)(object)component != (Object)null && names.Contains(((Object)item).name)) { ((StaticTarget)component).m_primaryTarget = true; } if ((Object)(object)component != (Object)null && shouldBePrimaryTarget(item)) { ((StaticTarget)component).m_primaryTarget = true; } setResistances(item); } } private bool shouldBePrimaryTarget(GameObject gameObject) { if ((Object)(object)gameObject.GetComponent<Door>() != (Object)null) { return true; } if ((Object)(object)gameObject.GetComponent<CraftingStation>() != (Object)null) { return true; } if ((Object)(object)gameObject.GetComponent<StationExtension>() != (Object)null) { return true; } if ((Object)(object)gameObject.GetComponent<Container>() != (Object)null) { return false; } return false; } private void setResistances(GameObject gameObject) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) WearNTear component = gameObject.GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_damages.m_chop = setChopDamageResistance(component); component.m_damages.m_pickaxe = setPickaxeDamageResistance(component); component.m_damages.m_fire = setFireDamageResistance(component); } } private DamageModifier setChopDamageResistance(WearNTear wearNTear) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected I4, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) MaterialType materialType = wearNTear.m_materialType; MaterialType val = materialType; return (DamageModifier)((int)val switch { 0 => 6, 3 => 2, 2 => 5, 1 => 1, _ => 0, }); } private DamageModifier setPickaxeDamageResistance(WearNTear wearNTear) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected I4, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) MaterialType materialType = wearNTear.m_materialType; MaterialType val = materialType; return (DamageModifier)((int)val switch { 0 => 0, 3 => 1, 2 => 2, 1 => 6, _ => 0, }); } private DamageModifier setFireDamageResistance(WearNTear wearNTear) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected I4, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) MaterialType materialType = wearNTear.m_materialType; MaterialType val = materialType; return (DamageModifier)((int)val switch { 0 => 6, 3 => 2, 2 => 0, 1 => 5, _ => 0, }); } } public class DatabaseAddMethods { public void AddItems(List<GameObject> items) { foreach (GameObject item in items) { AddItem(item); } } public void AddRecipes(List<Recipe> recipes) { foreach (Recipe recipe in recipes) { AddRecipe(recipe); } } public void AddStatuseffects(List<StatusEffect> statusEffects) { foreach (StatusEffect statusEffect in statusEffects) { AddStatus(statusEffect); } } private bool IsObjectDBValid() { return (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count != 0 && ObjectDB.instance.m_recipes.Count != 0 && (Object)(object)ObjectDB.instance.GetItemPrefab("Amber") != (Object)null; } private void AddStatus(StatusEffect status) { if (!IsObjectDBValid()) { return; } if ((Object)(object)status != (Object)null) { if ((Object)(object)ObjectDB.instance.m_StatusEffects.Find((StatusEffect x) => ((Object)x).name == ((Object)status).name) == (Object)null) { ObjectDB.instance.m_StatusEffects.Add(status); } } else { Debug.LogError((object)("BalrondHumanoidRandomizer: " + ((Object)status).name + " - Status not found")); } } private void AddRecipe(Recipe recipe) { if (!IsObjectDBValid()) { return; } if ((Object)(object)recipe != (Object)null) { if ((Object)(object)ObjectDB.instance.GetRecipe(recipe.m_item.m_itemData) == (Object)null) { ObjectDB.instance.m_recipes.Add(recipe); } } else { Debug.LogError((object)("BalrondHumanoidRandomizer: " + ((Object)recipe).name + " - Recipe not found")); } } private void AddItem(GameObject newPrefab) { if (!IsObjectDBValid()) { return; } ItemDrop component = newPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null) { if ((Object)(object)ObjectDB.instance.GetItemPrefab(((Object)newPrefab).name) == (Object)null) { ObjectDB.instance.m_items.Add(newPrefab); Dictionary<int, GameObject> dictionary = (Dictionary<int, GameObject>)typeof(ObjectDB).GetField("m_itemByHash", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ObjectDB.instance); dictionary[((Object)newPrefab).name.GetHashCode()] = newPrefab; } } else { Debug.LogError((object)("BalrondHumanoidRandomizer: " + ((Object)newPrefab).name + " - ItemDrop not found on prefab")); } } } [BepInPlugin("balrond.astafaraios.BalrondHumanoidRandomizer", "BalrondHumanoidRandomizer", "1.5.0")] public class Launch : BaseUnityPlugin { [HarmonyPatch(typeof(AudioMan), "Awake")] public static class AudioMan_Awake_Path { public static void Postfix(AudioMan __instance) { AudioRoutingService.OnAudioManAwake(__instance); } } [HarmonyPatch(typeof(Game), "Awake")] public static class Game_Awake_Path { public static void Prefix() { hasSpawned = false; SetupNewHudElements(); } } [HarmonyPatch(typeof(MonsterAI), "Awake")] public static class MonsterAI_Path { public static void Postfix(MonsterAI __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).gameObject == (Object)null) && (((Object)((Component)__instance).gameObject).name.Contains("Variant") || (Object)(object)((Component)__instance).gameObject.GetComponent<HumanoidRandomizer>() != (Object)null)) { string baseCreatureName = GetBaseCreatureName(((Component)__instance).gameObject); if (RandomizerConfig.IsCreatureEnabled(baseCreatureName)) { __instance.m_minAttackInterval = 2.5f; } } } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] public static class Object_CopyOtherDB_Path { public static void Postfix() { if (!IsObjectDBValid()) { return; } try { StatusEffect val = ObjectDB.instance.m_StatusEffects.Find((StatusEffect x) => (Object)(object)x != (Object)null && ((Object)x).name == "Spirit"); if ((Object)(object)val != (Object)null && modResourceLoader != null) { val.m_icon = modResourceLoader.spiritBurnIcon; } itemEdits.editItems(ObjectDB.instance.m_items); databaseAddMethods.AddStatuseffects(modResourceLoader.statusEffects); databaseAddMethods.AddRecipes(modResourceLoader.recipes); databaseAddMethods.AddItems(modResourceLoader.attackList); databaseAddMethods.AddItems(modResourceLoader.visualList); } catch (Exception ex) { Debug.LogError((object)("BalrondHumanoidRandomizer: Object_CopyOtherDB_Path failed\n" + ex)); } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public static class ObjectDB_Awake_Path { public static bool hasSpawned; public static void Postfix() { if (!IsObjectDBValid()) { return; } try { StatusEffect val = ObjectDB.instance.m_StatusEffects.Find((StatusEffect x) => (Object)(object)x != (Object)null && ((Object)x).name == "Spirit"); if ((Object)(object)val != (Object)null && modResourceLoader != null) { val.m_icon = modResourceLoader.spiritBurnIcon; } itemEdits.editItems(ObjectDB.instance.m_items); databaseAddMethods.AddStatuseffects(modResourceLoader.statusEffects); databaseAddMethods.AddRecipes(modResourceLoader.recipes); databaseAddMethods.AddItems(modResourceLoader.attackList); databaseAddMethods.AddItems(modResourceLoader.visualList); } catch (Exception ex) { Debug.LogError((object)("BalrondHumanoidRandomizer: ObjectDB_Awake_Path failed\n" + ex)); } } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] public static class CharacterDrop_GenerateDropList_Path { public static void Prefix(CharacterDrop __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.m_character == (Object)null) && __instance.m_character.GetLevel() >= 4) { __instance.m_character.SetLevel(4); } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetScene_Awake_Path { public static void Prefix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null) { Debug.LogWarning((object)"BalrondHumanoidRandomizer: No ZnetScene found"); return; } try { modResourceLoader.AddPrefabsToZnetScene(__instance); if (hasSpawned) { return; } itemSetBuilder.ResetRuntimeState(); pieceTargeting.changePieceTargeting(__instance.m_prefabs); itemSetBuilder.setup(__instance.m_prefabs); itemSetBuilder.fixAllReferences(); GameObject val = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton"); GameObject val2 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_NoArcher"); GameObject val3 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Poison"); GameObject val4 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Meadows"); GameObject val5 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Meadows_noarcher"); GameObject val6 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Swamps"); GameObject val7 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Swamps_noarcher"); GameObject val8 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Mountains"); GameObject val9 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Mountains_noarcher"); GameObject val10 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_DeepNorth"); GameObject val11 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_aspect"); GameObject val12 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Skeleton_Friendly"); GameObject val13 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Draugr"); GameObject val14 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Draugr_Ranged"); GameObject val15 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Draugr_Elite"); GameObject val16 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Goblin"); GameObject val17 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "GoblinArcher"); GameObject val18 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "GoblinShaman"); if ((Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_StatusEffects != null) { StatusEffect val19 = ObjectDB.instance.m_StatusEffects.Find((StatusEffect x) => (Object)(object)x != (Object)null && x.m_name == "Shield_MonsterRandomizer"); if ((Object)(object)val19 != (Object)null) { StatusEffectBuilder.setupVisualsForStatus(val19, __instance.m_prefabs); } } if ((Object)(object)val != (Object)null) { itemSetBuilder.CreateItemSets(val, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton")); } if ((Object)(object)val2 != (Object)null) { itemSetBuilder.CreateItemSets(val2, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_NoArcher")); } if ((Object)(object)val3 != (Object)null) { itemSetBuilder.CreateItemSets(val3, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Poison")); } if ((Object)(object)val4 != (Object)null) { itemSetBuilder.CreateItemSets(val4, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Meadows")); } if ((Object)(object)val5 != (Object)null) { itemSetBuilder.CreateItemSets(val5, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Meadows_noarcher")); } if ((Object)(object)val6 != (Object)null) { itemSetBuilder.CreateItemSets(val6, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Swamps")); } if ((Object)(object)val7 != (Object)null) { itemSetBuilder.CreateItemSets(val7, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Swamps_noarcher")); } if ((Object)(object)val8 != (Object)null) { itemSetBuilder.CreateItemSets(val8, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Mountains")); } if ((Object)(object)val9 != (Object)null) { itemSetBuilder.CreateItemSets(val9, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Mountains_noarcher")); } if ((Object)(object)val10 != (Object)null) { itemSetBuilder.CreateItemSets(val10, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_DeepNorth")); } if ((Object)(object)val11 != (Object)null) { itemSetBuilder.CreateItemSets(val11, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_aspect")); } if ((Object)(object)val12 != (Object)null) { itemSetBuilder.CreateItemSets(val12, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Skeleton_Friendly")); } if ((Object)(object)val13 != (Object)null) { itemSetBuilder.CreateItemSets(val13, modResourceLoader.animatorControllerDraugr, RandomizerConfig.IsCreatureEnabled("Draugr")); } if ((Object)(object)val14 != (Object)null) { itemSetBuilder.CreateItemSets(val14, modResourceLoader.animatorControllerDraugr, RandomizerConfig.IsCreatureEnabled("Draugr_Ranged")); } if ((Object)(object)val15 != (Object)null) { itemSetBuilder.CreateItemSets(val15, modResourceLoader.animatorControllerDraugr, RandomizerConfig.IsCreatureEnabled("Draugr_Elite")); } if ((Object)(object)val16 != (Object)null) { itemSetBuilder.CreateItemSets(val16, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("Goblin")); } if ((Object)(object)val17 != (Object)null) { itemSetBuilder.CreateItemSets(val17, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("GoblinArcher")); } if ((Object)(object)val18 != (Object)null) { itemSetBuilder.CreateItemSets(val18, modResourceLoader.animatorController, RandomizerConfig.IsCreatureEnabled("GoblinShaman")); } addPrefabList(itemSetBuilder.prefabs, __instance.m_prefabs); AudioRoutingService.Process((IEnumerable<GameObject>)itemSetBuilder.prefabs); monsterManager.setupMonsterList(__instance.m_prefabs); monsterManager.changeMonsterResistance(); monsterManager.setupSpawners(__instance.m_prefabs); GameObject val20 = __instance.m_prefabs.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Player"); if ((Object)(object)val20 != (Object)null)