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 CrimsonBlood v0.10.1
CrimsonBlood.dll
Decompiled a month 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.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Networking; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace CrimsonBlood; internal static class BloodFxBundle { internal sealed class Entry { internal string Kind; internal string Name; internal readonly Dictionary<string, string> Values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); internal float GetFloat(string key, float fallback) { if (Values.TryGetValue(key, out var value) && float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return result; } return fallback; } internal int GetInt(string key, int fallback) { if (Values.TryGetValue(key, out var value) && int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return result; } return fallback; } internal string GetString(string key, string fallback) { if (!Values.TryGetValue(key, out var value)) { return fallback; } return value; } } internal const string BundleName = "marc_bloodfx_v1"; internal const string ManifestAsset = "mbf_manifest"; private static AssetBundle bundle; private static bool attempted; private static List<Entry> entries; private static readonly Dictionary<string, Object> Cache = new Dictionary<string, Object>(StringComparer.OrdinalIgnoreCase); internal static string Status = "not loaded yet"; internal static bool LoadedByThisMod; internal static bool Available => (Object)(object)bundle != (Object)null; internal static AssetBundle Get(ManualLogSource log) { if ((Object)(object)bundle != (Object)null) { return bundle; } if (attempted) { return null; } attempted = true; bundle = FindLoaded(); if ((Object)(object)bundle != (Object)null) { Status = "shared: 'marc_bloodfx_v1' was already loaded by another mod"; log.LogInfo((object)("Blood FX: " + Status)); return bundle; } string text = ResolvePath(); if (text == null) { Status = "built-in blood effects (no blood bundle installed)"; log.LogInfo((object)("Blood FX: " + Status)); return null; } try { bundle = AssetBundle.LoadFromFile(text); } catch (Exception ex) { bundle = null; log.LogWarning((object)("Blood FX: loading " + text + " threw: " + ex.Message)); } if ((Object)(object)bundle == (Object)null) { bundle = FindLoaded(); if ((Object)(object)bundle != (Object)null) { Status = "shared: another copy of 'marc_bloodfx_v1' is loaded"; log.LogInfo((object)("Blood FX: " + Status)); return bundle; } Status = "failed to load " + text + " (built with an incompatible Unity version, or damaged)"; log.LogWarning((object)("Blood FX: " + Status)); return null; } LoadedByThisMod = true; Status = "loaded " + text; log.LogInfo((object)("Blood FX: " + Status)); return bundle; } internal static T Load<T>(string assetName, ManualLogSource log) where T : Object { if (string.IsNullOrEmpty(assetName)) { return default(T); } string key = typeof(T).Name + ":" + assetName; if (Cache.TryGetValue(key, out var value)) { return (T)(object)((value is T) ? value : null); } T val = default(T); AssetBundle val2 = Get(log); if ((Object)(object)val2 != (Object)null) { try { val = val2.LoadAsset<T>(assetName); } catch (Exception ex) { log.LogWarning((object)("Blood FX: could not load '" + assetName + "': " + ex.Message)); } if ((Object)(object)val == (Object)null) { log.LogWarning((object)("Blood FX: no " + typeof(T).Name + " named '" + assetName + "' in marc_bloodfx_v1; that effect uses its fallback.")); } } Cache[key] = (Object)(object)val; return val; } internal static List<Entry> Entries(string kind, ManualLogSource log) { List<Entry> list = new List<Entry>(); List<Entry> list2 = AllEntries(log); for (int i = 0; i < list2.Count; i++) { if (string.Equals(list2[i].Kind, kind, StringComparison.OrdinalIgnoreCase)) { list.Add(list2[i]); } } return list; } private static List<Entry> AllEntries(ManualLogSource log) { if (entries != null) { return entries; } entries = new List<Entry>(); TextAsset val = BloodFxBundle.Load<TextAsset>("mbf_manifest", log); if ((Object)(object)val == (Object)null) { return entries; } string[] array = val.text.Split(new char[2] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); bool flag = false; for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0 || text[0] == '#') { continue; } string[] array2 = text.Split(new char[1] { '|' }); if (array2.Length < 2) { continue; } if (array2[0] == "bundle") { flag = true; if (!string.Equals(array2[1], "marc_bloodfx_v1", StringComparison.OrdinalIgnoreCase)) { log.LogWarning((object)("Blood FX: manifest names bundle '" + array2[1] + "', expected 'marc_bloodfx_v1'.")); } continue; } Entry entry = new Entry { Kind = array2[0], Name = array2[1] }; for (int j = 2; j < array2.Length; j++) { int num = array2[j].IndexOf('='); if (num > 0) { entry.Values[array2[j].Substring(0, num)] = array2[j].Substring(num + 1); } } entries.Add(entry); } if (!flag) { log.LogWarning((object)"Blood FX: manifest has no bundle line; is this the right bundle?"); } return entries; } private static AssetBundle FindLoaded() { try { foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles()) { if ((Object)(object)allLoadedAssetBundle != (Object)null && string.Equals(((Object)allLoadedAssetBundle).name, "marc_bloodfx_v1", StringComparison.OrdinalIgnoreCase)) { return allLoadedAssetBundle; } } } catch (Exception) { } return null; } private static string ResolvePath() { List<string> list = new List<string>(); try { string directoryName = Path.GetDirectoryName(typeof(BloodFxBundle).Assembly.Location); if (!string.IsNullOrEmpty(directoryName)) { list.Add(Path.Combine(directoryName, Path.Combine("Assets", "marc_bloodfx_v1"))); list.Add(Path.Combine(directoryName, Path.Combine("assets", "marc_bloodfx_v1"))); list.Add(Path.Combine(directoryName, "marc_bloodfx_v1")); } } catch { } for (int i = 0; i < list.Count; i++) { if (File.Exists(list[i])) { return list[i]; } } try { string[] files = Directory.GetFiles(Paths.PluginPath, "marc_bloodfx_v1", SearchOption.AllDirectories); if (files.Length != 0) { return files[0]; } } catch { } return null; } } [BepInPlugin("marc.valheim.crimsonblood", "Crimson Blood", "0.10.1.0")] [BepInProcess("valheim.exe")] public sealed class CrimsonBloodPlugin : BaseUnityPlugin { private enum PlayerHitSoundKind { None, Sword, Axe, Arrow } private sealed class BleedState { public Character Target; public Vector3 LastDripPosition; public float LastDripTime; public float Intensity; public bool IsPlayer; public Color Color; } public const string PluginGuid = "marc.valheim.crimsonblood"; public const string PluginName = "Crimson Blood"; public const string PluginVersion = "0.10.1.0"; private const string YoureInjuredGuid = "com.marccunningham.youreinjured"; private const float MinimumMeaningfulHealthLoss = 0.01f; private const float MinimumDirectionMagnitude = 0.0001f; private const int MinimumPoolSize = 4; private const int MaximumPoolSize = 240; private const int MaximumPersistentSplatPoolSize = 512; internal const float DefaultValheimRealSecondsPerDay = 1800f; internal static readonly Color RedBloodColor = new Color(0.34f, 0.02f, 0.025f, 0.88f); internal static readonly Color BlackBloodColor = new Color(0.075f, 0.012f, 0.016f, 0.8f); private const float MinimumVisualDistance = 5f; private const float MaximumVisualDistance = 150f; private const float MinimumImpactCooldown = 0.03f; private const float MaximumImpactCooldown = 0.75f; internal static CrimsonBloodPlugin Instance; private ConfigEntry<bool> enabledConfig; private ConfigEntry<KeyCode> diagnosticKey; private ConfigEntry<KeyCode> clearDiagnosticsKey; private ConfigEntry<float> visualDistance; private ConfigEntry<float> dynamicEffectRenderDistance; private ConfigEntry<float> surfaceSplatRenderDistance; private ConfigEntry<float> minimumHealthLossForVisual; private ConfigEntry<float> perTargetCooldown; private ConfigEntry<bool> useExternalAssetTextures; private ConfigEntry<string> assetRootFolder; private ConfigEntry<bool> useHighDefinitionGroundSplats; private ConfigEntry<int> maximumBurstTextures; private ConfigEntry<int> maximumTrailTextures; private ConfigEntry<int> maximumGroundSplatTextures; private ConfigEntry<int> burstPoolSize; private ConfigEntry<int> streakPoolSize; private ConfigEntry<int> dropletPoolSize; private ConfigEntry<int> splatPoolSize; private ConfigEntry<int> maximumPersistentSurfaceSplats; private ConfigEntry<int> maximumDropletsPerHit; private ConfigEntry<int> maximumStreaksPerHeavyHit; private ConfigEntry<int> maximumBurstsPerHeavyHit; private ConfigEntry<float> dropletGravity; private ConfigEntry<float> dropletLifetime; private ConfigEntry<float> streakLifetime; private ConfigEntry<float> burstLifetime; private ConfigEntry<float> surfaceSplatLifetimeInGameDays; private ConfigEntry<float> minimumSplatHealthLoss; private ConfigEntry<bool> createImmediateImpactSplats; private ConfigEntry<bool> allowWallMarks; private ConfigEntry<bool> groundOnlySurfaceMarks; private ConfigEntry<bool> createFallbackSplatsWhenAirborne; private ConfigEntry<float> surfaceOffset; private ConfigEntry<float> splatSettleSeconds; private ConfigEntry<bool> allowPlayerImpactVisuals; private ConfigEntry<bool> suppressPlayerImpactsWhenYoureInjuredLoaded; private ConfigEntry<bool> disableVanillaBloodEffects; private ConfigEntry<string> vanillaBloodEffectTokens; private ConfigEntry<bool> recordVanillaEffectRoots; private ConfigEntry<float> vanillaEffectWindowSeconds; private ConfigEntry<float> immediateWallProbeDistance; private ConfigEntry<float> maxImmediateSplatSize; private ConfigEntry<bool> useGroundedLethalFinish; private ConfigEntry<bool> logVisualEvents; private ConfigEntry<float> bluntBloodMultiplier; private ConfigEntry<int> bluntMaximumDropletsPerHit; private ConfigEntry<float> bluntBurstSizeMultiplier; private ConfigEntry<float> bluntSplatSizeMultiplier; private ConfigEntry<float> bluntLifetimeMultiplier; private ConfigEntry<bool> enableWoundBodyMarks; private ConfigEntry<float> bodyMarkLifetimeSeconds; private ConfigEntry<int> maxBodyMarksPerTarget; private ConfigEntry<bool> enableBleedingTrails; private ConfigEntry<float> trailMinimumHealthLoss; private ConfigEntry<float> trailDripDistance; private ConfigEntry<float> trailDripInterval; private ConfigEntry<float> trailDripSizeMultiplier; private ConfigEntry<int> maxBleedingActors; private ConfigEntry<bool> enablePlayerBleedDamage; private ConfigEntry<float> playerBleedDamagePerTick; private ConfigEntry<float> playerBleedTickSeconds; private ConfigEntry<bool> playerBleedCanKill; private ConfigEntry<float> playerBleedMinimumHealthLoss; private float nextPlayerBleedDamageTime; private bool inBleedTick; private int bleedTickHitsIgnored; private int playerBleedStartsRefused; private ConfigEntry<KeyCode> bandageKey; private ConfigEntry<bool> requireBandageMaterial; private ConfigEntry<string> bandageItemSharedName; private ConfigEntry<int> bandageItemCost; private ConfigEntry<bool> enableBandageAudio; private ConfigEntry<float> bandageAudioVolume; private ConfigEntry<string> bandageAudioFile; private ConfigEntry<bool> enablePlayerHitSounds; private ConfigEntry<float> playerHitSoundVolume; private ConfigEntry<string> swordHitSoundFile; private ConfigEntry<string> axeHitSoundFile; private ConfigEntry<string> arrowHitSoundFile; private Harmony harmony; private Transform visualRoot; private string pluginDirectory; private string activeAssetDirectory; private Material quadMaterial; private Texture2D fallbackDropletTexture; private Texture2D fallbackBurstTexture; private Texture2D fallbackSplatTexture; private Texture2D fallbackTrailTexture; private readonly List<Texture2D> burstTextures = new List<Texture2D>(); private readonly List<Texture2D> dropletTextures = new List<Texture2D>(); private readonly List<Texture2D> splatTextures = new List<Texture2D>(); private readonly List<Texture2D> trailTextures = new List<Texture2D>(); private readonly List<Texture2D> ownedTextures = new List<Texture2D>(); private readonly List<Material> ownedMaterials = new List<Material>(); private readonly List<CrimsonBloodBurst> burstPool = new List<CrimsonBloodBurst>(); private readonly List<CrimsonBloodStreak> streakPool = new List<CrimsonBloodStreak>(); private readonly List<CrimsonBloodDroplet> dropletPool = new List<CrimsonBloodDroplet>(); private readonly List<CrimsonBloodSplat> splatPool = new List<CrimsonBloodSplat>(); private readonly List<CrimsonBloodBodyMark> bodyMarkPool = new List<CrimsonBloodBodyMark>(); private readonly Dictionary<int, float> nextAllowedImpactTime = new Dictionary<int, float>(); private readonly Dictionary<Character, BleedState> bleedingActors = new Dictionary<Character, BleedState>(); private readonly List<Character> bleedingActorsToRemove = new List<Character>(); private readonly Dictionary<Character, List<CrimsonBloodBodyMark>> bodyMarksByTarget = new Dictionary<Character, List<CrimsonBloodBodyMark>>(); private readonly Queue<string> recentEvents = new Queue<string>(); private readonly Queue<string> recentVanillaEffectRoots = new Queue<string>(); private readonly HashSet<string> windowEffectNames = new HashSet<string>(StringComparer.Ordinal); private readonly Dictionary<string, string[]> vanillaEffectNamesByCreature = new Dictionary<string, string[]>(StringComparer.Ordinal); private readonly RaycastHit[] immediateSurfaceHits = (RaycastHit[])(object)new RaycastHit[16]; private Camera cachedMainCamera; private AudioSource bandageAudioSource; private AudioClip bandageAudioClip; private AudioClip swordHitAudioClip; private AudioClip axeHitAudioClip; private AudioClip arrowHitAudioClip; private string loadedBandageAudioPath; private float nextCameraSearchTime; private float nextCooldownTrimTime; private float nextBleedUpdateTime; private float nextPlayerHitSoundTime; private bool bandageAudioLoadAttempted; private bool bandageAudioLoadInProgress; private bool playerHitAudioLoadAttempted; private bool playerHitAudioLoadInProgress; private int applyDamageHookCalls; private int observedDamageCalls; private int realHealthLossEvents; private int zeroHealthLossEvents; private int visualEvents; private int burstsSpawned; private int streaksSpawned; private int dropletsSpawned; private int splatsSpawned; private int recycledBursts; private int recycledStreaks; private int recycledDroplets; private int recycledSplats; private int suppressedPlayerImpactEvents; private int cooldownSkippedEvents; private int distanceSkippedEvents; private int surfaceLandingEvents; private int fallbackLandingEvents; private int fallbackSplatsDiscarded; private int characterSurfaceSkips; private int rigidbodySurfaceSkips; private int invalidSurfaceSkips; private int suppressedVanillaBloodEffects; private int observedVanillaEffectRoots; private int unmatchedVanillaEffectRoots; private int mutedVanillaRenderers; private int groundedLethalFinishes; private int destroyedPoolEntriesRecovered; private int bodyMarksSpawned; private int bodyMarksOnSkin; private int bodyMarksFlatFallback; private int bodyMarksSkippedNonPhysical; private int bodyMarksDeferredToDismemberment; private int worldExitCleanups; private int trailDripsSpawned; private int bleedingActorsStarted; private int bleedingActorsPruned; private int bandagesApplied; private int playerBleedDamageTicks; private int bandageAttemptsFailed; private int playerHitSoundsPlayed; private int playerHitSoundsSkipped; private float vanillaEffectWindowUntil; private Vector3 vanillaEffectWindowCenter; private bool externalAssetsLoaded; private string assetLoadSummary = "Not loaded yet"; private string lastEvent = "none"; private CrimsonPackFx packFx; private bool hadNetworkSession; private static readonly HashSet<string> LoggedOnceKeys = new HashSet<string>(); private static Mesh sharedQuadMesh; private readonly List<Transform> modOwnedSubtrees = new List<Transform>(); private readonly List<Transform> bodyMarkParentScratch = new List<Transform>(); private readonly Dictionary<int, bool> modOwnedNameCache = new Dictionary<int, bool>(); private const int ModOwnedNameCacheLimit = 8192; private const float SkinSearchRadius = 0.6f; private const int MaxSkinMarkTriangles = 600; private Mesh skinBakeMesh; private SkinnedMeshRenderer skinRenderer; private readonly List<SkinnedMeshRenderer> skinRendererScratch = new List<SkinnedMeshRenderer>(); private readonly List<Vector3> skinBakeVertices = new List<Vector3>(); private readonly List<Vector3> skinBakeNormals = new List<Vector3>(); private readonly List<int> skinSubmeshTriangles = new List<int>(); private readonly List<Vector3> skinVertices = new List<Vector3>(); private readonly List<Vector3> skinNormals = new List<Vector3>(); private readonly List<int> skinTriangles = new List<int>(); private readonly List<Transform> skinBones = new List<Transform>(); private readonly HashSet<Transform> skinBoneSet = new HashSet<Transform>(); private readonly HashSet<Mesh> unbakeableSkinMeshes = new HashSet<Mesh>(); private readonly Dictionary<int, int> patchVertexMap = new Dictionary<int, int>(); private readonly List<Vector3> patchVertices = new List<Vector3>(); private readonly List<Vector3> patchNormals = new List<Vector3>(); private readonly List<Vector2> patchUvs = new List<Vector2>(); private readonly List<Color32> patchColors = new List<Color32>(); private readonly List<int> patchTriangles = new List<int>(); internal static double WorldSecondsPerDay { get { EnvMan instance = EnvMan.instance; return ((Object)(object)instance != (Object)null && instance.m_dayLengthSec > 0) ? ((float)instance.m_dayLengthSec) : 1800f; } } internal float DropletGravityMultiplier { get { if (dropletGravity != null) { return Mathf.Clamp(dropletGravity.Value, 0.1f, 6f); } return 1f; } } internal float SurfaceOffset { get { if (surfaceOffset != null) { return Mathf.Clamp(surfaceOffset.Value, 0.001f, 0.05f); } return 0.006f; } } internal float SplatSettleSeconds { get { if (splatSettleSeconds != null) { return Mathf.Clamp(splatSettleSeconds.Value, 0.05f, 0.5f); } return 0.14f; } } internal float SurfaceSplatLifetimeInGameDays { get { if (surfaceSplatLifetimeInGameDays != null) { return Mathf.Clamp(surfaceSplatLifetimeInGameDays.Value, 0.05f, 7f); } return 2f; } } internal float DynamicEffectRenderDistance { get { if (dynamicEffectRenderDistance != null) { return Mathf.Clamp(dynamicEffectRenderDistance.Value, 6f, 60f); } return 24f; } } internal float SurfaceSplatRenderDistance { get { if (surfaceSplatRenderDistance != null) { return Mathf.Clamp(surfaceSplatRenderDistance.Value, 4f, 50f); } return 18f; } } internal bool DisableVanillaBloodEffects { get { if (disableVanillaBloodEffects != null) { return disableVanillaBloodEffects.Value; } return false; } } internal bool UseGroundedLethalFinish { get { if (useGroundedLethalFinish != null) { return useGroundedLethalFinish.Value; } return true; } } internal bool CreateFallbackSplatsWhenAirborne { get { if (createFallbackSplatsWhenAirborne != null) { return createFallbackSplatsWhenAirborne.Value; } return false; } } internal bool AllowWallMarks { get { if (allowWallMarks != null) { return allowWallMarks.Value; } return false; } } internal Camera RenderCamera { get { if ((Object)(object)cachedMainCamera != (Object)null && ((Behaviour)cachedMainCamera).isActiveAndEnabled) { return cachedMainCamera; } if (Time.unscaledTime >= nextCameraSearchTime) { nextCameraSearchTime = Time.unscaledTime + 0.5f; cachedMainCamera = Camera.main; } return cachedMainCamera; } } internal static float FadeWindowSeconds(double lifetimeSeconds) { return Mathf.Max(30f, (float)(lifetimeSeconds * 0.025)); } internal static void LogOnce(string key, string message) { if (LoggedOnceKeys.Add(key)) { CrimsonBloodPlugin instance = Instance; if ((Object)(object)instance != (Object)null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("Crimson Blood: " + message)); } } } internal static bool IsBlackBlood(Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return color.r < 0.2f; } internal bool TryGetWorldTimeSeconds(out double worldTimeSeconds) { worldTimeSeconds = 0.0; try { if ((Object)(object)ZNet.instance == (Object)null) { return false; } double timeSeconds = ZNet.instance.GetTimeSeconds(); if (double.IsNaN(timeSeconds) || double.IsInfinity(timeSeconds) || timeSeconds < 0.0) { return false; } worldTimeSeconds = timeSeconds; return true; } catch { return false; } } internal bool IsCharacterSurface(Collider collider) { if ((Object)(object)collider != (Object)null) { return (Object)(object)((Component)collider).GetComponentInParent<Character>() != (Object)null; } return false; } internal bool IsRejectedBloodSurface(Collider collider) { if ((Object)(object)collider == (Object)null) { return true; } if (IsCharacterSurface(collider)) { characterSurfaceSkips++; return true; } if ((Object)(object)collider.attachedRigidbody != (Object)null) { rigidbodySurfaceSkips++; return true; } Transform val = ((Component)collider).transform; int num = 0; while ((Object)(object)val != (Object)null && num < 8) { string text = ((Object)val).name ?? string.Empty; if (text.IndexOf("ragdoll", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("corpse", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("character", StringComparison.OrdinalIgnoreCase) >= 0) { invalidSurfaceSkips++; return true; } num++; val = val.parent; } return false; } internal bool IsValidBloodSurfaceNormal(Vector3 normal) { //IL_0019: 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) if (!AllowWallMarks) { return normal.y >= 0.55f; } return normal.y >= -0.35f; } internal void RecordCharacterSurfaceSkip() { characterSurfaceSkips++; } internal void RecordAirborneFallbackDiscarded() { fallbackSplatsDiscarded++; } internal void BeginVanillaEffectWindow(Character target) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (DisableVanillaBloodEffects && !((Object)(object)target == (Object)null)) { vanillaEffectWindowCenter = target.GetCenterPoint(); float num = ((vanillaEffectWindowSeconds == null) ? 1.25f : Mathf.Clamp(vanillaEffectWindowSeconds.Value, 0.25f, 3f)); if (Time.time > vanillaEffectWindowUntil) { windowEffectNames.Clear(); } vanillaEffectWindowUntil = Mathf.Max(vanillaEffectWindowUntil, Time.time + num); string[] array = VanillaBloodEffectNames(target); for (int i = 0; i < array.Length; i++) { windowEffectNames.Add(array[i]); } } } private string[] VanillaBloodEffectNames(Character target) { string prefabName = Utils.GetPrefabName(((Component)target).gameObject); if (vanillaEffectNamesByCreature.TryGetValue(prefabName, out var value)) { return value; } List<string> list = new List<string>(); AddVisualEffectNames(target.m_hitEffects, list); if (EffectListHasRagdoll(target.m_deathEffects)) { AddVisualEffectNames(target.m_deathEffects, list); } value = list.ToArray(); vanillaEffectNamesByCreature[prefabName] = value; return value; } private static void AddVisualEffectNames(EffectList effects, List<string> into) { if (effects == null || effects.m_effectPrefabs == null) { return; } for (int i = 0; i < effects.m_effectPrefabs.Length; i++) { EffectData val = effects.m_effectPrefabs[i]; GameObject val2 = val?.m_prefab; if (!((Object)(object)val2 == (Object)null) && val.m_enabled && !((Object)(object)val2.GetComponent<Ragdoll>() != (Object)null) && !((Object)(object)val2.GetComponent<Character>() != (Object)null) && !((Object)(object)val2.GetComponentInChildren<Renderer>(true) == (Object)null) && !into.Contains(((Object)val2).name)) { into.Add(((Object)val2).name); } } } private static bool EffectListHasRagdoll(EffectList effects) { if (effects == null || effects.m_effectPrefabs == null) { return false; } for (int i = 0; i < effects.m_effectPrefabs.Length; i++) { EffectData val = effects.m_effectPrefabs[i]; if (val != null && val.m_enabled && (Object)(object)val.m_prefab != (Object)null && (Object)(object)val.m_prefab.GetComponent<Ragdoll>() != (Object)null) { return true; } } return false; } private static string StripClone(string objectName) { if (objectName == null || !objectName.EndsWith("(Clone)", StringComparison.Ordinal)) { return objectName; } return objectName.Substring(0, objectName.Length - "(Clone)".Length); } internal void OnVanillaEffectsCreated(GameObject[] createdEffects) { //IL_003a: 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) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (!DisableVanillaBloodEffects || createdEffects == null || createdEffects.Length == 0 || Time.time > vanillaEffectWindowUntil) { return; } foreach (GameObject val in createdEffects) { if ((Object)(object)val == (Object)null) { continue; } Vector3 val2 = val.transform.position - vanillaEffectWindowCenter; if (((Vector3)(ref val2)).sqrMagnitude > 625f || IsModOwnedVisualName(((Object)val).name) || (Object)(object)val.GetComponent<Ragdoll>() != (Object)null || (Object)(object)val.GetComponent<Character>() != (Object)null) { continue; } string text = BuildVanillaEffectSignature(val); observedVanillaEffectRoots++; if (windowEffectNames.Contains(StripClone(((Object)val).name)) || EffectSignatureMatchesVanillaBlood(text)) { MuteVanillaBloodVisuals(val); suppressedVanillaBloodEffects++; RememberVanillaEffectRoot("MUTED " + text); continue; } unmatchedVanillaEffectRoots++; if (recordVanillaEffectRoots != null && recordVanillaEffectRoots.Value) { RememberVanillaEffectRoot("OBSERVED " + text); } } } internal static bool IsModOwnedVisualName(string objectName) { if (!string.IsNullOrEmpty(objectName)) { if (!objectName.StartsWith("CrimsonBlood_", StringComparison.Ordinal) && !objectName.StartsWith("Dismemberment_", StringComparison.Ordinal)) { return objectName.StartsWith("MBF_", StringComparison.Ordinal); } return true; } return false; } private void MuteVanillaBloodVisuals(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { try { val.enabled = false; mutedVanillaRenderers++; } catch { } } } } private bool EffectSignatureMatchesVanillaBlood(string signature) { if (string.IsNullOrEmpty(signature)) { return false; } string[] array = ((vanillaBloodEffectTokens != null) ? vanillaBloodEffectTokens.Value : "blood,bleed,gore,splatter").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); string text = signature.ToLowerInvariant(); for (int i = 0; i < array.Length; i++) { string value = array[i].Trim().ToLowerInvariant(); if (!string.IsNullOrEmpty(value) && text.Contains(value)) { return true; } } return false; } private static string BuildVanillaEffectSignature(GameObject root) { if ((Object)(object)root == (Object)null) { return "<destroyed>"; } string text = ((Object)root).name ?? "unnamed"; Transform transform = root.transform; for (int i = 0; i < transform.childCount && i < 24; i++) { Transform child = transform.GetChild(i); if ((Object)(object)child == (Object)null) { continue; } text = text + " / " + ((Object)child).name; for (int j = 0; j < child.childCount && j < 6; j++) { Transform child2 = child.GetChild(j); if ((Object)(object)child2 != (Object)null) { text = text + " / " + ((Object)child2).name; } } } return text; } private void RememberVanillaEffectRoot(string line) { while (recentVanillaEffectRoots.Count >= 24) { recentVanillaEffectRoots.Dequeue(); } recentVanillaEffectRoots.Enqueue(line); } internal bool ShouldRenderEffectAt(Vector3 worldPosition, bool isSurfaceMark) { //IL_003b: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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) Camera renderCamera = RenderCamera; Vector3 val = (((Object)(object)renderCamera != (Object)null) ? ((Component)renderCamera).transform.position : (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : Vector3.zero)); float num = (isSurfaceMark ? SurfaceSplatRenderDistance : DynamicEffectRenderDistance); Vector3 val2 = worldPosition - val; return ((Vector3)(ref val2)).sqrMagnitude <= num * num; } private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown Instance = this; pluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); BindConfig(); harmony = new Harmony("marc.valheim.crimsonblood"); harmony.PatchAll(typeof(CrimsonBloodPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood 0.10.1.0 loaded. F11 writes diagnostics; F12 clears recent events. Blood pack: " + (PackConfig.Master ? "on (bundle marc_bloodfx_v1 loads when the first world starts)" : "off (UseBloodPack = false)") + ".")); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Asset-driven mode expects an assets folder beside CrimsonBlood.dll. If it is missing, safe procedural fallback textures are used."); } private void OnDestroy() { if (harmony != null) { harmony.UnpatchSelf(); harmony = null; } DestroyVisualSystem(); nextAllowedImpactTime.Clear(); bleedingActors.Clear(); bleedingActorsToRemove.Clear(); bodyMarksByTarget.Clear(); recentEvents.Clear(); recentVanillaEffectRoots.Clear(); if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } private void Update() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) bool flag = IsGameInputBlocked(); if (!flag && Input.GetKeyDown(diagnosticKey.Value)) { WriteDiagnostics(); } if (!flag && Input.GetKeyDown(clearDiagnosticsKey.Value)) { recentEvents.Clear(); recentVanillaEffectRoots.Clear(); lastEvent = "none"; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Crimson Blood: cleared recent event diagnostics."); } CheckWorldExit(); if ((Object)(object)Player.m_localPlayer != (Object)null) { EnsureVisualSystem(); } HandleBandageInput(flag); UpdateBleedingTrails(); UpdatePlayerBleedDamage(); if (packFx != null) { packFx.Update(); } if (Time.time >= nextCooldownTrimTime) { nextCooldownTrimTime = Time.time + 20f; TrimExpiredCooldowns(); } } private static bool IsGameInputBlocked() { try { if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return true; } if (Console.IsVisible()) { return true; } if (TextInput.IsVisible()) { return true; } if (Menu.IsVisible()) { return true; } if (InventoryGui.IsVisible()) { return true; } } catch { } return false; } private void CheckWorldExit() { bool flag = (Object)(object)ZNet.instance != (Object)null; if (hadNetworkSession && !flag) { DeactivateAllVisuals(); } hadNetworkSession = flag; } private void DeactivateAllVisuals() { worldExitCleanups++; for (int i = 0; i < burstPool.Count; i++) { if ((Object)(object)burstPool[i] != (Object)null && ((Component)burstPool[i]).gameObject.activeSelf) { burstPool[i].Deactivate(); } } for (int j = 0; j < streakPool.Count; j++) { if ((Object)(object)streakPool[j] != (Object)null && ((Component)streakPool[j]).gameObject.activeSelf) { streakPool[j].Deactivate(); } } for (int k = 0; k < dropletPool.Count; k++) { if ((Object)(object)dropletPool[k] != (Object)null && ((Component)dropletPool[k]).gameObject.activeSelf) { dropletPool[k].Deactivate(); } } for (int l = 0; l < splatPool.Count; l++) { if ((Object)(object)splatPool[l] != (Object)null && ((Component)splatPool[l]).gameObject.activeSelf) { splatPool[l].Deactivate(); } } for (int m = 0; m < bodyMarkPool.Count; m++) { if ((Object)(object)bodyMarkPool[m] != (Object)null && ((Component)bodyMarkPool[m]).gameObject.activeSelf) { bodyMarkPool[m].Deactivate(); } } if (packFx != null) { packFx.DeactivateAll(); } bleedingActors.Clear(); bleedingActorsToRemove.Clear(); bodyMarksByTarget.Clear(); nextAllowedImpactTime.Clear(); modOwnedNameCache.Clear(); inBleedTick = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Crimson Blood: left the world; all blood visuals cleared."); } private void BindConfig() { //IL_089a: Unknown result type (might be due to invalid IL or missing references) //IL_08a4: Expected O, but got Unknown enabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Master", "Enabled", true, "Turns Crimson Blood's local visual layer on or off. It never changes combat balance."); diagnosticKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("0 - Master", "DiagnosticKey", (KeyCode)292, "Writes Crimson Blood diagnostic information to BepInEx/LogOutput.log."); clearDiagnosticsKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("0 - Master", "ClearDiagnosticsKey", (KeyCode)293, "Clears Crimson Blood's recent diagnostic event list."); visualDistance = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Safety", "VisualDistanceMetres", 80f, "Maximum distance from the local player at which combat blood visuals are created."); dynamicEffectRenderDistance = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Safety", "DynamicEffectRenderDistanceMetres", 24f, "Maximum distance from the camera at which airborne bursts, streaks, and droplets remain visible."); surfaceSplatRenderDistance = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Safety", "SurfaceSplatRenderDistanceMetres", 18f, "Maximum distance from the camera at which surface blood marks remain visible."); minimumHealthLossForVisual = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Safety", "MinimumActualHealthLoss", 0.1f, "Actual health lost after armour, blocking and resistances required before a visual may spawn."); perTargetCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Safety", "PerTargetImpactCooldownSeconds", 0.06f, "Stops rapid repeated damage ticks from producing excessive visual bursts."); useExternalAssetTextures = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Asset Loading", "UseExternalAssetTextures", true, "Loads supplied transparent PNG effects from the assets folder beside CrimsonBlood.dll."); assetRootFolder = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Asset Loading", "AssetRootFolder", "assets", "Folder beside CrimsonBlood.dll that contains sprays, trails, and ground_splats."); useHighDefinitionGroundSplats = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Asset Loading", "UseHighDefinitionGroundSplats", false, "Uses assets/ground_splats/kenney_512 if you copied it beside the DLL. This uses more video memory than the default 256px set."); maximumBurstTextures = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Asset Loading", "MaximumBurstTextures", 6, "Maximum number of splash-frame textures loaded from assets/sprays/blood_splash_frames."); maximumTrailTextures = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Asset Loading", "MaximumTrailTextures", 8, "Maximum number of trail/droplet textures loaded from assets/trails."); maximumGroundSplatTextures = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Asset Loading", "MaximumGroundSplatTextures", 36, "Maximum number of ground-splat textures loaded. 36 default 256px textures are safe for this first asset build."); burstPoolSize = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Safety Pools", "ImpactBurstPoolSize", 20, "Pre-warmed maximum number of animated impact burst sprites."); streakPoolSize = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Safety Pools", "PressureStreakPoolSize", 22, "Pre-warmed maximum number of pressure spray streaks."); dropletPoolSize = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Safety Pools", "DropletPoolSize", 150, "Pre-warmed maximum number of moving droplets."); splatPoolSize = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Safety Pools", "SurfaceSplatPoolSize", 160, "Pre-warmed number of temporary blood splats. The pool can grow safely while two-day marks are still active."); maximumPersistentSurfaceSplats = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Safety Pools", "MaximumPersistentSurfaceSplats", 480, "Maximum number of surface blood marks that may coexist before the oldest mark is reused. Higher values preserve more two-day blood trails but use more performance."); maximumDropletsPerHit = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Look", "MaximumDropletsPerHit", 26, "Upper safety cap for liquid droplets created by one strong hit."); maximumStreaksPerHeavyHit = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Look", "MaximumPressureStreaksPerHeavyHit", 6, "Upper safety cap for streaks on stronger hits."); maximumBurstsPerHeavyHit = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Look", "MaximumAnimatedBurstsPerHeavyHit", 3, "Upper safety cap for animated splash bursts on stronger hits."); dropletGravity = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "DropletGravityMultiplier", 1.85f, "Gravity multiplier for airborne droplets. Higher values make them fall and hit surfaces sooner."); dropletLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "DropletLifetimeSeconds", 1.2f, "Maximum airborne lifetime before a droplet fades or tries a final nearby splat."); streakLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "PressureStreakLifetimeSeconds", 0.18f, "Lifetime of directional pressure spray streaks."); burstLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "ImpactBurstLifetimeSeconds", 0.16f, "Lifetime of animated impact burst sprites."); surfaceSplatLifetimeInGameDays = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "SurfaceSplatLifetimeInGameDays", 2f, "How many full Valheim in-game days ground and structure blood remains before it fades. Default: 2 days."); minimumSplatHealthLoss = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "MinimumHealthLossForImmediateImpactSplat", 0.85f, "Health loss required before an immediate blood mark may appear below/near the impact."); createImmediateImpactSplats = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Look", "CreateImmediateImpactSplats", true, "Places one small wet mark near a meaningful hit where a suitable surface exists."); allowWallMarks = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Look", "AllowWallAndSteepSurfaceBloodMarks", true, "Allows blood marks on static walls, wooden structures, steep rocks, floors, and terrain."); groundOnlySurfaceMarks = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Look", "GroundOnlySurfaceMarks", false, "Legacy compatibility setting. v0.7.5 ignores this value so wall and steep-surface marks work when AllowWallAndSteepSurfaceBloodMarks is true."); immediateWallProbeDistance = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "ImmediateWallProbeDistanceMetres", 1.35f, "How far a fresh hit checks behind and around the wound for a nearby static wall or steep rock to receive blood."); maxImmediateSplatSize = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "MaxImmediateSplatSize", 0.45f, "Hard cap on the size of an immediate impact/ground/wall blood mark. Lower this if kill blood looks like a giant slab. Range 0.10-0.80."); createFallbackSplatsWhenAirborne = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Look", "CreateFallbackSplatsWhenAirborne", false, "When false, droplets that never reach a valid ground surface simply fade instead of creating a late fallback blood mark in the air."); surfaceOffset = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "SurfaceOffset", 0.006f, "Small offset that keeps a blood mark just above its surface and avoids flickering."); splatSettleSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "SurfaceSplatSettleSeconds", 0.14f, "Real-time seconds a new blood mark takes to spread to its final size. This is independent of splat lifetime."); bluntBloodMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "BluntHeavyHitBloodMultiplier", 1.85f, "Extra amount of blood created by strong blunt hits such as maces and clubs. Affects heavy hits only."); bluntMaximumDropletsPerHit = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Look", "MaximumDropletsPerHeavyBluntHit", 30, "Safety cap used only for strong blunt hits. Lets mace and club impacts be fuller without raising every weapon type."); bluntBurstSizeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "BluntHeavyHitBurstSizeMultiplier", 1.6f, "Size multiplier for animated impact bursts created by strong blunt hits."); bluntSplatSizeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "BluntHeavyHitSplatSizeMultiplier", 1.45f, "Size multiplier for blood marks created by strong blunt hits."); bluntLifetimeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Look", "BluntHeavyHitLifetimeMultiplier", 1.38f, "Makes blunt-hit bursts, droplets, and streaks stay visible slightly longer."); allowPlayerImpactVisuals = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Player Compatibility", "AllowPlayerImpactVisuals", true, "Allows Crimson Blood to create impact visuals when the local player takes real damage."); suppressPlayerImpactsWhenYoureInjuredLoaded = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Player Compatibility", "PreventDuplicatePlayerHitBloodWhenYoureInjuredLoaded", true, "Compatibility setting retained for existing configs. When You're Injured is installed, Crimson Blood now automatically leaves local-player blood to that mod so only one player blood visual system can run."); disableVanillaBloodEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Player Compatibility", "HideVanillaBlood", true, "On by default: Valheim's own blood effects near a hit are hidden, so only Crimson Blood's blood shows. The effect objects are left to the game; only their renderers are switched off, and the check runs only for a moment after each hit. Turn off to see vanilla blood as well. (Replaces DisableVanillaBloodEffects from 0.8.x.)"); vanillaBloodEffectTokens = ((BaseUnityPlugin)this).Config.Bind<string>("5 - Player Compatibility", "VanillaBloodEffectTokens", "blood,bleed,gore,splatter", "Name fragments used to identify actual vanilla effect GameObjects created during a hit. Unmatched roots appear in F11 diagnostics."); recordVanillaEffectRoots = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Player Compatibility", "RecordVanillaEffectRootsAroundHits", true, "Records EffectList-created root names near a real hit. Use F11 results to identify any remaining vanilla blood effect exactly."); vanillaEffectWindowSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Player Compatibility", "VanillaEffectWindowSeconds", 1.25f, "Seconds after a damage event that newly created EffectList roots are inspected for vanilla blood suppression."); useGroundedLethalFinish = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Player Compatibility", "UseGroundedLethalFinish", true, "On a lethal hit, replaces the hanging animated impact burst with a grounded death spill and falling droplets."); enableWoundBodyMarks = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "EnableWoundBodyMarks", true, "Attach short-lived blood marks to the creature/player at the exact hit point."); bodyMarkLifetimeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "BodyMarkLifetimeSeconds", 180f, "Real-time seconds body marks remain attached before fading. They also disappear if the target despawns."); maxBodyMarksPerTarget = ((BaseUnityPlugin)this).Config.Bind<int>("6 - Hit Blood, Trails & Bandage", "MaxBodyMarksPerTarget", 6, "Maximum attached wound marks per creature/player before the oldest mark is recycled."); enableBleedingTrails = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "EnableBleedingTrails", true, "Wounded creatures bleed until death/despawn. The local player bleeds until bandaged."); trailMinimumHealthLoss = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "TrailMinimumHealthLoss", 2f, "Actual health loss required before a target starts leaving a bleeding trail."); trailDripDistance = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "TrailDripDistance", 1.2f, "Meters a bleeding actor must move before another trail drip is emitted."); trailDripInterval = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "TrailDripInterval", 0.6f, "Maximum seconds between trail-drip checks while a bleeding actor is visible."); trailDripSizeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "TrailDripSizeMultiplier", 0.55f, "Size multiplier for trail drips relative to impact splats."); maxBleedingActors = ((BaseUnityPlugin)this).Config.Bind<int>("6 - Hit Blood, Trails & Bandage", "MaxBleedingActors", 32, "Maximum simultaneously tracked bleeding actors. Existing bleed states continue when the cap is reached."); enablePlayerBleedDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "EnablePlayerBleedDamage", true, "When true, the local player loses health over time while bleeding (until bandaged). Gives bandages a real purpose. Cosmetic-only for creatures; this affects ONLY the local player."); playerBleedDamagePerTick = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "PlayerBleedDamagePerTick", 0.5f, "Health points removed from the local player each bleed tick. Default 0.5."); playerBleedTickSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "PlayerBleedTickSeconds", 2f, "Seconds between player bleed-damage ticks. Default 2.0 (so 0.5 HP every 2s = 0.25 HP/sec)."); playerBleedCanKill = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "PlayerBleedCanKill", true, "When true, bleeding can reduce the player to 0 and kill them if never bandaged. When false, bleed damage stops at 1 HP (never lethal on its own)."); playerBleedMinimumHealthLoss = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "PlayerBleedMinimumHealthLoss", 15f, new ConfigDescription("The local player only STARTS bleeding when a single hit takes more than this much health. Smaller hits (a stumble off a bump, a scratch) never start a bleed. Creatures keep using TrailMinimumHealthLoss.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>())); bandageKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("6 - Hit Blood, Trails & Bandage", "BandageKey", (KeyCode)103, "Key the local player presses to bandage and stop their cosmetic bleeding trail."); requireBandageMaterial = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "RequireBandageMaterial", true, "When true, bandaging consumes the configured inventory item."); bandageItemSharedName = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Hit Blood, Trails & Bandage", "BandageItemSharedName", "$item_leatherscraps", "Shared item name consumed when bandaging. Default is Leather Scraps."); bandageItemCost = ((BaseUnityPlugin)this).Config.Bind<int>("6 - Hit Blood, Trails & Bandage", "BandageItemCost", 1, "Number of configured items consumed when bandaging."); enableBandageAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "EnableBandageAudio", true, "Play a local UI-style bandage sound when bleeding stops."); bandageAudioVolume = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "BandageAudioVolume", 0.9f, "Volume for the local bandage sound."); bandageAudioFile = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Hit Blood, Trails & Bandage", "BandageAudioFile", "bandage.mp3", "Audio file under assets/audio beside the plugin DLL."); enablePlayerHitSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("6 - Hit Blood, Trails & Bandage", "EnablePlayerHitSounds", true, "Play local weapon-specific impact sounds only when the local player is hit by a sword, axe, or arrow."); playerHitSoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Hit Blood, Trails & Bandage", "PlayerHitSoundVolume", 0.9f, "Volume for local player-only weapon hit sounds."); swordHitSoundFile = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Hit Blood, Trails & Bandage", "SwordHitSoundFile", "sword_hit.mp3", "Sword impact audio file under assets/audio beside the plugin DLL."); axeHitSoundFile = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Hit Blood, Trails & Bandage", "AxeHitSoundFile", "axe_hit.mp3", "Axe impact audio file under assets/audio beside the plugin DLL."); arrowHitSoundFile = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Hit Blood, Trails & Bandage", "ArrowHitSoundFile", "arrow_hit.mp3", "Arrow impact audio file under assets/audio beside the plugin DLL."); logVisualEvents = ((BaseUnityPlugin)this).Config.Bind<bool>("7 - Debug", "LogVisualEvents", false, "Writes every spawned visual event to LogOutput.log and lists them in the F11 recent events. Leave false outside testing (when false the event text is not even built)."); PackConfig.Bind(((BaseUnityPlugin)this).Config); } internal void RecordHookCall() { applyDamageHookCalls++; } internal bool ShouldObserve(Character target) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (!enabledConfig.Value || (Object)(object)target == (Object)null) { return false; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)target == (Object)(object)localPlayer) { return true; } if ((Object)(object)localPlayer == (Object)null) { return false; } float num = Mathf.Clamp(visualDistance.Value, 5f, 150f); Vector3 val = ((Component)target).transform.position - ((Component)localPlayer).transform.position; return ((Vector3)(ref val)).sqrMagnitude <= num * num; } internal void RecordDamage(Character target, HitData hit, float healthBefore) { //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) if (!enabledConfig.Value || (Object)(object)target == (Object)null) { return; } if (inBleedTick) { bleedTickHitsIgnored++; return; } observedDamageCalls++; float health = target.GetHealth(); float num = Mathf.Max(0f, healthBefore - health); if (num < 0.01f) { zeroHealthLossEvents++; return; } realHealthLossEvents++; if ((Object)(object)target == (Object)(object)Player.m_localPlayer) { TryPlayPlayerHitSound(hit); } if (num < Mathf.Max(0.01f, minimumHealthLossForVisual.Value)) { if (logVisualEvents.Value) { RememberEvent("SKIP threshold target=" + GetTargetName(target) + " loss=" + num.ToString("0.##")); } return; } if (!IsWithinVisualRange(target)) { distanceSkippedEvents++; return; } if ((Object)(object)target == (Object)(object)Player.m_localPlayer && !CanSpawnLocalPlayerImpact()) { suppressedPlayerImpactEvents++; if (logVisualEvents.Value) { RememberEvent("SKIP player-compatibility loss=" + num.ToString("0.##")); } return; } EnsureVisualSystem(); if ((Object)(object)visualRoot == (Object)null) { if (logVisualEvents.Value) { RememberEvent("SKIP visual-root-unavailable target=" + GetTargetName(target)); } return; } DamageCategory category = ResolveDamageCategory(hit); Vector3 impactPoint = ResolveImpactPoint(target, hit); Color bloodColor = ResolveBloodColor(target, category); float severity = Mathf.Clamp01((num - 0.35f) / 14f); StartOrRefreshBleeding(target, impactPoint, num, severity, bloodColor); int instanceID = ((Object)target).GetInstanceID(); if (nextAllowedImpactTime.TryGetValue(instanceID, out var value) && Time.time < value) { cooldownSkippedEvents++; return; } nextAllowedImpactTime[instanceID] = Time.time + Mathf.Clamp(perTargetCooldown.Value, 0.03f, 0.75f); Vector3 sprayDirection = ResolveOutwardSprayDirection(target, hit, impactPoint); bool lethalHit = health <= 0.01f; if ((Object)(object)target == (Object)(object)Player.m_localPlayer && packFx != null && CanSpawnLocalPlayerImpact()) { packFx.FlashScreen(num, target.GetMaxHealth()); } SpawnImpact(target, hit, impactPoint, sprayDirection, num, severity, category, bloodColor, lethalHit); } private bool IsWithinVisualRange(Character target) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return false; } float num = Mathf.Clamp(visualDistance.Value, 5f, 150f); Vector3 val = ((Component)target).transform.position - ((Component)localPlayer).transform.position; return ((Vector3)(ref val)).sqrMagnitude <= num * num; } private bool CanSpawnLocalPlayerImpact() { if (allowPlayerImpactVisuals == null || !allowPlayerImpactVisuals.Value) { return false; } return !IsYoureInjuredLoaded(); } private static bool IsYoureInjuredLoaded() { try { return Chainloader.PluginInfos != null && Chainloader.PluginInfos.ContainsKey("com.marccunningham.youreinjured"); } catch { return false; } } private void EnsureVisualSystem() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)visualRoot != (Object)null)) { visualRoot = new GameObject("CrimsonBlood_LocalVisuals").transform; visualRoot.SetParent(((Component)this).transform, false); ((Object)((Component)visualRoot).gameObject).hideFlags = (HideFlags)61; PrepareTexturesAndMaterials(); PrewarmPools(); EnsureBandageAudioSource(); BeginLoadBandageAudioIfNeeded(); BeginLoadPlayerHitAudioIfNeeded(); packFx = new CrimsonPackFx(this, ((BaseUnityPlugin)this).Logger); packFx.Initialize(visualRoot); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood: " + assetLoadSummary)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood: blood pack: " + packFx.Summary + " | procedural quad shader=" + (((Object)(object)quadMaterial != (Object)null && (Object)(object)quadMaterial.shader != (Object)null) ? ((Object)quadMaterial.shader).name : "none"))); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood: visual pools ready: bursts=" + burstPool.Count + ", streaks=" + streakPool.Count + ", droplets=" + dropletPool.Count + ", splats=" + splatPool.Count + ", bodyMarks=" + bodyMarkPool.Count + ".")); } } private void PrepareTexturesAndMaterials() { ClearLoadedAssetLists(); externalAssetsLoaded = false; activeAssetDirectory = string.Empty; bool flag = false; if (useExternalAssetTextures.Value) { string path = (string.IsNullOrWhiteSpace(assetRootFolder.Value) ? "assets" : assetRootFolder.Value.Trim()); activeAssetDirectory = Path.Combine(pluginDirectory ?? string.Empty, path); flag = TryLoadExternalTextureSet(activeAssetDirectory); } int count = burstTextures.Count; int count2 = trailTextures.Count; int count3 = splatTextures.Count; externalAssetsLoaded = count > 0 || count2 > 0 || count3 > 0; CreateFallbackTexturesIfNeeded(); if (burstTextures.Count == 0) { burstTextures.Add(fallbackBurstTexture); } if (dropletTextures.Count == 0) { dropletTextures.Add(fallbackDropletTexture); } if (splatTextures.Count == 0) { splatTextures.Add(fallbackSplatTexture); } quadMaterial = CreateTransparentMaterial("CrimsonBlood_AssetQuadMaterial", fallbackSplatTexture); ownedMaterials.Add(quadMaterial); if (trailTextures.Count == 0) { trailTextures.Add(fallbackTrailTexture); } string text = (flag ? "EXTERNAL" : (externalAssetsLoaded ? "PARTIAL" : "FALLBACK")); assetLoadSummary = "assetMode=" + text + " | root=" + (string.IsNullOrEmpty(activeAssetDirectory) ? "not-requested" : activeAssetDirectory) + " | externalBurst=" + count + " | externalTrail=" + count2 + " | externalSplat=" + count3 + " | activeBurst=" + burstTextures.Count + " | activeTrail=" + trailTextures.Count + " | activeSplat=" + splatTextures.Count; } private bool TryLoadExternalTextureSet(string assetRoot) { if (string.IsNullOrEmpty(assetRoot) || !Directory.Exists(assetRoot)) { assetLoadSummary = "assets folder missing: " + assetRoot; return false; } string folder = Path.Combine(assetRoot, "sprays", "blood_splash_frames"); string folder2 = Path.Combine(assetRoot, "trails"); string folder3 = Path.Combine(assetRoot, "ground_splats", "kenney_256"); if (useHighDefinitionGroundSplats.Value) { string text = Path.Combine(assetRoot, "ground_splats", "kenney_512"); if (Directory.Exists(text)) { folder3 = text; } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood: UseHighDefinitionGroundSplats is on but " + text + " does not exist; using the kenney_256 splats instead.")); } } int num = LoadPngFolder(folder, Mathf.Clamp(maximumBurstTextures.Value, 1, 16), burstTextures, "burst"); int num2 = LoadPngFolder(folder2, Mathf.Clamp(maximumTrailTextures.Value, 1, 16), trailTextures, "trail"); int num3 = LoadPngFolder(folder3, Mathf.Clamp(maximumGroundSplatTextures.Value, 1, 48), splatTextures, "splat"); for (int i = 0; i < trailTextures.Count; i++) { if ((Object)(object)trailTextures[i] != (Object)null) { dropletTextures.Add(trailTextures[i]); } } int num4; if (num > 0 && num2 > 0) { num4 = ((num3 > 0) ? 1 : 0); if (num4 != 0) { goto IL_0179; } } else { num4 = 0; } ((BaseUnityPlugin)this).Logger.LogWarning((object)"Crimson Blood: asset folders were found but one or more required texture groups were empty. Falling back only for missing groups."); goto IL_0179; IL_0179: return (byte)num4 != 0; } private int LoadPngFolder(string folder, int maximumTextures, List<Texture2D> destination, string groupName) { if (!Directory.Exists(folder)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Crimson Blood: missing " + groupName + " asset folder: " + folder)); return 0; } string[] files; try { files = Directory.GetFiles(folder, "*.png", SearchOption.TopDirectoryOnly); Array.Sort(files, (IComparer<string>?)StringComparer.OrdinalIgnoreCase); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Crimson Blood: could not enumerate " + groupName + " textures. " + ex.Message)); return 0; } int num = 0; for (int i = 0; i < files.Length; i++) { if (num >= maximumTextures) { break; } if (!CrimsonAssetLoader.TryLoadAlphaMaskPng(files[i], out var texture, out var error)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Crimson Blood: skipped " + groupName + " texture '" + Path.GetFileName(files[i]) + "'. " + error)); } else { ((Object)texture).name = "CrimsonBlood_" + groupName + "_" + Path.GetFileNameWithoutExtension(files[i]); destination.Add(texture); ownedTextures.Add(texture); num++; } } return num; } private void CreateFallbackTexturesIfNeeded() { if ((Object)(object)fallbackDropletTexture == (Object)null) { fallbackDropletTexture = CrimsonAssetLoader.CreateSoftCircleTexture("CrimsonBlood_FallbackDroplet", 64, 0.88f); ownedTextures.Add(fallbackDropletTexture); } if ((Object)(object)fallbackBurstTexture == (Object)null) { fallbackBurstTexture = CrimsonAssetLoader.CreateBurstTexture("CrimsonBlood_FallbackBurst", 128); ownedTextures.Add(fallbackBurstTexture); } if ((Object)(object)fallbackSplatTexture == (Object)null) { fallbackSplatTexture = CrimsonAssetLoader.CreateIrregularSplatTexture("CrimsonBlood_FallbackSplat", 128); ownedTextures.Add(fallbackSplatTexture); } if ((Object)(object)fallbackTrailTexture == (Object)null) { fallbackTrailTexture = CrimsonAssetLoader.CreateTrailTexture("CrimsonBlood_FallbackTrail", 32, 128); ownedTextures.Add(fallbackTrailTexture); } } private Material CreateTransparentMaterial(string materialName, Texture2D texture) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Standard"); if ((Object)(object)val == (Object)null) { val = Shader.Find("Legacy Shaders/Transparent/Specular"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Particles/Alpha Blended"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Unlit/Transparent"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Sprites/Default"); } Material val2 = new Material(val); ((Object)val2).name = materialName; ((Object)val2).hideFlags = (HideFlags)61; val2.color = Color.white; val2.renderQueue = 3000; if ((Object)(object)texture != (Object)null) { if (val2.HasProperty("_MainTex")) { val2.SetTexture("_MainTex", (Texture)(object)texture); } if (val2.HasProperty("_BaseMap")) { val2.SetTexture("_BaseMap", (Texture)(object)texture); } } if (val2.HasProperty("_Mode")) { val2.SetFloat("_Mode", 3f); } if (val2.HasProperty("_Surface")) { val2.SetFloat("_Surface", 1f); } if (val2.HasProperty("_Blend")) { val2.SetFloat("_Blend", 0f); } if (val2.HasProperty("_SrcBlend")) { val2.SetInt("_SrcBlend", 5); } if (val2.HasProperty("_DstBlend")) { val2.SetInt("_DstBlend", 10); } if (val2.HasProperty("_ZWrite")) { val2.SetInt("_ZWrite", 0); } if (val2.HasProperty("_Cull")) { val2.SetInt("_Cull", 0); } if (val2.HasProperty("_Glossiness")) { val2.SetFloat("_Glossiness", 0.82f); } if (val2.HasProperty("_Smoothness")) { val2.SetFloat("_Smoothness", 0.82f); } if (val2.HasProperty("_Metallic")) { val2.SetFloat("_Metallic", 0f); } if (val2.HasProperty("_SpecColor")) { val2.SetColor("_SpecColor", new Color(0.22f, 0.08f, 0.08f, 1f)); } if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Color.white); } if (val2.HasProperty("_BaseColor")) { val2.SetColor("_BaseColor", Color.white); } val2.SetOverrideTag("RenderType", "Transparent"); val2.DisableKeyword("_ALPHATEST_ON"); val2.EnableKeyword("_ALPHABLEND_ON"); val2.DisableKeyword("_ALPHAPREMULTIPLY_ON"); return val2; } private void PrewarmPools() { int num = Mathf.Clamp(burstPoolSize.Value, 4, 48); int num2 = Mathf.Clamp(streakPoolSize.Value, 4, 48); int num3 = Mathf.Clamp(dropletPoolSize.Value, 4, 240); int num4 = Mathf.Clamp(splatPoolSize.Value, 4, 240); int num5 = Mathf.Clamp(maxBodyMarksPerTarget.Value * 8, 4, 96); for (int i = 0; i < num; i++) { CreateBurstPoolObject(i); } for (int j = 0; j < num2; j++) { CreateStreakPoolObject(j); } for (int k = 0; k < num3; k++) { CreateDropletPoolObject(k); } for (int l = 0; l < num4; l++) { CreateSplatPoolObject(l); } for (int m = 0; m < num5; m++) { CreateBodyMarkPoolObject(m); } } private void CreateBurstPoolObject(int index) { GameObject obj = CreateQuadObject(); ((Object)obj).name = "CrimsonBlood_ImpactBurst_" + index; obj.transform.SetParent(visualRoot, false); ((Object)obj).hideFlags = (HideFlags)61; Renderer component = obj.GetComponent<Renderer>(); ConfigureRenderer(component, quadMaterial); CrimsonBloodBurst crimsonBloodBurst = obj.AddComponent<CrimsonBloodBurst>(); crimsonBloodBurst.Initialize(this, component); obj.SetActive(false); burstPool.Add(crimsonBloodBurst); } private void CreateDropletPoolObject(int index) { GameObject obj = CreateQuadObject(); ((Object)obj).name = "CrimsonBlood_Droplet_" + index; obj.transform.SetParent(visualRoot, false); ((Object)obj).hideFlags = (HideFlags)61; Renderer component = obj.GetComponent<Renderer>(); ConfigureRenderer(component, quadMaterial); CrimsonBloodDroplet crimsonBloodDroplet = obj.AddComponent<CrimsonBloodDroplet>(); crimsonBloodDroplet.Initialize(this, component); obj.SetActive(false); dropletPool.Add(crimsonBloodDroplet); } private void CreateStreakPoolObject(int index) { GameObject obj = CreateQuadObject(); ((Object)obj).name = "CrimsonBlood_Streak_" + index; obj.transform.SetParent(visualRoot, false); ((Object)obj).hideFlags = (HideFlags)61; Renderer component = obj.GetComponent<Renderer>(); ConfigureRenderer(component, quadMaterial); CrimsonBloodStreak crimsonBloodStreak = obj.AddComponent<CrimsonBloodStreak>(); crimsonBloodStreak.Initialize(this, component); obj.SetActive(false); streakPool.Add(crimsonBloodStreak); } private void CreateSplatPoolObject(int index) { GameObject obj = CreateQuadObject(); ((Object)obj).name = "CrimsonBlood_Splat_" + index; obj.transform.SetParent(visualRoot, false); ((Object)obj).hideFlags = (HideFlags)61; MeshRenderer component = obj.GetComponent<MeshRenderer>(); ConfigureRenderer((Renderer)(object)component, quadMaterial); CrimsonBloodSplat crimsonBloodSplat = obj.AddComponent<CrimsonBloodSplat>(); crimsonBloodSplat.Initialize(this, component); obj.SetActive(false); splatPool.Add(crimsonBloodSplat); } private void CreateBodyMarkPoolObject(int index) { GameObject obj = CreateQuadObject(); ((Object)obj).name = "CrimsonBlood_BodyMark_" + index; obj.transform.SetParent(visualRoot, false); ((Object)obj).hideFlags = (HideFlags)61; MeshRenderer component = obj.GetComponent<MeshRenderer>(); ConfigureRenderer((Renderer)(object)component, quadMaterial); CrimsonBloodBodyMark crimsonBloodBodyMark = obj.AddComponent<CrimsonBloodBodyMark>(); crimsonBloodBodyMark.Initialize(this, component); obj.SetActive(false); bodyMarkPool.Add(crimsonBloodBodyMark); } private void EnsureBandageAudioSource() { if (!((Object)(object)bandageAudioSource != (Object)null)) { bandageAudioSource = ((Component)this).gameObject.GetComponent<AudioSource>(); if ((Object)(object)bandageAudioSource == (Object)null) { bandageAudioSource = ((Component)this).gameObject.AddComponent<AudioSource>(); } bandageAudioSource.playOnAwake = false; bandageAudioSource.loop = false; bandageAudioSource.spatialBlend = 0f; } } private static GameObject CreateQuadObject() { //IL_0005: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown GameObject val = new GameObject("CrimsonBlood_Quad"); val.AddComponent<MeshFilter>().sharedMesh = SharedQuadMesh(); val.AddComponent<MeshRenderer>(); return val; } private static Mesh SharedQuadMesh() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)sharedQuadMesh != (Object)null) { return sharedQuadMesh; } sharedQuadMesh = new Mesh(); ((Object)sharedQuadMesh).name = "CrimsonBlood_Quad"; ((Object)sharedQuadMesh).hideFlags = (HideFlags)61; sharedQuadMesh.vertices = (Vector3[])(object)new Vector3[4] { new Vector3(-0.5f, -0.5f, 0f), new Vector3(0.5f, -0.5f, 0f), new Vector3(-0.5f, 0.5f, 0f), new Vector3(0.5f, 0.5f, 0f) }; sharedQuadMesh.uv = (Vector2[])(object)new Vector2[4] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) }; sharedQuadMesh.normals = (Vector3[])(object)new Vector3[4] { Vector3.back, Vector3.back, Vector3.back, Vector3.back }; Vector4 val = default(Vector4); ((Vector4)(ref val))..ctor(1f, 0f, 0f, -1f); sharedQuadMesh.tangents = (Vector4[])(object)new Vector4[4] { val, val, val, val }; sharedQuadMesh.triangles = new int[6] { 0, 3, 1, 3, 0, 2 }; sharedQuadMesh.RecalculateBounds(); return sharedQuadMesh; } private static void ConfigureRenderer(Renderer renderer, Material material) { if (!((Object)(object)renderer == (Object)null)) { renderer.sharedMaterial = material; renderer.shadowCastingMode = (ShadowCastingMode)0; renderer.receiveShadows = false; } } private void SpawnImpact(Character target, HitData hit, Vector3 impactPoint, Vector3 sprayDirection, float healthLoss, float severity, DamageCategory category, Color bloodColor, bool lethalHit) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_000d: 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_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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bc: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_040d: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_044b: Unknown result type (might be due to invalid IL or missing references) //IL_044c: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Unknown result type (might be due to invalid IL or missing references) //IL_0462: Unknown result type (might be due to invalid IL or missing references) //IL_0463: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_0533: Unknown result type (might be due to invalid IL or missing references) Vector3 val = impactPoint + sprayDirection * 0.035f + Vector3.up * 0.035f; bool flag = healthLoss >= 2.5f || severity >= 0.15f; bool flag2 = healthLoss >= 5.5f || severity >= 0.38f; bool flag3 = healthLoss >= 10f || severity >= 0.68f; if (category == DamageCategory.Fall) { SpawnBodyMarks(target, hit, category, impactPoint, sprayDirection, severity, bloodColor, lethalHit); TryCreateImmediateImpactSplat(((Component)target).transform, val, Mathf.Lerp(0.2f, 0.7f, severity), bloodColor, Vector3.zero); visualEvents++; if (logVisualEvents.Value) { string text = "SPAWN target=" + GetTargetName(target) + " loss=" + healthLoss.ToString("0.##") + " category=Fall splat-only"; RememberEvent(text); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood " + text)); } return; } int num = Mathf.Clamp(maximumDropletsPerHit.Value, 2, 30); if (category == DamageCategory.Blunt && flag2) { num = Mathf.Clamp(bluntMaximumDropletsPerHit.Value, 4, 30); } int num2 = Mathf.Clamp(3 + Mathf.RoundToInt(Mathf.Lerp(2f, (float)num - 3f, severity)), 2, num); int num3 = (flag ? Mathf.Clamp(1 + Mathf.RoundToInt(Mathf.Lerp(0f, (float)maximumStreaksPerHeavyHit.Value - 1f, severity)), 1, Mathf.Max(1, maximumStreaksPerHeavyHit.Value)) : 0); int num4 = (flag ? 1 : 0); if (flag2) { num4 = Mathf.Clamp(maximumBurstsPerHeavyHit.Value, 1, 3); } switch (category) { case DamageCategory.Slash: case DamageCategory.Chop: num2 += 2; break; case DamageCategory.Pierce: num2++; num3 = Mathf.Max(num3, 1); break; case DamageCategory.Blunt: if (flag2) { float num5 = Mathf.Clamp(bluntBloodMultiplier.Value, 1f, 3f); num2 = Mathf.RoundToInt((float)num2 * num5) + 2; num3 = Mathf.Max(num3, 4); num4 = Mathf.Max(num4, 3); } else { num2++; } break; case DamageCategory.Fire: num2 = Mathf.Max(1, num2 - 6); num3 = 0; num4 = 0; break; case DamageCategory.Poison: num2 = Mathf.Max(1, num2 - 7); num3 = 0; num4 = 0; break; case DamageCategory.BiteOrMonsterHit: num2 += 2; break; } num2 = Mathf.Clamp(num2, 1, num); if (category != DamageCategory.Fire && category != DamageCategory.Poison && !(category == DamageCategory.Blunt && flag2)) { num2 = Mathf.Min(num + 2, num2 + 2); } num3 = Mathf.Clamp(num3, 0, Mathf.Clamp(maximumStreaksPerHeavyHit.Value, 0, 8)); num4 = Mathf.Clamp(num4, 0, Mathf.Clamp(maximumBurstsPerHeavyHit.Value + 1, 0, 4)); if (createImmediateImpactSplats.Value && healthLoss >= Mathf.Max(0f, minimumSplatHealthLoss.Value)) { float num6 = Mathf.Lerp(0.15f, flag3 ? 0.58f : 0.42f, severity); if (category == DamageCategory.Blunt && flag2) { num6 *= Mathf.Clamp(bluntSplatSizeMultiplier.Value, 1f, 2.5f); } TryCreateImmediateImpactSplat(((Component)target).transform, val + sprayDirection * 0.15f, num6, bloodColor, sprayDirection); } bool flag4 = lethalHit && UseGroundedLethalFinish; SpawnBodyMarks(target, hit, category, impactPoint, sprayDirection, severity, bloodColor, lethalHit); if (flag4) { groundedLethalFinishes++; num4 = 0; num3 = 0; num2 = Mathf.Min(num2, 12); TryCreateImmediateImpactSplat(((Component)target).transform, impactPoint, Mathf.Clamp(0.34f + severity * 0.48f, 0.34f, 0.78f), bloodColor, sprayDirection); if (IsPhysicalCategory(category)) { TrySpawnKillPool(target, bloodColor); } } if (!flag4) { SpawnAnimatedBursts(((Component)target).transform, val, sprayDirection, num4, severity, category, bloodColor, flag2); } SpawnPressureStreaks(((Component)target).transform, val, sprayDirection, num3, severity, category, bloodColor); SpawnBallisticDroplets(((Component)target).transform, val, sprayDirection, num2, severity, category, bloodColor, flag2, flag4); visualEvents++; if (logVisualEvents.Value) { string text2 = "SPAWN target=" + GetTargetName(target) + " loss=" + healthLoss.ToString("0.##") + " category=" + category.ToString() + " lethal=" + lethalHit + " burst=" + num4 + " streaks=" + num3 + " droplets=" + num2 + " direction=" + FormatVector(sprayDirection); RememberEvent(text2); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crimson Blood " + text2)); } } private void TrySpawnKillPool(Character target, Color bloodColor) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if (packFx == null || (Object)(object)target == (Object)null || !packFx.KillPoolsActive) { return; } Vector3 origin = target.GetCenterPoint() + Vector3.up * 0.6f; if (TryFindSurface(((Component)target).transform, origin, Vector3.down, 4.5f, out var bestHit) && !(((RaycastHit)(ref bestHit)).normal.y < 0.55f)) { float creatureRadius = 0.5f; try { creatureRadius = target.GetRadius(); } catch { } packFx.SpawnKillPool(((RaycastHit)(ref bestHit)).point, ((RaycastHit)(ref bestHit)).normal, creatureRadius, bloodColor); } } private static bool IsPhysicalCategory(DamageCategory category) { if (category != DamageCategory.Slash && category != DamageCategory.Chop && category != DamageCategory.Pierce && category != DamageCategory.Blunt && category != DamageCategory.BiteOrMonsterHit) { return category == DamageCategory.Fall; } return true; } private void SpawnBodyMarks(Character target, HitData hit, DamageCategory category, Vector3 impactPoint, Vector3 sprayDirection, float severity, Color color, bool lethalHit) { //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)target == (Object)null || lethalHit || enableWoundBodyMarks == null || !enableWoundBodyMarks.Value) { return; } if (!IsPhysicalCategory(category)) { bodyMarksSkippedNonPhysical++; return; } if (PackConfig.DeferToDismemberment && (Object)(object)target != (Object)(object)Player.m_localPlayer && DismembermentBridge.IsLoaded() && DismembermentBridge.OwnsWoundsFor(target, hit, category, ((BaseUnityPlugin)this).Logger)) { bodyMarksDeferredToDismemberment++; return; } int num = Mathf.Clamp((maxBodyMarksPerTarget == null) ? 6 : maxBodyMarksPerTarget.Value, 1, 24); if (!bodyMarksByTarget.TryGetValue(target, out var value)) { value = new List<CrimsonBloodBodyMark>(); bodyMarksByTarget[target] = value; } CleanupBodyMarkList(value); while (value.Count >= num) { CrimsonBloodBodyMark crimsonBloodBodyMark = value[0]; for (int i = 1; i < value.Count; i++) { if ((Object)(object)value[i] != (Object)null && value[i].ActivatedAt < crimsonBloodBodyMark.ActivatedAt) { crimsonBloodBodyMark = value[i]; } } if ((Object)(object)crimsonBloodBodyMark != (Object)null) { crimsonBloodBodyMark.Deactivate(); } CleanupBodyMarkList(value); if (value.Count >= num && value.Count > 0) { value.RemoveAt(0); } } bool flag = PrepareSkinSurface(target, impactPoint); int num2 = ((!(severity >= 0.55f)) ? 1 : 2); for (int j = 0; j < num2; j++) { CrimsonBloodBodyMark bodyMark = GetBodyMark(); if ((Object)(object)bodyMark == (Object)null) { break; } float size = Mathf.Lerp(0.105f, 0.235f, Mathf.Clamp01(severity)) * Random.Range(0.82f, 1.24f); float lifetime = Mathf.Clamp((bodyMarkLifetimeSeconds == null) ? 180f : bodyMarkLifetimeSeconds.Value, 10f, 900f); float rotationDegrees = Random.Range(0f, 360f); Texture2D randomSplatTexture = GetRandomSplatTexture(); Color val = color; val.a = Mathf.Clamp(val.a * 0.92f, 0.45f, 0.95f); Material val2 = ((packFx != null) ? packFx.PickBodyMarkDecal() : null); if ((Object)(object)val2 != (Object)null) { val = packFx.DecalTint(val2, val); } if (flag && BuildSkinMarkMesh(bodyMark.SkinMesh, impactPoint, size, rotationDegrees, out var bone)) { bodyMark.ActivateOnSkin(bone, lifetime, val, randomSplatTexture, val2); bodyMarksOnSkin++; } else { Transform parent = FindBestBodyMarkParent(target, impactPoint); Vector3 val3 = impactPoint - target.GetCenterPoint(); if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = ((((Vector3)(ref sprayDirection)).sqrMagnitude > 0.0001f) ? sprayDirection : ((Component)target).transform.forward); } ((Vector3)(ref val3)).Normalize(); Vector3 val4 = Vector3.Cross(Vector3.up, val3); if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f) { val4 = ((Component)target).transform.right; } ((Vector3)(ref val4)).Normalize(); Vector3 val5 = Vector3.Cross(val3, val4); Vector3 normalized = ((Vector3)(ref val5)).normalized; Vector3 val6 = val4 * Random.Range(-0.045f, 0.045f) + normalized * Random.Range(-0.045f, 0.045f); bodyMark.Activate(parent, impactPoint + val6, val3, size, lifetime, val, randomSplatTexture, rotationDegrees, val2); bodyMarksFlatFallback++; } value.Add(bodyMark); bodyMarksSpawned++; } } private static void CleanupBodyMarkList(List<CrimsonBloodBodyMark> marks) { for (int num = marks.Count - 1; num >= 0; num--) { CrimsonBloodBodyMark crimsonBloodBodyMark = marks[num]; if ((Object)(object)crimsonBloodBodyMark == (Object)null || !((Component)crimsonBloodBodyMark).gameObject.activeSelf) { marks.RemoveAt(num); } } } private Transform FindBestBodyMarkParent(Character target, Vector3 impactPoint) { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)target == (Object)null) { return visualRoot; } Transform result = ((Component)target).transform; float num = float.MaxValue; GameObject visual = target.GetVisual(); Transform obj = (((Object)(object)visual != (Object)null) ? visual.transform : ((Component)target).transform); List<Transform> list = bodyMarkParentScratch; list.Clear(); ((Component)obj).GetComponentsInChildren<Transform>(true, list); modOwnedSubtrees.Clear(); for (int i = 0; i < list.Count; i++) { Transform val = list[i]; if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<CrimsonBloodBodyMark>() != (Object)null) { continue; } if (IsModOwnedTransform(val)) { modOwnedSubtrees.Add(val); } else if (!IsInsideModOwnedSubtree(val)) { Vector3 val2 = val.position - impactPoint; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = val; } } } modOwnedSubtrees.Clear(); list.Clear(); return result; } private bool IsModOwnedTransform(Transform candidate) { int instanceID = ((Object)candidate).GetInstanceID(); if (modOwnedNameCache.TryGetValue(instanceID, out var value)) { return value; } if (modOwnedNameCache.Count >= 8192) { modOwnedNameCache.Clear(); } value = IsModOwnedVisualName(((Object)candidate).name); modOwnedNameCache[instanceID] = value; return value; } private bool IsInsideModOwnedSubtree(Transform candidate) { for (int i = 0; i < modOwnedSubtrees.Count; i++) { if ((Object)(object)modOwnedSubtrees[i] != (Object)null && candidate.IsChildOf(modOwnedSubtrees[i])) { return true; } } return false; } private bool PrepareSkinSurface(Character target, Vector3 impactPoint) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) skinRenderer = null; skinVertices.Clear(); skinNormals.Clear(); skinTriangles.Clear(); skinBones.Clear(); skinBoneSet.Clear(); if ((Object)(object)target == (Object)null) { return false; } GameObject visual = target.GetVisual(); ((Component)(((Object)(object)visual != (Object)null) ? visual.transform : ((Component)target).transform)).GetComponentsInChildren<SkinnedMeshRenderer>(false, skinRendererScratch); if ((Object)(object)skinBakeMesh == (Object)null) { skinBakeMesh = new Mesh(); ((Object)skinBakeMesh).name = "CrimsonBlood_SkinBake"; ((Object)skinBakeMesh).hideFlags = (HideFlags)61; } float num = 0.36f; for (int i = 0; i < 2; i++) { if (!((Object)(object)skinRenderer == (Object)null)) { break; } for (int j = 0; j < skinRendererScratch.Count; j++) { SkinnedMeshRenderer val = skinRendererScratch[j]; if ((Object)(object)val == (Object)null || !((Renderer)val).enabled || (Object)(object)val.sharedMesh == (Object)null || i == 0 != ((Renderer)val).isVisible || unbakeableSkinMeshes.Contains(val.sharedMesh)) { continue; } Bounds bounds = ((Renderer)val).bounds; if (((Bounds)(ref bounds)).SqrDistance(impactPoint) > num || !BakeSkin(val)) { continue; } Transform transform = ((Component)val).transform; Matrix4x4 toWorld = transform.localToWorldMatrix; float num2 = NearestVertexSqrDistance(skinBakeVertices, toWorld, impactPoint); Vector3 val2 = transform.lossyScale - Vector3.one; if (((Vector3)(ref val2)).sqrMagnitude > 0.0004f) { Matrix4x4 val3 = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); float num3 = NearestVertexSqrDistance(skinBakeVertices, val3, impactPoint); if (num3 < num2) { num2 = num3; toWorld = val3; } } if (!(num2 >= num)) { num = num2; skinRenderer = val; CopyBakedSkin(toWorld); } } } skinRendererScratch.Clear(); if ((Object)(object)skinRenderer == (Object)null || skinTriangles.Count == 0) { skinRenderer = null; return false; } Transform[] bones = skinRenderer.bones; if (bones != null) { for (int k = 0; k < bones.Length; k++) { if ((Object)(object)bones[k] != (Object)null && skinBoneSet.Add(bones[k])) { skinBones.Add(bones[k]); } } } return true; } private bool BakeSkin(SkinnedMeshRenderer candidate) { try { candidate.BakeMesh(skinBakeMesh); if (skinBakeMesh.vertexCount == 0) { MarkUnbakeable(candidate, "baked mesh was empty"); return false; } skinBakeMesh.GetVertices(skinBakeVertices); skinBakeMesh.GetNormals(skinBakeNormals); return skinBakeVertices.Count > 0; } catch (Exception ex) { MarkUnbakeable(candidate, ex.Message); return false; } } private void MarkUnbakeable(SkinnedMeshRenderer candidate, string reason) { if (unbakeableSkinMeshes.Add(candidate.sharedMesh)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Crimson Blood: cannot read skinned mesh '" + ((Object)candidate.sharedMesh).name + "' (" + reason + "); wound marks on it use flat quads.")); } } private void CopyBakedSkin(Matrix4x4 toWorld) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) skinVertices.Clear(); skinNormals.Clear(); skinTriangles.Clear(); bool flag = skinBakeNormals.Count == skinBakeVertices.Count; for (int i = 0; i < skinBakeVertices.Count; i++) { skinVertices.Add(((Matrix4x4)(ref toWorld)).MultiplyPoint3x4(skinBakeVertices[i])); List<Vector3> list = skinNormals; Vector3 item; if (!flag) { item = Vector3.zero; } else { Vector3 val = ((Matrix4x4)(ref toWorld)).MultiplyVector(skinBakeNormals[i]); item = ((Vector3)(ref val)).normalized; } list.Add(item); } for (int j = 0; j < skinBakeMesh.subMeshCount; j++) { if ((int)skinBakeMesh.GetTopology(j) == 0) { skinBakeMesh.GetTriangles(skinSubmeshTriangles, j); skinTriangles.AddRange(skinSubmeshTriangles); } } } private static float NearestVertexSqrDistance(List<Vector3> vertices, Matrix4x4 toWorld, Vector3 point) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to inval