using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PRZ_KillScoreDetail")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PRZ_KillScoreDetail")]
[assembly: AssemblyTitle("PRZ_KillScoreDetail")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
}
}
}
public static class BonusNames
{
public static Dictionary<string, int> NameToId = new Dictionary<string, int>();
public static List<string> IdToName = new List<string>();
public static bool Initialized = false;
public static void Init()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if (Initialized)
{
return;
}
List<Bonus> list = new List<Bonus>();
list.AddRange(KillScoreCalculator.GetAllBonuses(0));
list.AddRange(KillScoreCalculator.GetAllBonuses(1));
list.AddRange(KillScoreCalculator.GetAllBonuses(2));
for (int i = 0; i < list.Count; i++)
{
string name = list[i].Name;
if (!NameToId.ContainsKey(name))
{
NameToId[name] = i;
IdToName.Add(name);
}
}
Initialized = true;
Debug.Log((object)$"[KillScoreDetail] 建表完成,共 {IdToName.Count} 项");
foreach (KeyValuePair<string, int> item in NameToId)
{
Debug.Log((object)$"[KillScoreDetail] {item.Value} = '{item.Key}'");
}
}
public static int GetId(string name)
{
if (NameToId.TryGetValue(name, out var value))
{
return value;
}
return -1;
}
public static string GetName(int id)
{
if (id >= 0 && id < IdToName.Count)
{
return IdToName[id];
}
return null;
}
}
[HarmonyPatch(typeof(Creature), "LocalHit")]
public static class CreatureLocalHitPatch
{
public static Creature LastDyingCreature;
public static void Prefix(Creature __instance)
{
LastDyingCreature = __instance;
}
}
[HarmonyPatch(typeof(PlayerKillScore), "AddKillScore")]
public static class AddKillScorePatch
{
public static void Prefix(string killed, int worth, List<Bonus> bonuses)
{
BonusNames.Init();
Creature lastDyingCreature = CreatureLocalHitPatch.LastDyingCreature;
if (!((Object)(object)lastDyingCreature == (Object)null))
{
KillScoreTag killScoreTag = ((Component)lastDyingCreature).gameObject.GetComponent<KillScoreTag>();
if ((Object)(object)killScoreTag == (Object)null)
{
killScoreTag = ((Component)lastDyingCreature).gameObject.AddComponent<KillScoreTag>();
}
killScoreTag.Killed = killed;
killScoreTag.Worth = worth;
killScoreTag.Bonuses = bonuses;
}
}
}
[HarmonyPatch(typeof(WeaponUI), "UpdateInspectedItemText")]
public static class WeaponUIInspectPatch
{
public static void Postfix(WeaponUI __instance)
{
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
FieldInfo fieldInfo = AccessTools.Field(typeof(WeaponUI), "_descriptionText");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(WeaponUI), "_inspectedItem");
if (fieldInfo == null || fieldInfo2 == null)
{
return;
}
object? value = fieldInfo.GetValue(__instance);
TextMeshProUGUI val = (TextMeshProUGUI)((value is TextMeshProUGUI) ? value : null);
object? value2 = fieldInfo2.GetValue(__instance);
Item val2 = (Item)((value2 is Item) ? value2 : null);
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
return;
}
KillScoreTag component = ((Component)val2).gameObject.GetComponent<KillScoreTag>();
if ((Object)(object)component == (Object)null || component.Bonuses == null)
{
return;
}
string text = "";
foreach (Bonus bonuse in component.Bonuses)
{
text += $"\n{bonuse.Worth}x {bonuse.Name}";
}
((TMP_Text)val).text = ((TMP_Text)val).text + text;
}
}
[HarmonyPatch(typeof(SaveManager), "ItemToSavedItem")]
public static class SaveItemPatch
{
public static void Postfix(Item item, ref SavedItem __result)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)item == (Object)null || __result == null)
{
return;
}
KillScoreTag component = ((Component)item).gameObject.GetComponent<KillScoreTag>();
if ((Object)(object)component == (Object)null || component.Bonuses == null)
{
return;
}
uint num = 0u;
foreach (Bonus bonuse in component.Bonuses)
{
int id = BonusNames.GetId(bonuse.Name);
if (id >= 0 && id < 32)
{
num |= (uint)(1 << id);
}
}
__result.Sight = (byte)(num & 0xFF);
__result.BarrelAttachment = (byte)((num >> 8) & 0xFF);
__result.AmmoType = (byte)((num >> 16) & 0xFF);
__result.ExtendedMag = ((num >> 24) & 1) != 0;
__result.LaserSight = ((num >> 25) & 1) != 0;
__result.Sharpness = (byte)((num >> 26) & 0xFF);
}
}
[HarmonyPatch(typeof(Creature), "LoadFromSave")]
public static class LoadItemPatch
{
public static void Postfix(Creature __instance, SavedItem savedItem)
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null || savedItem == null)
{
return;
}
uint num = (uint)(savedItem.Sight | (savedItem.BarrelAttachment << 8) | (savedItem.AmmoType << 16) | ((savedItem.ExtendedMag ? 1 : 0) << 24) | ((savedItem.LaserSight ? 1 : 0) << 25) | (savedItem.Sharpness << 26));
if (num == 0)
{
return;
}
BonusNames.Init();
List<Bonus> list = new List<Bonus>();
for (int i = 0; i < 32; i++)
{
if ((num & (uint)(1 << i)) != 0)
{
string name = BonusNames.GetName(i);
if (name != null)
{
list.Add(new Bonus(name, 1.25f));
}
}
}
if (list.Count != 0)
{
KillScoreTag killScoreTag = ((Component)__instance).gameObject.GetComponent<KillScoreTag>();
if ((Object)(object)killScoreTag == (Object)null)
{
killScoreTag = ((Component)__instance).gameObject.AddComponent<KillScoreTag>();
}
killScoreTag.Bonuses = list;
}
}
}
public class KillScoreTag : MonoBehaviour
{
public string Killed;
public int Worth;
public List<Bonus> Bonuses;
}
namespace PRZ_KillScoreDetail
{
[BepInPlugin("com.prz.killscoredetail", "PRZ - KillScoreDetail", "1.0.0")]
[BepInProcess("How to Fish.exe")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.prz.killscoredetail");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PRZ - KillScoreDetail loaded!");
}
}
}