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 RE9Gameplay v1.0.0
BepInEx/plugins/RE9Gameplay/RE9Gameplay.dll
Decompiled 2 hours 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 System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using RE9Gameplay.Assets; using RE9Gameplay.Character; using RE9Gameplay.Data; using RE9Gameplay.Gameplay; using RE9Gameplay.Weapons; using ResidentEvil.API; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("RE9Gameplay")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RE9Gameplay")] [assembly: AssemblyTitle("RE9Gameplay")] [assembly: AssemblyVersion("1.0.0.0")] namespace RE9Gameplay { [BepInPlugin("link.re9gameplay", "RE9Gameplay", "1.0.0")] [BepInDependency("re4company.overhaul", "0.35.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "link.re9gameplay"; public const string DisplayName = "RE9Gameplay"; public const string Version = "1.0.0"; public const string ModuleId = "re9gameplay"; internal static ManualLogSource Log; internal static PluginConfig Cfg; private ModuleInfo module; private IDisposable events; private Harmony harmony; private void Awake() { //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Cfg = new PluginConfig(((BaseUnityPlugin)this).Config); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "data", "weapons.json"); string text2 = Path.Combine(directoryName, "data", "characters.json"); try { Log.LogInfo((object)("RE4Gameplay add-on API " + GameApi.ApiVersion)); module = GameApi.RegisterModule("re9gameplay", "RE9Gameplay", "1.0.0"); } catch (Exception ex) { Log.LogError((object)("RE4Gameplay's add-on API refused the module, so RE9Gameplay is off: " + ex.Message)); return; } try { WeaponRegistry.RegisterAll(module, WeaponTable.Load(text), directoryName, text); } catch (Exception ex2) { Log.LogError((object)("data/weapons.json: " + ex2.Message)); } try { LeonCharacters.RegisterAll(module, CharacterTable.Load(text2), directoryName, text2); } catch (Exception ex3) { Log.LogError((object)("data/characters.json: " + ex3.Message)); } events = GameApi.Subscribe(module, (Action<ApiEvent>)OnEvent); harmony = new Harmony("link.re9gameplay"); try { harmony.PatchAll(typeof(Plugin).Assembly); } catch (Exception ex4) { Log.LogError((object)("Harmony patches failed; findable guns are off: " + ex4.Message)); } try { StarterPatch.Install(harmony); } catch (Exception ex5) { Log.LogError((object)("Starter gun patch failed: " + ex5.Message)); } try { Re9CaseStyle.Install(harmony); } catch (Exception ex6) { Log.LogError((object)("RE9 case look patch failed: " + ex6.Message)); } try { Re5Compat.Install(harmony); } catch (Exception ex7) { Log.LogError((object)("RE5Gameplay compatibility patch failed: " + ex7.Message)); } try { FirstPersonBody.Install(harmony); } catch (Exception ex8) { Log.LogError((object)("First-person patch failed: " + ex8.Message)); } Log.LogInfo((object)("RE9Gameplay 1.0.0 loaded: " + WeaponRegistry.Registered.Count + " guns")); } private static void LogCompatibility() { int num = (GameApi.IsConnected ? (GameApi.IsContentCompatible ? 1 : 0) : (-1)); if (num != CompatLog.Last) { CompatLog.Last = num; switch (num) { case 1: Log.LogInfo((object)"Add-on catalog matches in this lobby: RE9 guns and Leon are active."); break; case 0: Log.LogWarning((object)"Add-on catalog does not match in this lobby (yet): RE9 guns are paused until every player has the same RE9Gameplay version and config."); break; } } } private void OnEvent(ApiEvent e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 ApiEventKind kind = e.Kind; if ((int)kind > 1) { if ((int)kind == 4) { LogCompatibility(); ShopPreviews.Tick(Time.realtimeSinceStartup); if (e.IsHost) { float realtimeSinceStartup = Time.realtimeSinceStartup; StarterGun.Tick(module, realtimeSinceStartup); Findables.Tick(realtimeSinceStartup); Re9Kit.Tick(realtimeSinceStartup); } } } else { StarterGun.Reset(); Findables.Reset(); } } } internal static class CompatLog { public static int Last = -1; } internal sealed class PluginConfig { public readonly ConfigEntry<bool> GiveStarter; public readonly ConfigEntry<bool> FindablesEnabled; public readonly ConfigEntry<int> FindablesPerLanding; public readonly ConfigEntry<float> FindableChance; public readonly ConfigEntry<bool> SkipOwnedFindables; public readonly ConfigEntry<bool> SellFindables; public readonly ConfigEntry<float> WeaponVolume; public readonly ConfigEntry<bool> LogRig; public readonly ConfigEntry<bool> FirstPersonBody; public readonly ConfigEntry<bool> Re4Animations; public readonly ConfigEntry<bool> Re4Skeleton; public readonly ConfigEntry<bool> Re4Hands; public readonly ConfigEntry<string> Re4HandTint; public readonly ConfigEntry<bool> Re9Kit; public readonly ConfigEntry<bool> Re9CaseLook; public readonly ConfigEntry<bool> LiveGripTuning; public PluginConfig(ConfigFile c) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown GiveStarter = c.Bind<bool>("Starter", "GiveAlligatorSnapper", true, "Host: give every new inventory an Alligator Snapper alongside the RE4 Handgun. It is also free at the Merchant."); FindablesEnabled = c.Bind<bool>("Findables", "Enabled", true, "Host: place RE9 guns inside the facility on each landing."); FindablesPerLanding = c.Bind<int>("Findables", "RollsPerLanding", 2, new ConfigDescription("Host: how many chances per landing to place a gun.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())); FindableChance = c.Bind<float>("Findables", "ChancePerRoll", 0.7f, new ConfigDescription("Host: chance (0-1) that each roll places a gun. Which gun is weighted by weapons.json \"findWeight\".", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SkipOwnedFindables = c.Bind<bool>("Findables", "SkipGunsEveryoneOwns", true, "Host: do not place a gun that every RE player already carries."); SellFindables = c.Bind<bool>("Merchant", "SellAllRE9Guns", true, "Sell every RE9 gun at the Merchant (weapons.json \"price\"); off = only the Hound Wolf guns and the Alligator Snapper. Changes the add-on catalog: every player must use the same value."); WeaponVolume = c.Bind<float>("Audio", "WeaponVolume", 1f, new ConfigDescription("Volume of RE9 gun sounds that come from this add-on's WAV files.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); Re9Kit = c.Bind<bool>("Suits", "RE9Sidearm", true, "Host: while wearing an RE9 suit, carry only the Alligator Snapper as sidearm (the Handgun and M92F are put aside and come back on any other suit)."); Re9CaseLook = c.Bind<bool>("Suits", "RE9InventoryLook", true, "While wearing an RE9 suit, show the case in Resident Evil Requiem's style (dark grid) instead of RE4's attache case."); Re4Skeleton = c.Bind<bool>("Suits", "RE4Skeleton", true, "With RE4Animations on: put the RE9 suit's skin on the RE4 skeleton itself (like RE5Gameplay's Chris and Sheva), so RE4's animations fit exactly and guns sit where RE4 puts them, while the suit keeps its RE9 proportions. Off: the RE9 skeleton copies the RE4 pose instead."); Re4Hands = c.Bind<bool>("Suits", "RE4Hands", true, "With RE4Skeleton on: the RE9 suits use RE4 Leon's own hands (the ones RE4Gameplay shapes around each gun), with the RE9 hands tucked away underneath, so every gun and the knife is held exactly like RE4 Leon holds it."); Re4HandTint = c.Bind<string>("Suits", "RE4HandTint", "0.13,0.13,0.14", "Colour multiplied onto RE4's hands on the RE9 suits, as R,G,B from 0 to 1 (the default darkens them to the RE9 gloves). Leave empty to keep RE4's own colours."); Re4Animations = c.Bind<bool>("Suits", "RE4Animations", true, "Animate RE9 suits with RE4Gameplay's own RE4 animations (a hidden RE4 skeleton drives the RE9 model). Off: copy Lethal Company's player animations instead."); FirstPersonBody = c.Bind<bool>("Suits", "FirstPersonBody", true, "In first person while wearing an RE9 suit, show the suit's own body (head hidden) instead of RE4Gameplay's separate first-person arms, which can't be made from an add-on model."); LogRig = c.Bind<bool>("Debug", "LogRig", false, "Log how each RE9 suit is fitted to the RE4 skeleton (bones, joints, RE4's hand meshes, a check a moment after it is worn). Turn on when a suit looks wrong."); LiveGripTuning = c.Bind<bool>("Debug", "LiveGripTuning", false, "Re-read the grip/holster numbers from the data files every time a gun or Leon model is created, so you can tune them in game (re-equip / re-select the suit)."); } } } namespace RE9Gameplay.Weapons { internal sealed class WeaponAudio { private sealed class MissingSoundException : Exception { public unsafe MissingSoundException(string key, WeaponSound sound) : base(key + " has no " + ((object)(*(WeaponSound*)(&sound))/*cast due to .constrained prefix*/).ToString() + " WAV; using the template sound") { } } private readonly string firePath; private readonly string reloadPath; private readonly string key; private AudioClip fire; private AudioClip reload; private bool loadedFire; private bool loadedReload; private static AudioMixerGroup mixer; private static bool mixerSearched; private WeaponAudio(string key, string firePath, string reloadPath) { this.key = key; this.firePath = firePath; this.reloadPath = reloadPath; } public static Action<WeaponAudioContext> For(WeaponEntry entry, string pluginDir) { string path = Path.Combine(pluginDir, entry.FireSound); if (!File.Exists(path)) { return null; } string text = Path.Combine(pluginDir, entry.ReloadSound); return new WeaponAudio(entry.Key, path, File.Exists(text) ? text : null).Play; } private void Play(WeaponAudioContext ctx) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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) //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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown AudioClip val = (((int)ctx.Sound == 0) ? Fire() : Reload()); if ((Object)(object)val == (Object)null) { throw new MissingSoundException(key, ctx.Sound); } GameObject val2 = new GameObject("RE9_" + key + "_" + ((object)ctx.Sound/*cast due to .constrained prefix*/).ToString()); Transform transform = val2.transform; Position position = ctx.Position; float x = ((Position)(ref position)).X; position = ctx.Position; float y = ((Position)(ref position)).Y; position = ctx.Position; transform.position = new Vector3(x, y, ((Position)(ref position)).Z); AudioSource obj = val2.AddComponent<AudioSource>(); obj.clip = val; obj.volume = Mathf.Clamp01(ctx.Volume) * Plugin.Cfg.WeaponVolume.Value; obj.spatialBlend = (ctx.IsLocal ? 0.6f : 1f); obj.rolloffMode = (AudioRolloffMode)1; obj.minDistance = 3f; obj.maxDistance = (((int)ctx.Sound == 0) ? 90f : 25f); obj.dopplerLevel = 0f; obj.outputAudioMixerGroup = Mixer(); obj.Play(); Object.Destroy((Object)val2, val.length + 0.25f); } private AudioClip Fire() { if (!loadedFire) { loadedFire = true; fire = TryLoad(firePath); } return fire; } private AudioClip Reload() { if (!loadedReload) { loadedReload = true; reload = ((reloadPath != null) ? TryLoad(reloadPath) : null); } return reload; } private static AudioClip TryLoad(string path) { try { return WavLoader.Load(path); } catch (Exception ex) { Plugin.Log.LogError((object)("Could not load " + path + ": " + ex.Message)); return null; } } private static AudioMixerGroup Mixer() { if ((Object)(object)mixer != (Object)null || mixerSearched) { return mixer; } mixerSearched = true; try { PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val == (Object)null) { mixerSearched = false; return null; } string[] array = new string[2] { "itemAudio", "movementAudio" }; foreach (string name in array) { object? obj = typeof(PlayerControllerB).GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(val); AudioSource val2 = (AudioSource)((obj is AudioSource) ? obj : null); if (val2 != null && (Object)(object)val2.outputAudioMixerGroup != (Object)null) { mixer = val2.outputAudioMixerGroup; break; } } } catch (Exception) { mixer = null; } return mixer; } } internal sealed class WeaponModel { private readonly WeaponEntry entry; private readonly GlbModel glb; private readonly string dataFile; public readonly string MuzzlePath; private WeaponModel(WeaponEntry entry, GlbModel glb, string dataFile) { this.entry = entry; this.glb = glb; this.dataFile = dataFile; string text = glb.FindNodePath((string n) => n.Equals("muzzle", StringComparison.OrdinalIgnoreCase)); MuzzlePath = ((text != null) ? ("grip/" + glb.TopName + "/" + text) : "grip/muzzle"); } public static WeaponModel TryOpen(WeaponEntry entry, string pluginDir, string dataFile) { string path = Path.Combine(pluginDir, entry.Model); if (!File.Exists(path)) { Plugin.Log.LogInfo((object)(entry.Key + ": no model at " + entry.Model + " yet; using the " + ((object)Unsafe.As<WeaponTemplate, WeaponTemplate>(ref entry.Template)/*cast due to .constrained prefix*/).ToString() + " model")); return null; } try { return new WeaponModel(entry, GlbModel.Open(path), dataFile); } catch (Exception ex) { Plugin.Log.LogError((object)(entry.Key + ": could not read " + entry.Model + ": " + ex.Message)); return null; } } public object Create() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0037: 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) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Cfg.LiveGripTuning.Value) { RefreshGripFromDisk(); } GameObject val = new GameObject("RE9_" + entry.Key); Transform transform = new GameObject("grip").transform; transform.SetParent(val.transform, false); Quaternion val2 = Quaternion.Euler(entry.GripEuler); float num = ((entry.GripScale <= 0f) ? 1f : entry.GripScale); transform.localRotation = val2; transform.localScale = Vector3.one * num; transform.localPosition = -(val2 * (entry.GripOffset * num)); glb.Instantiate(transform); val.AddComponent<PickupScale>(); if ((Object)(object)transform.Find("muzzle") == (Object)null && MuzzlePath == "grip/muzzle") { Transform transform2 = new GameObject("muzzle").transform; transform2.SetParent(transform, false); transform2.localPosition = (Vector3)(((??)entry.MuzzleOffset) ?? GuessMuzzle(transform)); } return val; } private static Vector3 GuessMuzzle(Transform grip) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0032: 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) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_0074: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = ((Component)grip).GetComponentsInChildren<Renderer>(); if (componentsInChildren.Length == 0) { return new Vector3(0f, 0.03f, 0.2f); } Bounds bounds = componentsInChildren[0].bounds; for (int i = 1; i < componentsInChildren.Length; i++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds); } Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).max.z); return grip.InverseTransformPoint(val + grip.TransformDirection(Vector3.forward) * 0.005f); } private void RefreshGripFromDisk() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) try { foreach (WeaponEntry item in WeaponTable.Load(dataFile)) { if (!(item.Key != entry.Key)) { entry.GripOffset = item.GripOffset; entry.GripEuler = item.GripEuler; entry.GripScale = item.GripScale; entry.MuzzleOffset = item.MuzzleOffset; break; } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Live grip tuning: " + ex.Message)); } } } internal sealed class PickupScale : MonoBehaviour { internal const float UnitsPerMetre = 1.36f; private void Start() { //IL_0037: 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) Transform parent = ((Component)this).transform.parent; if (!((Object)(object)parent != (Object)null) || !((Object)parent).name.StartsWith("Add-on weapon", StringComparison.Ordinal)) { ((Component)this).transform.localScale = ((Component)this).transform.localScale * 1.36f; } Object.Destroy((Object)(object)this); } } internal static class WeaponRegistry { public static readonly List<WeaponEntry> Registered = new List<WeaponEntry>(); public static WeaponEntry Starter { get; private set; } public static void RegisterAll(ModuleInfo module, List<WeaponEntry> entries, string pluginDir, string dataFile) { foreach (WeaponEntry entry in entries) { try { WeaponDefinition val = Build(entry, pluginDir, dataFile); GameApi.RegisterWeapon(module, val); Registered.Add(entry); if (entry.Starter && Starter == null) { Starter = entry; } Plugin.Log.LogInfo((object)("Registered " + entry.ItemId + " (" + entry.Name + ", " + ((object)Unsafe.As<WeaponTemplate, WeaponTemplate>(ref entry.Template)/*cast due to .constrained prefix*/).ToString() + " behaviour)")); } catch (Exception ex) { Plugin.Log.LogError((object)("Could not register " + entry.Key + ": " + ex.Message)); } } } private static WeaponDefinition Build(WeaponEntry e, string pluginDir, string dataFile) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown Sanitize(e); CheckAmmo(e); int? num = (e.Starter ? new int?(0) : ((!e.Merchant && !Plugin.Cfg.SellFindables.Value) ? ((int?)null) : new int?(e.Price ?? DefaultPrice(e)))); string text = Path.Combine(pluginDir, e.Icon); string text2 = (File.Exists(text) ? text : null); ItemDefinition val = new ItemDefinition(e.ItemId, e.Name, e.Width, e.Height, 1, e.Description, text2, num, Math.Max(0, e.Sell), (Func<object>)null, (Func<ItemUseContext, ItemUseResult>)null); WeaponModel weaponModel = WeaponModel.TryOpen(e, pluginDir, dataFile); Func<object> func = ((weaponModel != null) ? new Func<object>(weaponModel.Create) : null); string text3 = weaponModel?.MuzzlePath ?? "Muzzle"; return new WeaponDefinition(val, e.Template, e.Capacity, e.Damage, e.Interval, e.Reload, e.AmmoId, e.Range, e.Spread, e.Pellets, e.Burst, e.Automatic, false, func, (ModelTransform?)null, WeaponAudio.For(e, pluginDir), (IEnumerable<WeaponUpgradeStep>)e.Upgrades, text3); } private static int DefaultPrice(WeaponEntry e) { return Math.Max(1000, e.Sell * 2); } private static void CheckAmmo(WeaponEntry e) { if (string.IsNullOrEmpty(e.AmmoId)) { e.AmmoId = null; return; } try { bool flag = false; foreach (ItemDefinition item in GameApi.Items) { if (item != null && item.Id != null && item.Id.StartsWith("re4:", StringComparison.Ordinal)) { flag = true; break; } } if (flag && GameApi.FindItem(e.AmmoId) == null) { Plugin.Log.LogWarning((object)(e.Key + ": ammo \"" + e.AmmoId + "\" is not an RE4Gameplay item; using the " + ((object)Unsafe.As<WeaponTemplate, WeaponTemplate>(ref e.Template)/*cast due to .constrained prefix*/).ToString() + "'s ammo")); e.AmmoId = null; } } catch (Exception) { } } private static void Sanitize(WeaponEntry e) { e.Capacity = Clamp(e, "capacity", e.Capacity, 1, 9999); e.Damage = Clamp(e, "damage", e.Damage, 0.01f, 1000000f); e.Interval = Clamp(e, "interval", e.Interval, 0.02f, 120f); e.Reload = Clamp(e, "reload", e.Reload, 0.01f, 120f); e.Range = Clamp(e, "range", e.Range, 0.5f, 1000f); e.Spread = Clamp(e, "spread", e.Spread, 0f, 1f); e.Pellets = Clamp(e, "pellets", e.Pellets, 1, 32); e.Burst = Clamp(e, "burst", e.Burst, 1, 16); e.Width = Clamp(e, "width", e.Width, 1, 15); e.Height = Clamp(e, "height", e.Height, 1, 8); if (e.Name.Length > 128) { e.Name = e.Name.Substring(0, 128); } if (e.Description.Length > 2048) { e.Description = e.Description.Substring(0, 2048); } } private static int Clamp(WeaponEntry e, string what, int v, int min, int max) { int num = Math.Min(max, Math.Max(min, v)); if (num != v) { Plugin.Log.LogWarning((object)(e.Key + ": " + what + " " + v + " clamped to " + num)); } return num; } private static float Clamp(WeaponEntry e, string what, float v, float min, float max) { float num = (float.IsNaN(v) ? min : Mathf.Clamp(v, min, max)); if (Math.Abs(num - v) > 1E-06f) { Plugin.Log.LogWarning((object)(e.Key + ": " + what + " " + v + " clamped to " + num)); } return num; } public static bool IsOurs(string itemId) { return itemId?.StartsWith("re9gameplay:", StringComparison.Ordinal) ?? false; } public static WeaponEntry Find(string itemId) { foreach (WeaponEntry item in Registered) { if (item.ItemId == itemId) { return item; } } return null; } } } namespace RE9Gameplay.Gameplay { internal static class Findables { private static float spawnAt = -1f; private static int seed; public static void Reset() { spawnAt = -1f; } public static void LevelReady() { if (Plugin.Cfg.FindablesEnabled.Value && GameApi.IsHost) { spawnAt = Time.realtimeSinceStartup + 4f; seed = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.randomMapSeed : Environment.TickCount); } } public static void Tick(float now) { if (spawnAt < 0f || now < spawnAt) { return; } spawnAt = -1f; try { Spawn(); } catch (Exception ex) { Plugin.Log.LogError((object)("Findable spawn failed: " + ex)); } } private static void Spawn() { //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) if (!GameApi.IsHost) { return; } if (!GameApi.IsContentCompatible) { Plugin.Log.LogWarning((object)"Findables skipped: add-on catalogs do not match in this lobby"); return; } RoundManager instance = RoundManager.Instance; GameObject[] array = (((Object)(object)instance != (Object)null) ? instance.insideAINodes : null); if (array == null || array.Length == 0) { Plugin.Log.LogWarning((object)"Findables skipped: no inside AI nodes on this moon"); return; } Random random = new Random(seed ^ 0x5E9A11); HashSet<string> hashSet = OwnedByEveryone(); List<KeyValuePair<string, float>> list = new List<KeyValuePair<string, float>>(); float num = 0f; foreach (WeaponEntry item in WeaponRegistry.Registered) { if (!item.Starter && !(item.FindWeight <= 0f) && (!Plugin.Cfg.SkipOwnedFindables.Value || !hashSet.Contains(item.ItemId))) { list.Add(new KeyValuePair<string, float>(item.ItemId, item.FindWeight)); num += item.FindWeight; } } if (list.Count == 0 || num <= 0f) { return; } int num2 = Mathf.Max(0, Plugin.Cfg.FindablesPerLanding.Value); float num3 = Mathf.Clamp01(Plugin.Cfg.FindableChance.Value); HashSet<int> hashSet2 = new HashSet<int>(); int num4 = 0; for (int i = 0; i < num2; i++) { if (random.NextDouble() > (double)num3) { continue; } double num5 = random.NextDouble() * (double)num; string key = list[list.Count - 1].Key; foreach (KeyValuePair<string, float> item2 in list) { num5 -= (double)item2.Value; if (num5 <= 0.0) { key = item2.Key; break; } } int num6 = -1; for (int j = 0; j < 12; j++) { int num7 = random.Next(array.Length); if ((Object)(object)array[num7] != (Object)null && hashSet2.Add(num7)) { num6 = num7; break; } } if (num6 >= 0) { Vector3 position = array[num6].transform.position; Result val = GameApi.SpawnPickup(key, 1, new Position(position.x, position.y, position.z)); if (((Result)(ref val)).Success) { num4++; } else { Plugin.Log.LogWarning((object)("Could not place " + key + ": " + ((Result)(ref val)).Message)); } } } if (num4 > 0) { Plugin.Log.LogInfo((object)("Placed " + num4 + " RE9 gun(s) in the facility")); } } private static HashSet<string> OwnedByEveryone() { HashSet<string> hashSet = new HashSet<string>(); StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null) { return hashSet; } bool flag = true; PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val == (Object)null || !val.isPlayerControlled) { continue; } PlayerSnapshot player = GameApi.GetPlayer(val.actualClientId); if (player == null || !player.IsResidentEvilMode) { continue; } HashSet<string> hashSet2 = new HashSet<string>(); if (player.Items != null) { foreach (ItemSnapshot item in player.Items) { if (item != null && item.ItemId != null) { hashSet2.Add(item.ItemId); } } } if (flag) { hashSet.UnionWith(hashSet2); flag = false; } else { hashSet.IntersectWith(hashSet2); } } return hashSet; } } [HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")] internal static class SpawnScrapPatch { [HarmonyPostfix] private static void Postfix() { try { Findables.LevelReady(); } catch (Exception ex) { Plugin.Log.LogError((object)("Findables hook: " + ex.Message)); } } } internal static class Re5Compat { private const char Sep = '\u001f'; private const string Re5Prefix = "re5gameplay "; private static MethodInfo manifestGetter; private static FieldInfo packetText; private static FieldInfo packetOp; public static void Install(Harmony harmony) { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_016f: 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_0191: Expected O, but got Unknown //IL_0191: Expected O, but got Unknown Type type = AccessTools.TypeByName("RE4Company.Session"); Type type2 = AccessTools.TypeByName("RE4Company.AddonBridge"); Type type3 = AccessTools.TypeByName("RE5Arsenal.Plugin"); if (!(type3 == null)) { MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Request", (Type[])null, (Type[])null) : null); MethodInfo methodInfo2 = ((type2 != null) ? AccessTools.Method(type2, "Hello", (Type[])null, (Type[])null) : null); MethodInfo methodInfo3 = AccessTools.Method(type3, "Heard", (Type[])null, (Type[])null); packetText = AccessTools.Field(AccessTools.TypeByName("RE4Company.Packet"), "Text"); packetOp = AccessTools.Field(AccessTools.TypeByName("RE4Company.Packet"), "Op"); manifestGetter = AccessTools.PropertyGetter(typeof(GameApi), "Manifest"); if (methodInfo == null || methodInfo2 == null || methodInfo3 == null || packetText == null || packetOp == null || manifestGetter == null) { Plugin.Log.LogWarning((object)"RE5Gameplay is installed but its hello hook could not be matched; if RE9 guns and RE5 guns stop working together, report this log."); return; } HarmonyMethod val = new HarmonyMethod(typeof(Re5Compat), "RequestPrefix", (Type[])null) { priority = 0 }; harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Re5Compat), "HelloPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(Re5Compat), "HeardPrefix", (Type[])null), new HarmonyMethod(typeof(Re5Compat), "HeardPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Plugin.Log.LogInfo((object)"RE5Gameplay found: sharing RE4Gameplay's hello so RE5 guns and add-on guns both work."); } } private static void RequestPrefix(string op, ref string text) { if (!(op != "hello") && text != null && text.StartsWith("re5gameplay ", StringComparison.Ordinal) && text.IndexOf('\u001f') < 0) { string text2; try { text2 = manifestGetter.Invoke(null, null) as string; } catch (Exception) { return; } if (!string.IsNullOrEmpty(text2)) { text = text + "\u001f" + text2; } } } private static void HelloPrefix(ref string manifest) { if (manifest != null) { int num = manifest.IndexOf('\u001f'); if (num >= 0) { manifest = manifest.Substring(num + 1); } } } private static void HeardPrefix(object request, out string __state) { __state = null; if (request != null && !(packetOp.GetValue(request) as string != "hello")) { string text = packetText.GetValue(request) as string; int num = text?.IndexOf('\u001f') ?? (-1); if (num >= 0) { __state = text; packetText.SetValue(request, text.Substring(0, num)); } } } private static void HeardPostfix(object request, string __state) { if (__state != null && request != null) { packetText.SetValue(request, __state); } } } internal static class Re9CaseStyle { private static FieldInfo gridField; private static FieldInfo piecesField; private static FieldInfo backgroundField; private static FieldInfo headingField; private static FieldInfo uiRoot; private static readonly Color Backdrop = new Color(0.02f, 0.02f, 0.025f, 0.78f); private static readonly Color GridLine = new Color(0.82f, 0.83f, 0.86f, 0.3f); private static readonly Color Tile = new Color(0.16f, 0.16f, 0.17f, 0.85f); private static readonly Color TileEdge = new Color(0.85f, 0.85f, 0.88f, 0.45f); private static bool Active { get { if (Plugin.Cfg.Re9CaseLook.Value) { return FirstPersonBody.WearingOurs(); } return false; } } public static void Install(Harmony harmony) { //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown Type type = AccessTools.TypeByName("RE4Company.NativeMenus"); Type type2 = AccessTools.TypeByName("RE4Company.CaseModel"); Type type3 = AccessTools.TypeByName("RE4Company.OriginalUi"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Case", (Type[])null, (Type[])null) : null); MethodInfo methodInfo2 = ((type2 != null) ? AccessTools.Method(type2, "Draw", (Type[])null, (Type[])null) : null); gridField = ((type != null) ? AccessTools.Field(type, "grid") : null); piecesField = ((type != null) ? AccessTools.Field(type, "pieces") : null); backgroundField = ((type != null) ? AccessTools.Field(type, "background") : null); headingField = ((type != null) ? AccessTools.Field(type, "heading") : null); uiRoot = ((type3 != null) ? AccessTools.Field(type3, "Root") : null); if (methodInfo == null || methodInfo2 == null) { Plugin.Log.LogWarning((object)"RE4Gameplay's case screen was not found; RE9 suits use the RE4 case look."); return; } harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Re9CaseStyle), "DrawPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Re9CaseStyle), "CasePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static bool DrawPrefix() { return !Active; } private static void CasePostfix(object __instance, Transform panel) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) try { bool active = Active; ShowOriginal(__instance, backgroundField, !active); ShowOriginal(__instance, headingField, !active); Transform val = (((Object)(object)panel != (Object)null) ? panel.Find("RE9 case backdrop") : null); if (!active) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)((Component)val).gameObject); } } else { if ((Object)(object)panel == (Object)null) { return; } if ((Object)(object)val == (Object)null) { GameObject val2 = new GameObject("RE9 case backdrop", new Type[2] { typeof(RectTransform), typeof(Image) }); RectTransform val3 = (RectTransform)val2.transform; ((Transform)val3).SetParent(panel, false); val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = new Vector2(-4000f, -4000f); val3.offsetMax = new Vector2(4000f, 4000f); Image component = val2.GetComponent<Image>(); ((Graphic)component).color = Backdrop; ((Graphic)component).raycastTarget = false; ((Transform)val3).SetAsFirstSibling(); } if (gridField?.GetValue(__instance) is IList list) { foreach (object item in list) { object obj = Item1(item); RectTransform val4 = (RectTransform)((obj is RectTransform) ? obj : null); if (val4 != null) { Graphic[] components = ((Component)val4).GetComponents<Graphic>(); for (int i = 0; i < components.Length; i++) { components[i].color = GridLine; } } } } if (!(piecesField?.GetValue(__instance) is IList list2)) { return; } { foreach (object item2 in list2) { object obj2 = Item1(item2); RectTransform val5 = (RectTransform)((obj2 is RectTransform) ? obj2 : null); if (val5 != null && (Object)(object)((Transform)val5).Find("RE9 tile") == (Object)null) { GameObject val6 = new GameObject("RE9 tile", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Outline) }); RectTransform val7 = (RectTransform)val6.transform; ((Transform)val7).SetParent((Transform)(object)val5, false); val7.anchorMin = Vector2.zero; val7.anchorMax = Vector2.one; val7.offsetMin = new Vector2(1.5f, 1.5f); val7.offsetMax = new Vector2(-1.5f, -1.5f); Image component2 = val6.GetComponent<Image>(); ((Graphic)component2).color = Tile; ((Graphic)component2).raycastTarget = false; Outline component3 = val6.GetComponent<Outline>(); ((Shadow)component3).effectColor = TileEdge; ((Shadow)component3).effectDistance = new Vector2(1f, -1f); ((Transform)val7).SetAsFirstSibling(); } } return; } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("RE9 case look not applied: " + ex.Message)); } } private static object Item1(object tuple) { return tuple?.GetType().GetField("Item1")?.GetValue(tuple); } private static void ShowOriginal(object menus, FieldInfo field, bool show) { if (field == null || uiRoot == null) { return; } object value = field.GetValue(menus); if (value != null) { object? value2 = uiRoot.GetValue(value); RectTransform val = (RectTransform)((value2 is RectTransform) ? value2 : null); if (val != null && ((Component)val).gameObject.activeSelf != show) { ((Component)val).gameObject.SetActive(show); } } } } internal static class Re9Kit { private const string KitKey = "re9gameplay.kit"; private const string RestKey = "re9gameplay.resting"; private const string SnapKey = "re9gameplay.snapperAt"; private static readonly string[] PutAside = new string[2] { "Handgun", "M92F" }; private static bool resolved; private static bool broken; private static FieldInfo sessionInstance; private static FieldInfo sessionPlayers; private static FieldInfo pcAddon; private static FieldInfo loItems; private static FieldInfo loAddonData; private static FieldInfo loWeapon; private static FieldInfo loLoaded; private static FieldInfo ciKind; private static FieldInfo ciCount; private static FieldInfo ciX; private static FieldInfo ciY; private static FieldInfo ciRotated; private static FieldInfo ciLocked; private static MethodInfo findPlayer; private static MethodInfo characterFor; private static MethodInfo loAdd; private static MethodInfo loCanPlace; private static MethodInfo loOwns; private static MethodInfo reply; private static MethodInfo kindOf; private static ConstructorInfo caseItemCtor; private static FieldInfo specAll; private static FieldInfo specAddon; private static float next; public static void Tick(float now) { if (now < next) { return; } next = now + 0.5f; if (!Plugin.Cfg.Re9Kit.Value || !Resolve()) { return; } try { object value = sessionInstance.GetValue(null); if (value == null || !(sessionPlayers.GetValue(value) is IDictionary dictionary)) { return; } List<ulong> list = new List<ulong>(); foreach (object key in dictionary.Keys) { list.Add((ulong)key); } foreach (ulong item in list) { object obj = dictionary[item]; if (obj == null) { continue; } object? obj2 = findPlayer.Invoke(null, new object[1] { item }); PlayerControllerB val = (PlayerControllerB)((obj2 is PlayerControllerB) ? obj2 : null); if ((Object)(object)val == (Object)null) { continue; } bool flag = WearingOurs(val); Dictionary<string, string> dictionary2 = loAddonData.GetValue(obj) as Dictionary<string, string>; if (dictionary2 == null) { dictionary2 = new Dictionary<string, string>(); loAddonData.SetValue(obj, dictionary2); } string value2; bool flag2 = dictionary2.TryGetValue("re9gameplay.kit", out value2) && value2 == "1"; if (!dictionary2.ContainsKey("re5gameplay.slots") && !HasMarker(obj, "re5gameplay.slots")) { bool flag3 = false; if (flag) { flag3 = Apply(obj, dictionary2, flag2); } else if (flag2) { flag3 = Restore(obj, dictionary2); } if (flag3) { reply.Invoke(value, new object[4] { item, "", 0, 0f }); Plugin.Log.LogInfo((object)("Player " + item + ": " + (flag ? "RE9 kit (Alligator Snapper)" : "back to the full pistol set"))); } } } } catch (Exception ex) { broken = true; Plugin.Log.LogWarning((object)("RE9 kit switching stopped: " + (ex.InnerException ?? ex).Message)); } } private static bool WearingOurs(PlayerControllerB player) { object obj = characterFor.Invoke(null, new object[1] { player }); CharacterDefinition val = (CharacterDefinition)((obj != null) ? /*isinst with value type is only supported in some contexts*/: null); if (val != null) { return val.Id.StartsWith("re9gameplay:", StringComparison.Ordinal); } return false; } private static bool HasMarker(object state, string marker) { if (AccessTools.Field(state.GetType(), "SeenPickups")?.GetValue(state) is List<string> list) { return list.Contains(marker); } return false; } private static bool Apply(object state, Dictionary<string, string> data, bool kit) { if (!(loItems.GetValue(state) is IList list)) { return false; } string value; StringBuilder stringBuilder = new StringBuilder(data.TryGetValue("re9gameplay.resting", out value) ? value : ""); bool flag = false; int num = -1; int num2 = -1; bool flag2 = false; for (int num3 = list.Count - 1; num3 >= 0; num3--) { object obj = list[num3]; string text = ciKind.GetValue(obj) as string; if (Array.IndexOf(PutAside, text) >= 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(';'); } stringBuilder.Append(Escape(text)).Append('|').Append(ciCount.GetValue(obj)) .Append('|') .Append(ciX.GetValue(obj)) .Append('|') .Append(ciY.GetValue(obj)) .Append('|') .Append(((bool)ciRotated.GetValue(obj)) ? 1 : 0) .Append('|') .Append(((bool)ciLocked.GetValue(obj)) ? 1 : 0); if (text == "Handgun" || num < 0) { num = (int)ciX.GetValue(obj); num2 = (int)ciY.GetValue(obj); flag2 = (bool)ciRotated.GetValue(obj); } list.RemoveAt(num3); flag = true; } } string text2 = SnapperKind(); if (!string.IsNullOrEmpty(text2) && !Has(list, text2) && (bool)loAdd.Invoke(state, new object[2] { text2, 1 })) { FillMagazine(state); flag = true; } if (num >= 0 && !string.IsNullOrEmpty(text2)) { object obj2 = Find(list, text2); if (obj2 != null) { int num4 = (int)ciX.GetValue(obj2); int num5 = (int)ciY.GetValue(obj2); bool flag3 = (bool)ciRotated.GetValue(obj2); list.Remove(obj2); ciX.SetValue(obj2, num); ciY.SetValue(obj2, num2); ciRotated.SetValue(obj2, flag2); if ((bool)loCanPlace.Invoke(state, new object[4] { obj2, num, num2, flag2 })) { if (!data.ContainsKey("re9gameplay.snapperAt")) { data["re9gameplay.snapperAt"] = num4 + "|" + num5 + "|" + (flag3 ? 1 : 0); } } else { ciX.SetValue(obj2, num4); ciY.SetValue(obj2, num5); ciRotated.SetValue(obj2, flag3); } list.Add(obj2); } } if (flag || !kit) { data["re9gameplay.resting"] = stringBuilder.ToString(); data["re9gameplay.kit"] = "1"; SelectOwnedWeapon(state); flag = true; } return flag; } private static bool Restore(object state, Dictionary<string, string> data) { if (!(loItems.GetValue(state) is IList list)) { return false; } string text = SnapperKind(); object obj = (string.IsNullOrEmpty(text) ? null : Find(list, text)); if (obj != null && data.TryGetValue("re9gameplay.snapperAt", out var value)) { string[] array = value.Split('|'); if (array.Length == 3) { int num = (int)ciX.GetValue(obj); int num2 = (int)ciY.GetValue(obj); bool flag = (bool)ciRotated.GetValue(obj); int num3 = int.Parse(array[0], CultureInfo.InvariantCulture); int num4 = int.Parse(array[1], CultureInfo.InvariantCulture); bool flag2 = array[2] == "1"; list.Remove(obj); ciX.SetValue(obj, num3); ciY.SetValue(obj, num4); ciRotated.SetValue(obj, flag2); if (!(bool)loCanPlace.Invoke(state, new object[4] { obj, num3, num4, flag2 })) { ciX.SetValue(obj, num); ciY.SetValue(obj, num2); ciRotated.SetValue(obj, flag); } list.Add(obj); } } data.Remove("re9gameplay.snapperAt"); if (data.TryGetValue("re9gameplay.resting", out var value2) && !string.IsNullOrEmpty(value2)) { string[] array2 = value2.Split(';'); for (int i = 0; i < array2.Length; i++) { string[] array3 = array2[i].Split('|'); if (array3.Length < 6) { continue; } string text2 = Unescape(array3[0]); int num5 = int.Parse(array3[1], CultureInfo.InvariantCulture); if (!Has(list, text2)) { object obj2 = caseItemCtor.Invoke(new object[2] { text2, num5 }); int num6 = int.Parse(array3[2], CultureInfo.InvariantCulture); int num7 = int.Parse(array3[3], CultureInfo.InvariantCulture); bool flag3 = array3[4] == "1"; ciX.SetValue(obj2, num6); ciY.SetValue(obj2, num7); ciRotated.SetValue(obj2, flag3); ciLocked.SetValue(obj2, array3[5] == "1"); if ((bool)loCanPlace.Invoke(state, new object[4] { obj2, num6, num7, flag3 })) { list.Add(obj2); } else if (!(bool)loAdd.Invoke(state, new object[2] { text2, num5 })) { Plugin.Log.LogWarning((object)("No room to give back the " + text2 + "; it stays put aside.")); } } } } data.Remove("re9gameplay.resting"); data.Remove("re9gameplay.kit"); return true; } private static object Find(IList items, string kind) { foreach (object item in items) { if (ciKind.GetValue(item) as string == kind) { return item; } } return null; } private static bool Has(IList items, string kind) { foreach (object item in items) { if (ciKind.GetValue(item) as string == kind) { return true; } } return false; } private static string SnapperKind() { if (WeaponRegistry.Starter == null) { return null; } try { return kindOf.Invoke(null, new object[1] { WeaponRegistry.Starter.ItemId }) as string; } catch (Exception) { return null; } } private static int SnapperIndex() { if (WeaponRegistry.Starter == null || !(specAll.GetValue(null) is Array array)) { return -1; } for (int i = 0; i < array.Length; i++) { object? value = specAddon.GetValue(array.GetValue(i)); WeaponDefinition val = (WeaponDefinition)((value is WeaponDefinition) ? value : null); if (val != null && val.Id == WeaponRegistry.Starter.ItemId) { return i; } } return -1; } private static void FillMagazine(object state) { int num = SnapperIndex(); int[] array = loLoaded.GetValue(state) as int[]; if (num >= 0 && array != null && num < array.Length && array[num] <= 0) { array[num] = (int)AccessTools.Method(state.GetType(), "Capacity", new Type[1] { typeof(int) }, (Type[])null).Invoke(state, new object[1] { num }); } } private static void SelectOwnedWeapon(object state) { int num = (int)loWeapon.GetValue(state); if (!(bool)loOwns.Invoke(state, new object[1] { num })) { int num2 = SnapperIndex(); if (num2 >= 0 && (bool)loOwns.Invoke(state, new object[1] { num2 })) { loWeapon.SetValue(state, num2); } } } private static string Escape(string s) { return (s ?? "").Replace("%", "%25").Replace(";", "%3B").Replace("|", "%7C"); } private static string Unescape(string s) { return s.Replace("%7C", "|").Replace("%3B", ";").Replace("%25", "%"); } private static bool Resolve() { if (resolved) { return !broken; } resolved = true; Type type = AccessTools.TypeByName("RE4Company.Session"); Type type2 = AccessTools.TypeByName("RE4Company.PlayableCharacters"); Type type3 = AccessTools.TypeByName("RE4Company.PlayableCharacter"); Type type4 = AccessTools.TypeByName("RE4Company.Loadout"); Type type5 = AccessTools.TypeByName("RE4Company.CaseItem"); Type type6 = AccessTools.TypeByName("RE4Company.AddonBridge"); Type type7 = AccessTools.TypeByName("RE4Company.WeaponSpec"); if (type == null || type2 == null || type3 == null || type4 == null || type5 == null || type6 == null || type7 == null) { broken = true; } else { sessionInstance = AccessTools.Field(type, "Instance"); sessionPlayers = AccessTools.Field(type, "Players"); findPlayer = AccessTools.Method(type, "FindPlayer", new Type[1] { typeof(ulong) }, (Type[])null); reply = AccessTools.Method(type, "Reply", new Type[4] { typeof(ulong), typeof(string), typeof(int), typeof(float) }, (Type[])null); characterFor = AccessTools.Method(type2, "For", new Type[1] { typeof(PlayerControllerB) }, (Type[])null); pcAddon = AccessTools.Field(type3, "Addon"); loItems = AccessTools.Field(type4, "Items"); loAddonData = AccessTools.Field(type4, "AddonData"); loWeapon = AccessTools.Field(type4, "Weapon"); loLoaded = AccessTools.Field(type4, "Loaded"); loAdd = AccessTools.Method(type4, "Add", new Type[2] { typeof(string), typeof(int) }, (Type[])null); loCanPlace = AccessTools.Method(type4, "CanPlace", new Type[4] { type5, typeof(int), typeof(int), typeof(bool) }, (Type[])null); loOwns = AccessTools.Method(type4, "Owns", new Type[1] { typeof(int) }, (Type[])null); ciKind = AccessTools.Field(type5, "Kind"); ciCount = AccessTools.Field(type5, "Count"); ciX = AccessTools.Field(type5, "X"); ciY = AccessTools.Field(type5, "Y"); ciRotated = AccessTools.Field(type5, "Rotated"); ciLocked = AccessTools.Field(type5, "Locked"); caseItemCtor = AccessTools.Constructor(type5, new Type[2] { typeof(string), typeof(int) }, false); kindOf = AccessTools.Method(type6, "Kind", new Type[1] { typeof(string) }, (Type[])null); specAll = AccessTools.Field(type7, "All"); specAddon = AccessTools.Field(type7, "Addon"); broken = sessionInstance == null || sessionPlayers == null || findPlayer == null || reply == null || characterFor == null || pcAddon == null || loItems == null || loAddonData == null || loWeapon == null || loLoaded == null || loAdd == null || loCanPlace == null || loOwns == null || ciKind == null || ciCount == null || ciX == null || ciY == null || ciRotated == null || ciLocked == null || caseItemCtor == null || kindOf == null || specAll == null || specAddon == null; } if (broken) { Plugin.Log.LogWarning((object)"RE4Gameplay's inventory could not be reached; RE9 suits keep every pistol."); } return !broken; } } internal static class ShopPreviews { private static FieldInfo all; private static FieldInfo icon; private static FieldInfo addon; private static FieldInfo assetPath; private static bool resolved; private static bool broken; private static float next; private static object lastAll; private static int fixedCount; public static void Tick(float now) { if (now < next) { return; } next = now + 1f; if (!Resolve()) { return; } try { if (!(all.GetValue(null) is Array array) || (array == lastAll && fixedCount == WeaponRegistry.Registered.Count)) { return; } lastAll = array; string text = assetPath.GetValue(null) as string; if (string.IsNullOrEmpty(text)) { return; } string fullPath = Path.GetFullPath(Path.Combine(text, "ui", "shop_previews")); Dictionary<string, string> dictionary = new Dictionary<string, string>(); string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location); foreach (WeaponEntry item in WeaponRegistry.Registered) { string fullPath2 = Path.GetFullPath(Path.Combine(directoryName, item.Icon)); if (File.Exists(fullPath2)) { dictionary[item.ItemId] = fullPath2; } } int num = 0; foreach (object item2 in array) { if (item2 == null) { continue; } object? value = addon.GetValue(item2); WeaponDefinition val = (WeaponDefinition)((value is WeaponDefinition) ? value : null); if (val != null && dictionary.TryGetValue(val.Id, out var value2)) { string text2 = Relative(fullPath, value2.Substring(0, value2.Length - 4)); if (text2 == null) { text2 = "re9gameplay_no_preview/" + val.Id.Replace(':', '_'); } if (!string.Equals(icon.GetValue(item2) as string, text2, StringComparison.Ordinal)) { icon.SetValue(item2, text2); } num++; } } if (num > 0 && num != fixedCount) { Plugin.Log.LogInfo((object)("Merchant pictures: " + num + " RE9 guns show their own pictures.")); } fixedCount = num; } catch (Exception ex) { broken = true; Plugin.Log.LogWarning((object)("Merchant pictures could not be set (" + ex.Message + "); the Merchant shows the RE4 pictures.")); } } private static string Relative(string fromDir, string toFile) { char[] array = new char[2] { '\\', '/' }; string[] array2 = fromDir.TrimEnd(array).Split(array); string[] array3 = toFile.Split(array); int i; for (i = 0; i < array2.Length && i < array3.Length - 1 && string.Equals(array2[i], array3[i], StringComparison.OrdinalIgnoreCase); i++) { } if (i == 0) { return null; } List<string> list = new List<string>(); for (int j = i; j < array2.Length; j++) { list.Add(".."); } for (int k = i; k < array3.Length; k++) { list.Add(array3[k]); } return string.Join("/", list); } private static bool Resolve() { if (resolved) { return !broken; } resolved = true; Type type = AccessTools.TypeByName("RE4Company.WeaponSpec"); Type type2 = AccessTools.TypeByName("RE4Company.Plugin"); all = ((type != null) ? AccessTools.Field(type, "All") : null); icon = ((type != null) ? AccessTools.Field(type, "Icon") : null); addon = ((type != null) ? AccessTools.Field(type, "Addon") : null); assetPath = ((type2 != null) ? AccessTools.Field(type2, "AssetPath") : null); broken = all == null || icon == null || addon == null || assetPath == null; if (broken) { Plugin.Log.LogWarning((object)"RE4Gameplay's Merchant pictures were not found; the Merchant shows the RE4 pictures for RE9 guns."); } return !broken; } } internal static class StarterGun { private const string Flag = "starterGiven2"; private static float nextCheck; private static readonly HashSet<ulong> warned = new HashSet<ulong>(); public static void Reset() { nextCheck = 0f; warned.Clear(); } public static void Tick(ModuleInfo module, float now) { //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Cfg.GiveStarter.Value || WeaponRegistry.Starter == null || StarterPatch.Installed || !GameApi.IsHost || !GameApi.IsContentCompatible || now < nextCheck) { return; } nextCheck = now + 2f; StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null) { return; } string itemId = WeaponRegistry.Starter.ItemId; PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val == (Object)null || !val.isPlayerControlled || val.isPlayerDead) { continue; } ulong actualClientId = val.actualClientId; PlayerSnapshot player = GameApi.GetPlayer(actualClientId); if (player == null || !player.IsResidentEvilMode || player.IsDead) { continue; } Dictionary<string, object> dictionary = ReadData(module, actualClientId); if (MiniJson.GetBool(dictionary, "starterGiven2", fallback: false)) { continue; } if (Owns(player, itemId)) { MarkGiven(module, actualClientId, dictionary); continue; } Result val2 = GameApi.GiveItem(actualClientId, itemId, 1); if (((Result)(ref val2)).Success) { MarkGiven(module, actualClientId, dictionary); Plugin.Log.LogInfo((object)("Gave " + WeaponRegistry.Starter.Name + " to client " + actualClientId)); } else if (warned.Add(actualClientId)) { Plugin.Log.LogInfo((object)("Starter gun for client " + actualClientId + " is waiting: " + ((Result)(ref val2)).Message)); } } } private static bool Owns(PlayerSnapshot snap, string id) { if (snap.EquippedItemId == id) { return true; } if (snap.Items == null) { return false; } foreach (ItemSnapshot item in snap.Items) { if (item != null && item.ItemId == id) { return true; } } return false; } internal static Dictionary<string, object> ReadData(ModuleInfo module, ulong client) { string playerData = GameApi.GetPlayerData(module, client); if (string.IsNullOrEmpty(playerData)) { return new Dictionary<string, object>(); } try { return MiniJson.Obj(MiniJson.Parse(playerData)) ?? new Dictionary<string, object>(); } catch (Exception) { return new Dictionary<string, object>(); } } private static void MarkGiven(ModuleInfo module, ulong client, Dictionary<string, object> data) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) data["starterGiven2"] = true; data["v"] = 1.0; Result val = GameApi.SetPlayerData(module, client, MiniJson.Write(data)); if (!((Result)(ref val)).Success) { Plugin.Log.LogWarning((object)("Could not save starter flag for client " + client + ": " + ((Result)(ref val)).Message)); } } } internal static class StarterPatch { private static MethodInfo add; private static MethodInfo capacity; private static MethodInfo kindOf; private static FieldInfo loaded; private static FieldInfo weaponsAll; private static FieldInfo weaponAddon; private static string cachedKind; private static int cachedIndex = -1; public static bool Installed { get; private set; } public static void Install(Harmony harmony) { //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown Type type = AccessTools.TypeByName("RE4Company.Loadout"); Type type2 = AccessTools.TypeByName("RE4Company.AddonBridge"); Type type3 = AccessTools.TypeByName("RE4Company.WeaponSpec"); ConstructorInfo constructorInfo = ((type != null) ? AccessTools.Constructor(type, Type.EmptyTypes, false) : null); add = ((type != null) ? AccessTools.Method(type, "Add", new Type[2] { typeof(string), typeof(int) }, (Type[])null) : null); capacity = ((type != null) ? AccessTools.Method(type, "Capacity", new Type[1] { typeof(int) }, (Type[])null) : null); loaded = ((type != null) ? AccessTools.Field(type, "Loaded") : null); kindOf = ((type2 != null) ? AccessTools.Method(type2, "Kind", new Type[1] { typeof(string) }, (Type[])null) : null); weaponsAll = ((type3 != null) ? AccessTools.Field(type3, "All") : null); weaponAddon = ((type3 != null) ? AccessTools.Field(type3, "Addon") : null); if (constructorInfo == null || add == null || capacity == null || loaded == null || kindOf == null || weaponsAll == null || weaponAddon == null) { Plugin.Log.LogWarning((object)"RE4Gameplay's inventory could not be hooked; the Alligator Snapper is handed over afterwards instead."); return; } harmony.Patch((MethodBase)constructorInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(StarterPatch), "NewCase", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Installed = true; } private static void NewCase(object __instance) { try { if (!Plugin.Cfg.GiveStarter.Value || WeaponRegistry.Starter == null) { return; } string itemId = WeaponRegistry.Starter.ItemId; if (cachedKind == null) { cachedKind = kindOf.Invoke(null, new object[1] { itemId }) as string; } if (!string.IsNullOrEmpty(cachedKind) && (bool)add.Invoke(__instance, new object[2] { cachedKind, 1 })) { int num = WeaponIndex(itemId); int[] array = loaded.GetValue(__instance) as int[]; if (num >= 0 && array != null && num < array.Length) { array[num] = (int)capacity.Invoke(__instance, new object[1] { num }); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not add the Alligator Snapper to a new case: " + (ex.InnerException ?? ex).Message)); } } private static int WeaponIndex(string id) { if (!(weaponsAll.GetValue(null) is Array array)) { return -1; } if (cachedIndex >= 0 && cachedIndex < array.Length && Matches(array.GetValue(cachedIndex), id)) { return cachedIndex; } for (int i = 0; i < array.Length; i++) { if (Matches(array.GetValue(i), id)) { return cachedIndex = i; } } return -1; } private static bool Matches(object spec, string id) { if (spec != null) { object? value = weaponAddon.GetValue(spec); WeaponDefinition val = (WeaponDefinition)((value is WeaponDefinition) ? value : null); if (val != null) { return val.Id == id; } } return false; } } } namespace RE9Gameplay.Data { internal sealed class SkinEntry { public string Key; public string Name; public CharacterTemplate Template; public string Model; public float TargetHeight = 2.5f; public Vector3 Offset; public float Yaw; public float RackYaw = 180f; public List<string> HeadMeshes = new List<string>(); public Dictionary<string, string> BoneOverrides = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); public AimTuning Aim = new AimTuning(); public string MeleeModel; public Vector3 MeleeOffset; public Vector3 MeleeEuler; public float MeleeScale = 1f; public bool Holster; public Vector3 HolsterOffset; public Vector3 HolsterEuler; public string CharacterId => "re9gameplay:" + Key; } internal sealed class AimTuning { public float ReachPistol = 0.82f; public float ReachLong = 0.55f; public float SupportForward = 0.28f; public float LowReadyPitch = 35f; public float ChestPitchShare = 0.45f; public float BlendSpeed = 12f; } internal static class CharacterTable { public static List<SkinEntry> Load(string path) { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, object> o = MiniJson.Obj(MiniJson.Parse(File.ReadAllText(path))); List<SkinEntry> list = new List<SkinEntry>(); foreach (object item in MiniJson.GetArr(o, "skins") ?? throw new FormatException("characters.json has no \"skins\" array")) { Dictionary<string, object> dictionary = MiniJson.Obj(item); if (dictionary == null || !MiniJson.GetBool(dictionary, "enabled", fallback: true)) { continue; } SkinEntry skinEntry = new SkinEntry(); skinEntry.Key = MiniJson.GetString(dictionary, "key"); if (string.IsNullOrEmpty(skinEntry.Key)) { throw new FormatException("A skin has no \"key\""); } skinEntry.Name = MiniJson.GetString(dictionary, "name", skinEntry.Key); string text = MiniJson.GetString(dictionary, "voiceTemplate", "Leon"); if (!Enum.TryParse<CharacterTemplate>(text, ignoreCase: true, out skinEntry.Template)) { throw new FormatException(skinEntry.Key + ": unknown voiceTemplate \"" + text + "\""); } skinEntry.Model = MiniJson.GetString(dictionary, "model", "models/" + skinEntry.Key + ".glb"); skinEntry.TargetHeight = MiniJson.GetFloat(dictionary, "targetHeight", 2.5f); skinEntry.Offset = WeaponTable.Vec(MiniJson.GetFloats(dictionary, "offset"), Vector3.zero); skinEntry.Yaw = MiniJson.GetFloat(dictionary, "yaw", 0f); skinEntry.RackYaw = MiniJson.GetFloat(dictionary, "rackYaw", 180f); List<object> arr = MiniJson.GetArr(dictionary, "headMeshes"); if (arr != null) { foreach (object item2 in arr) { if (item2 is string { Length: >0 } text2) { skinEntry.HeadMeshes.Add(text2.ToLowerInvariant()); } } } Dictionary<string, object> obj = MiniJson.GetObj(dictionary, "bones"); if (obj != null) { foreach (KeyValuePair<string, object> item3 in obj) { if (item3.Value is string { Length: >0 } text3) { skinEntry.BoneOverrides[item3.Key] = text3; } } } Dictionary<string, object> obj2 = MiniJson.GetObj(dictionary, "melee"); if (obj2 != null && MiniJson.GetBool(obj2, "enabled", fallback: true)) { skinEntry.MeleeModel = MiniJson.GetString(obj2, "model"); Dictionary<string, object> obj3 = MiniJson.GetObj(obj2, "grip"); skinEntry.MeleeOffset = WeaponTable.Vec(MiniJson.GetFloats(obj3, "offset"), Vector3.zero); skinEntry.MeleeEuler = WeaponTable.Vec(MiniJson.GetFloats(obj3, "euler"), Vector3.zero); skinEntry.MeleeScale = MiniJson.GetFloat(obj3, "scale", 1f); Dictionary<string, object> obj4 = MiniJson.GetObj(obj2, "holster"); skinEntry.Holster = obj4 != null && MiniJson.GetBool(obj4, "enabled", fallback: true); skinEntry.HolsterOffset = WeaponTable.Vec(MiniJson.GetFloats(obj4, "offset"), Vector3.zero); skinEntry.HolsterEuler = WeaponTable.Vec(MiniJson.GetFloats(obj4, "euler"), Vector3.zero); } Dictionary<string, object> obj5 = MiniJson.GetObj(dictionary, "aim"); if (obj5 != null) { skinEntry.Aim.ReachPistol = MiniJson.GetFloat(obj5, "reachPistol", skinEntry.Aim.ReachPistol); skinEntry.Aim.ReachLong = MiniJson.GetFloat(obj5, "reachLong", skinEntry.Aim.ReachLong); skinEntry.Aim.SupportForward = MiniJson.GetFloat(obj5, "supportForward", skinEntry.Aim.SupportForward); skinEntry.Aim.LowReadyPitch = MiniJson.GetFloat(obj5, "lowReadyPitch", skinEntry.Aim.LowReadyPitch); skinEntry.Aim.ChestPitchShare = MiniJson.GetFloat(obj5, "chestPitchShare", skinEntry.Aim.ChestPitchShare); skinEntry.Aim.BlendSpeed = MiniJson.GetFloat(obj5, "blendSpeed", skinEntry.Aim.BlendSpeed); } list.Add(skinEntry); } return list; } } internal static class MiniJson { private sealed class Parser { private readonly string s; private int i; public bool End => i >= s.Length; public Parser(string text) { s = text; i = 0; } public FormatException Error(string message) { return new FormatException(message + " at character " + i); } public void SkipWs() { while (i < s.Length) { switch (s[i]) { case '\t': case '\n': case '\r': case ' ': case '\ufeff': i++; break; case '/': if (i + 1 < s.Length && s[i + 1] == '/') { while (i < s.Length && s[i] != '\n') { i++; } break; } return; default: return; } } } public object ReadValue() { if (End) { throw Error("Unexpected end of JSON"); } switch (s[i]) { case '{': return ReadObject(); case '[': return ReadArray(); case '"': return ReadString(); case 't': Expect("true"); return true; case 'f': Expect("false"); return false; case 'n': Expect("null"); return null; default: return ReadNumber(); } } private void Expect(string word) { if (string.CompareOrdinal(s, i, word, 0, word.Length) != 0) { throw Error("Expected " + word); } i += word.Length; } private Dictionary<string, object> ReadObject() { Dictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal); i++; SkipWs(); if (!End && s[i] == '}') { i++; return dictionary; } while (true) { SkipWs(); if (End || s[i] != '"') { throw Error("Expected property name"); } string key = ReadString(); SkipWs(); if (End || s[i] != ':') { throw Error("Expected ':'"); } i++; SkipWs(); dictionary[key] = ReadValue(); SkipWs(); if (End) { throw Error("Unterminated object"); } if (s[i] != ',') { break; } i++; SkipWs(); if (!End && s[i] == '}') { i++; return dictionary; } } if (s[i] == '}') { i++; return dictionary; } throw Error("Expected ',' or '}'"); } private List<object> ReadArray() { List<object> list = new List<object>(); i++; SkipWs(); if (!End && s[i] == ']') { i++; return list; } while (true) { SkipWs(); list.Add(ReadValue()); SkipWs(); if (End) { throw Error("Unterminated array"); } if (s[i] != ',') { break; } i++; SkipWs(); if (!End && s[i] == ']') { i++; return list; } } if (s[i] == ']') { i++; return list; } throw Error("Expected ',' or ']'"); } private string ReadString() { StringBuilder stringBuilder = new StringBuilder(); i++; while (!End) { char c = s[i++]; switch (c) { default: stringBuilder.Append(c); break; case '\\': if (End) { throw Error("Bad escape"); } switch (s[i++]) { case '"': stringBuilder.Append('"'); break; case '\\': stringBuilder.Append('\\'); break; case '/': stringBuilder.Append('/'); break; case 'b': stringBuilder.Append('\b'); break; case 'f': stringBuilder.Append('\f'); break; case 'n': stringBuilder.Append('\n'); break; case 'r': stringBuilder.Append('\r'); break; case 't': stringBuilder.Append('\t'); break; case 'u': if (i + 4 > s.Length) { throw Error("Bad unicode escape"); } stringBuilder.Append((char)int.Parse(s.Substring(i, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture)); i += 4; break; default: throw Error("Bad escape"); } break; case '"': return stringBuilder.ToString(); } } throw Error("Unterminated string"); } private double ReadNumber() { int num = i; while (i < s.Length) { char c = s[i]; if ((c < '0' || c > '9') && c != '-' && c != '+' && c != '.' && c != 'e' && c != 'E') { break; } i++; } if (num == i) { throw Error("Unexpected character '" + s[i] + "'"); } return double.Parse(s.Substring(num, i - num), NumberStyles.Float, CultureInfo.InvariantCulture); } } public static object Parse(string text) { if (text == null) { throw new ArgumentNullException("text"); } Parser parser = new Parser(text); parser.SkipWs(); object result = parser.ReadValue(); parser.SkipWs(); if (!parser.End) { throw parser.Error("Unexpected trailing characters"); } return result; } public static string Write(object value) { StringBuilder stringBuilder = new StringBuilder(); WriteValue(stringBuilder, value); return stringBuilder.ToString(); } public static Dictionary<string, object> Obj(object o) { return o as Dictionary<string, object>; } public static List<object> Arr(object o) { return o as List<object>; } public static object Get(Dictionary<string, object> o, string key) { if (o == null) { return null; } if (!o.TryGetValue(key, out var value)) { return null; } return value; } public static Dictionary<string, object> GetObj(Dictionary<string, object> o, string key) { return Get(o, key) as Dictionary<string, object>; } public static List<object> GetArr(Dictionary<string, object> o, string key) { return Get(o, key) as List<object>; } public static string GetString(Dictionary<string, object> o, string key, string fallback = null) { if (!(Get(o, key) is string result)) { return fallback; } return result; } public static double GetNumber(Dictionary<string, object> o, string key, double fallback) { object obj = Get(o, key); if (obj is double) { return (double)obj; } return fallback; } public static float GetFloat(Dictionary<string, object> o, string key, float fallback) { return (float)GetNumber(o, key, fallback); } public static int GetInt(Dictionary<string, object> o, string key, int fallback) { return (int)Math.Round(GetNumber(o, key, fallback)); } public static int? GetNullableInt(Dictionary<string, object> o, string key) { if (Get(o, key) is double a) { return (int)Math.Round(a); } return null; } public static bool GetBool(Dictionary<string, object> o, string key, bool fallback) { object obj = Get(o, key); if (obj is bool) { return (bool)obj; } return fallback; } public static float[] GetFloats(Dictionary<string, object> o, string key) { List<object> arr = GetArr(o, key); if (arr == null) { return null; } float[] array = new float[arr.Count]; for (int i = 0; i < arr.Count; i++) { array[i] = ((arr[i] is double num) ? ((float)num) : 0f); } return array; } public static int AsInt(object v, int fallback = -1) { if (!(v is double a)) { return fallback; } return (int)Math.Round(a); } private static void WriteValue(StringBuilder sb, object v) { if (v != null) { if (!(v is string s)) { if (!(v is bool flag)) { if (!(v is double num)) { if (!(v is float num2)) { if (!(v is int num3)) { if (!(v is long num4)) { if (!(v is Dictionary<string, object> dictionary)) { if (v is IEnumerable enumerable) { sb.Append('['); bool flag2 = true; foreach (object item in enumerable) { if (!flag2) { sb.Append(','); } flag2 = false; WriteValue(sb, item); } sb.Append(']'); } else { WriteString(sb, v.ToString()); } return; } sb.Append('{'); bool flag3 = true; foreach (KeyValuePair<string, object> item2 in dictionary) { if (!flag3) { sb.Append(','); } flag3 = false; WriteString(sb, item2.Key); sb.Append(':'); WriteValue(sb, item2.Value); } sb.Append('}'); } else { sb.Append(num4.ToString(CultureInfo.InvariantCulture)); } } else { sb.Append(num3.ToString(CultureInfo.InvariantCulture)); } } else { sb.Append(((double)num2).ToString("R", CultureInfo.InvariantCulture)); } } else { sb.Append(num.ToString("R", CultureInfo.InvariantCulture)); } } else { sb.Append(flag ? "true" : "false"); } } else { WriteString(sb, s); } } else { sb.Append("null"); } } private static void WriteString(StringBuilder sb, string s) { sb.Append('"'); foreach (char c in s) { switch (c) { case '"': sb.Append("\\\""); continue; case '\\': sb.Append("\\\\"); continue; case '\n': sb.Append("\\n"); continue; case '\r': sb.Append("\\r"); continue; case '\t': sb.Append("\\t"); continue; } if (c < ' ') { StringBuilder stringBuilder = sb.Append("\\u"); int num = c; stringBuilder.Append(num.ToString("x4")); } else { sb.Append(c); } } sb.Append('"'); } } internal sealed class WeaponEntry { public string Key; public string Name; public string Description; public WeaponTemplate Template; public string AmmoId; public int Capacity; public float Damage; public float Interval; public float Reload; public float Range; public float Spread; public int Pellets; public int Burst; public bool Automatic; public int Width; public int Height; public bool Starter; public int? Price; public bool Merchant; public int Sell; public float FindWeight; public string Model; public string Icon; public string FireSound; public string ReloadSound; public Vector3 GripOffset; public Vector3 GripEuler; public float GripScale = 1f; public Vector3? MuzzleOffset; public List<WeaponUpgradeStep> Upgrades = new List<WeaponUpgradeStep>(); public string ItemId => "re9gameplay:" + Key; } internal static class WeaponTable { public static List<WeaponEntry> Load(string path) { //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, object> o = MiniJson.Obj(MiniJson.Parse(File.ReadAllText(path))); List<WeaponEntry> list = new List<WeaponEntry>(); foreach (object item in MiniJson.GetArr(o, "weapons") ?? throw new FormatException("weapons.json has no \"weapons\" array")) { Dictionary<string, object> dictionary = MiniJson.Obj(item); if (dictionary != null && MiniJson.GetBool(dictionary, "enabled", fallback: true)) { WeaponEntry weaponEntry = new WeaponEntry(); weaponEntry.Key = MiniJson.GetString(dictionary, "key"); if (string.IsNullOrEmpty(weaponEntry.Key)) { throw new FormatException("A weapon has no \"key\""); } weaponEntry.Name = MiniJson.GetString(dictionary, "name", weaponEntry.Key); weaponEntry.Description = MiniJson.GetString(dictionary, "description", ""); string text = MiniJson.GetString(dictionary, "template", "Handgun"); if (!Enum.TryParse<WeaponTemplate>(text, ignoreCase: true, out weaponEntry.Template)) { throw new FormatException(weaponEntry.Key + ": unknown template \"" + text + "\""); } weaponEntry.AmmoId = MiniJson.GetString(dictionary, "ammo"); weaponEntry.Capacity = MiniJson.GetInt(dictionary, "capacity", 10); weaponEntry.Damage = MiniJson.GetFloat(dictionary, "damage", 28f); weaponEntry.Interval = MiniJson.GetFloat(dictionary, "interval", 0.47f); weaponEntry.Reload = MiniJson.GetFloat(dictionary, "reload", 1.5f); weaponEntry.Range = MiniJson.GetFloat(dictionary, "range", 65f); weaponEntry.Spread = MiniJson.GetFloat(dictionary, "spread", 0f); weaponEntry.Pellets = MiniJson.GetInt(dictionary, "pellets", 1); weaponEntry.Burst = MiniJson.GetInt(dictionary, "burst", 1); weaponEntry.Automatic = MiniJson.GetBool(dictionary, "automatic", fallback: false); weaponEntry.Width = MiniJson.GetInt(dictionary, "width", 3); weaponEntry.Height = MiniJson.GetInt(dictionary, "height", 2); weaponEntry.Starter = MiniJson.GetBool(dictionary, "starter", fallback: false); weaponEntry.Price = MiniJson.GetNullableInt(dictionary, "price"); weaponEntry.Merchant = MiniJson.GetBool(dictionary, "merchant", fallback: false); weaponEntry.Sell = MiniJson.GetInt(dictionary, "sell", 0); weaponEntry.FindWeight = MiniJson.GetFloat(dictionary, "findWeight", 0f); weaponEntry.Model = MiniJson.GetString(dictionary, "model", "models/" + weaponEntry.Key + ".glb"); weaponEntry.Icon = MiniJson.GetString(dictionary, "icon", "icons/" + weaponEntry.Key + ".png"); weaponEntry.FireSound = MiniJson.GetString(dictionary, "fireSound", "audio/" + weaponEntry.Key + "_fire.wav"); weaponEntry.ReloadSound = MiniJson.GetString(dictionary, "reloadSound", "audio/" + weaponEntry.Key + "_reload.wav"); Dictionary<string, object> obj = MiniJson.GetObj(dictionary, "grip"); weaponEntry.GripOffset = Vec(MiniJson.GetFloats(obj, "offset"), Vector3.zero); weaponEntry.GripEuler = Vec(MiniJson.GetFloats(obj, "euler"), Vector3.zero); weaponEntry.GripScale = MiniJson.GetFloat(obj, "scale", 1f); float[] floats = MiniJson.GetFloats(obj, "muzzle"); if (floats != null && floats.Length == 3) { weaponEntry.MuzzleOffset = new Vector3(floats[0], floats[1], floats[2]); } ReadUpgrades(weaponEntry, MiniJson.GetObj(dictionary, "upgrades")); list.Add(weaponEntry); } } return list; } private static void ReadUpgrades(WeaponEntry e, Dictionary<string, object> up) { if (up != null) { Add(e, (WeaponUpgrade)0, MiniJson.GetArr(up, "firepower")); Add(e, (WeaponUpgrade)1, MiniJson.GetArr(up, "firingSpeed")); Add(e, (WeaponUpgrade)2, MiniJson.GetArr(up, "reloadSpeed")); Add(e, (WeaponUpgrade)3, MiniJson.GetArr(up, "capacity")); } } private unsafe static void Add(WeaponEntry e, WeaponUpgrade stat, List<object> levels) { //IL_00a5: 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) //IL_00b3: Expected O, but got Unknown if (levels == null) { return; } int num = 0; foreach (object level in levels) { List<object> list = MiniJson.Arr(level); if (list != null && list.Count >= 2) { if (++num > 10) { Plugin.Log.LogWarning((object)(e.Key + ": more than 10 " + ((object)(*(WeaponUpgrade*)(&stat))/*cast due to .constrained prefix*/).ToString() + " levels; extra levels ignored")); break; } float num2 = ((list[0] is double num3) ? ((float)num3) : 0f); int num4 = MiniJson.AsInt(list[1], 0); e.Upgrades.Add(new WeaponUpgradeStep(stat, num2, num4)); } } } internal static Vector3 Vec(float[] a, Vector3 fallback) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (a == null || a.Length < 3) { return fallback; } return new Vector3(a[0], a[1], a[2]); } } } namespace RE9Gameplay.Character { internal static class FirstPersonBody { private static FieldInfo localVisualRoot; public static void Install(Harmony harmony) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown Type type = AccessTools.TypeByName("RE4Company.FirstPersonViewModel"); Type type2 = AccessTools.TypeByName("RE4Company.Avatars"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Context", new Type[1] { typeof(PlayerControllerB) }, (Type[])null) : null); localVisualRoot = ((type2 != null) ? AccessTools.Field(type2, "LocalVisualRoot") : null); if (methodInfo == null || localVisualRoot == null) { Plugin.Log.LogWarning((object)"RE4Gameplay's first-person view could not be found; RE9 suits may be invisible in first person."); } else { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(FirstPersonBody), "ContextPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static bool ContextPrefix(ref bool __result) { if (!Plugin.Cfg.FirstPersonBody.Value || !WearingOurs()) { return true; } __result = false; return false; } internal static bool WearingOurs() { try { object? value = localVisualRoot.GetValue(null); GameObject val = (GameObject)((value is GameObject) ? value : null); return (Object)(object)val != (Object)null && (Object)(object)val.GetComponent<LeonRig>() != (Object)null; } catch (Exception) { return false; } } } internal sealed class HandPoser { private sealed class Hand { public Transform Bone; public Quaternion BindLocal; public Vector3 F; public Vector3 N; public Vector3 S; public Vector3 Palm; public Transform[][] Fingers; public Transform[] Thumb; public readonly Dictionary<Transform, Quaternion> SegmentBind = new Dictionary<Transform, Quaternion>(); public bool Valid; } private static readonly Regex FingerName = new Regex("(?i)(index|middle|ring|pinky|little|thumb)\\D*([123])$"); private readonly Hand right; private readonly Hand left; public bool FixedWrists; private static readonly float[] Grip = new float[3] { 70f, 80f, 55f }; private static readonly float[] Trigger = new float[3] { 20f, 30f, 15f }; private static readonly float[] Support = new float[3] { 80f, 95f, 70f }; private static readonly float[] Fist = new float[3] { 80f, 90f, 65f }; private static readonly float[] Relaxed = new float[3] { 15f, 20f, 12f }; private static readonly float[] ThumbGrip = new float[3] { 20f, 25f, 20f }; private static readonly float[] ThumbRelaxed = new float[3] { 5f, 8f, 5f }; private static readonly float[] ThumbSupport = new float[3] { 30f, 35f, 25f }; private Vector3 gunForward; private Vector3 gunUp; private Vector3 gunPalm; private const float AimForward = 0.05f; private const float GripRight = 0.02f; private const float GripUp = 0.03f; private static MethodInfo muzzleLocal; private static bool muzzleResolved; private readonly Dictionary<Transform, Vector3> muzzles = new Dictionary<Transform, Vector3>(); private readonly Dictionary<Transform, bool> longGun = new Dictionary<Transform, bool>(); public HandPoser(Transform rightHand, Transform leftHand) { right = Build(rightHand, isRight: true); left = Build(leftHand, isRight: false); } private static Hand Build(Transform bone, bool isRight) { //IL_002a: 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_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: 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_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0254: 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_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_032f: 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_0346: 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_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) Hand h = new Hand { Bone = bone }; if ((Object)(object)bone == (Object)null) { return h; } h.BindLocal = bone.localRotation; Dictionary<string, SortedDictionary<int, Transform>> chains = new Dictionary<string, SortedDictionary<int, Transform>>(); Transform[] componentsInChildren = ((Component)bone).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { Match match = FingerName.Match(((Object)val).name); if (match.Success) { string text = match.Groups[1].Value.ToLowerInvariant(); if (text == "little") { text = "pinky"; } int key = match.Groups[2].Value[0] - 48; if (!chains.TryGetValue(text, out var value)) { value = (chains[text] = new SortedDictionary<int, Transform>()); } if (!value.ContainsKey(key)) { value[key] = val; } } } Transform[] array = Chain("index"); Transform[] array2 = Chain("middle"); Transform[] array3 = Chain("ring"); Transform[] array4 = Chain("pinky"); h.Thumb = Chain("thumb"); h.Fingers = new Transform[4][] { array, array2, array3, array4 }; Transform val2 = ((array2.Length != 0) ? array2[0] : ((array.Length != 0) ? array[0] : null)); Transform val3 = ((array.Length != 0) ? array[0] : null); Transform val4 = ((array4.Length != 0) ? array4[0] : ((array3.Length != 0) ? array3[0] : null)); if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null) { return h; } Vector3 val5 = bone.InverseTransformDirection(val2.position - bone.position); Vector3 normalized = ((Vector3)(ref val5)).normalized; Vector3 val6 = bone.InverseTransformDirection(val3.position - val4.position); val5 = Vector3.ProjectOnPlane(val6, normalized); val6 = ((Vector3)(ref val5)).normalized; if (((Vector3)(ref normalized)).sqrMagnitude < 0.5f || ((Vector3)(ref val6)).sqrMagnitude < 0.5f) { return h; } Vector3 val7 = (isRight ? Vector3.Cross