using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Skins;
using Skins.Manifest;
using Skins.Target;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrimsonDragonSkins")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("CrimsonDragonSkins")]
[assembly: AssemblyTitle("CrimsonDragonSkins")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace CrimsonDragonSkins
{
[BepInPlugin("sourmonkis.crimsondragonskins", "CrimsonDragonSkins", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
[HarmonyPatch]
internal static class Patches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(ColorProperty), "Apply")]
private static void AfterColorApply(ColorProperty __instance, Material material, string propertyName)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
try
{
if (propertyName != "_EmissiveColor" || (Object)(object)material == (Object)null)
{
return;
}
float a = __instance.A;
if (a < 0.496f || a > 0.574f)
{
return;
}
int num = Mathf.RoundToInt((a - 0.5f) * 100f);
if (num < 0 || num >= Weapons.Length)
{
return;
}
Color val = GlowFor(Weapons[num].Suffix);
material.SetColor("_EmissiveColor", val);
if (_logged++ >= 12)
{
return;
}
ManualLogSource logSrc = LogSrc;
if (logSrc != null)
{
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(19, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Glow on '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)material).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' (");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Weapons[num].Suffix);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") -> ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(val.r, "0.##");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(",");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(val.g, "0.##");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(",");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(val.b, "0.##");
}
logSrc.LogDebug(val2);
}
}
catch (Exception ex)
{
ManualLogSource logSrc2 = LogSrc;
if (logSrc2 != null)
{
logSrc2.LogWarning((object)ex.Message);
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SkinManager), "Reload")]
private static void BeforeReload()
{
try
{
ConfigFile cfg = Cfg;
if (cfg != null)
{
cfg.Reload();
}
}
catch (Exception)
{
}
_modelCache.Clear();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SkinGroup), "IsMatch")]
private static void AfterIsMatch(SkinGroup __instance, TargetContext ctx, ref bool __result)
{
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Expected O, but got Unknown
try
{
if (!AutoMatch.Value || ctx == null || !ctx.OfflineGearId.HasValue || __instance == null || __instance.Guid == null || !__instance.Guid.StartsWith("crimson-dragon.") || !VanillaModel.TryGetValue(__instance.Guid.Substring("crimson-dragon.".Length), out var value))
{
return;
}
string text = ModelOf(ctx.OfflineGearId.Value);
if (text == null)
{
return;
}
bool flag = text == value;
if (flag != __result && _matchLogged++ < 40)
{
ManualLogSource logSrc = LogSrc;
if (logSrc != null)
{
bool flag2 = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 4, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(flag ? "Offering" : "Hiding");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(__instance.Guid);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' for gear ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint?>(ctx.OfflineGearId);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (parts ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
logSrc.LogInfo(val);
}
}
__result = flag;
}
catch (Exception ex)
{
ManualLogSource logSrc2 = LogSrc;
if (logSrc2 != null)
{
logSrc2.LogWarning((object)ex.Message);
}
}
}
}
public const string Guid = "sourmonkis.crimsondragonskins";
private const float MarkerAlpha = 0.5f;
internal static ConfigEntry<bool> GlowEnabled;
internal static ConfigEntry<float> GlowBrightness;
internal static readonly Dictionary<string, ConfigEntry<string>> Colors = new Dictionary<string, ConfigEntry<string>>();
internal static ConfigFile Cfg;
internal static ConfigEntry<bool> AutoMatch;
private const string GroupPrefix = "crimson-dragon.";
private static readonly HashSet<int> ModelSlots = new HashSet<int> { 12, 16, 19, 44, 46, 48, 50 };
private static readonly Dictionary<string, string> VanillaModel = new Dictionary<string, string>
{
["sniper"] = "12:21,16:9,19:11",
["hicalpistol"] = "12:49,16:21,19:18",
["sawedoff"] = "12:47,16:22,19:21",
["assaultrifle"] = "12:14,16:8,19:7",
["helgun"] = "12:27,16:10,19:1",
["smg"] = "12:26,16:6,19:5",
["precisionrifle"] = "12:19,16:1,19:1",
["sledgehammer"] = "44:2,46:4,48:9,50:2"
};
private static readonly Dictionary<uint, string> _modelCache = new Dictionary<uint, string>();
private static readonly (string Suffix, string Key, string Default)[] Weapons = new(string, string, string)[8]
{
("sniper", "Sniper (Koning PR 11)", "#1AD9FF"),
("hicalpistol", "High Cal Pistol (Shelling Arid 5)", "#FF9E1F"),
("sawedoff", "Sawed-Off (Buckland SBS III)", "#FFE6C7"),
("assaultrifle", "Assault Rifle (Drekker Pres MOD 556)", "#1FFF66"),
("helgun", "HEL Gun (Omneco EXP1)", "#9E2EFF"),
("smg", "SMG (Van Auken LTC5)", "#FF269E"),
("precisionrifle", "Precision Rifle (Drekker DEL P1)", "#FF540A"),
("sledgehammer", "Sledgehammer (Santonian HDH)", "#8CCCFF")
};
internal static ManualLogSource LogSrc;
private static int _logged;
private static int _matchLogged;
public override void Load()
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
Cfg = ((BasePlugin)this).Config;
LogSrc = ((BasePlugin)this).Log;
GlowEnabled = ((BasePlugin)this).Config.Bind<bool>("Glow", "Enabled", true, "Turn the glowing lines on or off for all Crimson Dragon skins.");
GlowBrightness = ((BasePlugin)this).Config.Bind<float>("Glow", "Brightness", 0.6f, new ConfigDescription("How bright the glowing lines are. 0 = off, 0.6 = soft (default), 1 = bright, above 1 = very bright.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
AutoMatch = ((BasePlugin)this).Config.Bind<bool>("Compatibility", "Auto-match modded weapons", true, "Offer each Crimson Dragon skin on any weapon built from the same parts as the vanilla one (e.g. variants added by modded rundowns), and hide it on weapons that only reuse the vanilla ID but look different. Turn off to use only the vanilla weapon IDs.");
(string, string, string)[] weapons = Weapons;
for (int i = 0; i < weapons.Length; i++)
{
var (key, text, text2) = weapons[i];
Colors[key] = ((BasePlugin)this).Config.Bind<string>("Glow Colours", text, text2, "Glow colour as a hex code, e.g. #FF0000 for red, #1AD9FF for cyan, #FFFFFF for white.");
}
new Harmony("sourmonkis.crimsondragonskins").PatchAll(typeof(Patches));
((BasePlugin)this).Log.LogInfo((object)"Crimson Dragon glow config loaded. Edit the config, then use Settings > Reload Skins in game to apply.");
}
internal static Color GlowFor(string suffix)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_006d: 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_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_0047: Unknown result type (might be due to invalid IL or missing references)
if (!GlowEnabled.Value)
{
return new Color(0f, 0f, 0f, 1f);
}
Color val = Color.white;
if (Colors.TryGetValue(suffix, out var value))
{
val = ParseHex(value.Value, val);
}
float num = Mathf.Max(0f, GlowBrightness.Value);
return new Color(val.r * num, val.g * num, val.b * num, 1f);
}
private static Color ParseHex(string s, Color fallback)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrWhiteSpace(s))
{
return fallback;
}
s = s.Trim().TrimStart('#');
if (s.Length != 6 || !int.TryParse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
{
return fallback;
}
return new Color((float)((result >> 16) & 0xFF) / 255f, (float)((result >> 8) & 0xFF) / 255f, (float)(result & 0xFF) / 255f, 1f);
}
internal static string ModelOf(uint gearId)
{
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Expected O, but got Unknown
if (_modelCache.TryGetValue(gearId, out var value))
{
return value;
}
string text = null;
try
{
PlayerOfflineGearDataBlock block = GameDataBlockBase<PlayerOfflineGearDataBlock>.GetBlock(gearId);
string text2 = ((block != null) ? block.GearJSON : null);
if (!string.IsNullOrEmpty(text2))
{
using JsonDocument jsonDocument = JsonDocument.Parse(text2);
JsonElement property = jsonDocument.RootElement.GetProperty("Packet").GetProperty("Comps");
List<(int, int)> list = new List<(int, int)>();
foreach (JsonProperty item in property.EnumerateObject())
{
if (item.Value.ValueKind == JsonValueKind.Object)
{
int @int = item.Value.GetProperty("c").GetInt32();
if (ModelSlots.Contains(@int))
{
list.Add((@int, item.Value.GetProperty("v").GetInt32()));
}
}
}
text = string.Join(",", from x in list
orderby x.c
select $"{x.c}:{x.v}");
}
}
catch (Exception ex)
{
ManualLogSource logSrc = LogSrc;
if (logSrc != null)
{
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(7, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("gear ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(gearId);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logSrc.LogDebug(val);
}
}
_modelCache[gearId] = text;
return text;
}
}
}