using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using Il2CppSystem.Collections.Generic;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ReloadSync")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReloadSync")]
[assembly: AssemblyTitle("ReloadSync")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ReloadSync;
[BepInPlugin("local.reloadsync", "ReloadSync", "1.1.1")]
public class Plugin : BasePlugin
{
public const string GUID = "local.reloadsync";
internal static ManualLogSource L;
public override void Load()
{
L = ((BasePlugin)this).Log;
L.LogInfo((object)"[ReloadSync] v1.1.1 已载入。");
((BasePlugin)this).AddComponent<Applier>();
}
}
public class Applier : MonoBehaviour
{
private const float RETRY_SECONDS = 60f;
private float _t;
private float _waited;
private bool _done;
private void Update()
{
if (_done)
{
return;
}
_t += Time.deltaTime;
_waited += Time.deltaTime;
if (_t < 0.5f)
{
return;
}
_t = 0f;
try
{
if (GameDataBlockBase<GearFrontPartDataBlock>.IsLoaded() && GameDataBlockBase<GearStockPartDataBlock>.IsLoaded())
{
Apply();
_done = true;
}
}
catch (Exception ex)
{
if (_waited > 60f)
{
Plugin.L.LogError((object)("[ReloadSync] 放弃:" + ex.GetType().Name + " " + ex.Message));
_done = true;
}
}
}
private void Apply()
{
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
Target[] all = Tables.All;
foreach (Target target in all)
{
List<WeaponAnimSequenceItem> val = (target.IsStock ? GetStockSeq(target.Id) : GetFrontSeq(target.Id));
if (val == null)
{
num4++;
Plugin.L.LogWarning((object)("[ReloadSync] 找不到部件 id=" + target.Id + "(" + target.Name + "),跳过。"));
}
else if (Matches(val, target.New))
{
num2++;
}
else if (!Matches(val, target.Vanilla) && !Matches(val, target.Previous))
{
num3++;
Plugin.L.LogInfo((object)("[ReloadSync] id=" + target.Id + " " + target.Name + " 当前值与原版不一致(可能被其他 MOD 改过),跳过。"));
}
else
{
Write(target.IsStock, target.Id, target.New);
num++;
Plugin.L.LogInfo((object)("[ReloadSync] id=" + target.Id + " " + target.Name + " 已对齐 " + Describe(target.Vanilla) + " -> " + Describe(target.New)));
}
}
Plugin.L.LogInfo((object)("[ReloadSync] 完成:写入 " + num + ",已是对的 " + num2 + ",被别的 MOD 改过跳过 " + num3 + ",缺失 " + num4 + "。"));
}
private static List<WeaponAnimSequenceItem> GetFrontSeq(uint id)
{
GearFrontPartDataBlock block = GameDataBlockBase<GearFrontPartDataBlock>.GetBlock(id);
if (block != null)
{
return block.ReloadSequence;
}
return null;
}
private static List<WeaponAnimSequenceItem> GetStockSeq(uint id)
{
GearStockPartDataBlock block = GameDataBlockBase<GearStockPartDataBlock>.GetBlock(id);
if (block != null)
{
return block.ReloadSequence;
}
return null;
}
private static void Write(bool isStock, uint id, Ev[] events)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
List<WeaponAnimSequenceItem> val = new List<WeaponAnimSequenceItem>();
foreach (Ev ev in events)
{
WeaponAnimSequenceItem val2 = new WeaponAnimSequenceItem();
val2.TriggerTime = ev.T;
val2.Type = (eWeaponAnimSequenceItemType)ev.Type;
val2.StringData = ev.S;
val.Add(val2);
}
if (isStock)
{
GearStockPartDataBlock block = GameDataBlockBase<GearStockPartDataBlock>.GetBlock(id);
if (block != null)
{
block.ReloadSequence = val;
}
}
else
{
GearFrontPartDataBlock block2 = GameDataBlockBase<GearFrontPartDataBlock>.GetBlock(id);
if (block2 != null)
{
block2.ReloadSequence = val;
}
}
}
private static bool Matches(List<WeaponAnimSequenceItem> list, Ev[] events)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Invalid comparison between Unknown and I4
if (events == null)
{
return false;
}
if (list == null || list.Count != events.Length)
{
return false;
}
for (int i = 0; i < events.Length; i++)
{
WeaponAnimSequenceItem val = list[i];
if (val == null)
{
return false;
}
if (Math.Abs(val.TriggerTime - events[i].T) > 0.0005f)
{
return false;
}
if ((int)val.Type != events[i].Type)
{
return false;
}
if ((val.StringData ?? "") != (events[i].S ?? ""))
{
return false;
}
}
return true;
}
private static string Describe(Ev[] events)
{
float num = 0f;
float num2 = -1f;
foreach (Ev ev in events)
{
if (ev.T > num)
{
num = ev.T;
}
if (ev.Type == 6 && num2 < 0f)
{
num2 = ev.T;
}
}
StringBuilder stringBuilder = new StringBuilder(48);
stringBuilder.Append("结束=").Append(num.ToString("0.###"));
stringBuilder.Append(" 补弹=").Append((num2 < 0f) ? "无" : num2.ToString("0.###"));
stringBuilder.Append(" 事件=").Append(events.Length);
return stringBuilder.ToString();
}
}
internal sealed class Ev
{
public readonly float T;
public readonly int Type;
public readonly string S;
public Ev(float t, int type, string s)
{
T = t;
Type = type;
S = s;
}
}
internal sealed class Target
{
public readonly bool IsStock;
public readonly uint Id;
public readonly string Name;
public readonly Ev[] New;
public readonly Ev[] Vanilla;
public readonly Ev[] Previous;
public Target(bool isStock, uint id, string name, Ev[] fresh, Ev[] vanilla, Ev[] previous)
{
IsStock = isStock;
Id = id;
Name = name;
New = fresh;
Vanilla = vanilla;
Previous = previous;
}
}
internal static class Tables
{
public static readonly Target[] All = new Target[8]
{
new Target(isStock: false, 14u, "Front_Rifle_3", new Ev[9]
{
new Ev(0f, 0, "Front_Rifle_3_reload_animation"),
new Ev(0f, 1, "Front_Rifle_Reload"),
new Ev(0f, 2, "Front_Rifle_3_reload_animation"),
new Ev(0f, 9, "Front_Rifle_3_reload_animation"),
new Ev(0f, 5, "CARBINE_RELOAD_3_FOLEY"),
new Ev(0.1f, 5, "CARBINE_RELOAD_1_MAG_OUT"),
new Ev(0.8f, 5, "CARBINE_RELOAD_2_MAG_IN"),
new Ev(0.85f, 6, null),
new Ev(1.184f, 7, null)
}, new Ev[10]
{
new Ev(0f, 0, "Front_Rifle_3_reload_animation"),
new Ev(0f, 1, "Front_Rifle_Reload"),
new Ev(0f, 2, "Front_Rifle_3_reload_animation"),
new Ev(0f, 5, "CARBINE_RELOAD_3_FOLEY"),
new Ev(0.1f, 5, "CARBINE_RELOAD_1_MAG_OUT"),
new Ev(0.7f, 10, "drop"),
new Ev(1f, 10, "show"),
new Ev(1.66f, 5, "CARBINE_RELOAD_2_MAG_IN"),
new Ev(2f, 6, null),
new Ev(2.7f, 7, null)
}, null),
new Target(isStock: false, 20u, "Front_Shotgun_3", new Ev[14]
{
new Ev(0f, 0, "Front_Shotgun_3_animation_reload"),
new Ev(0f, 1, "Front_Rifle_Reload"),
new Ev(0f, 2, "Front_Shotgun_3_reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.2f, 5, "generic_reload_pat_soft"),
new Ev(0.3f, 5, "generic_reload_foley_subtle"),
new Ev(0.7f, 5, "generic_reload_foley_quick"),
new Ev(1f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.2f, 5, "pistol_reload_3_grab_mag"),
new Ev(1.5f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.6f, 6, null),
new Ev(1.8f, 5, "cannon_reload_foley_move"),
new Ev(2.15f, 5, "generic_reload_pat_soft"),
new Ev(2.88f, 7, null)
}, new Ev[14]
{
new Ev(0f, 0, "Front_Shotgun_3_animation_reload"),
new Ev(0f, 1, "Front_Rifle_Reload"),
new Ev(0f, 2, "Front_Shotgun_3_reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.2f, 5, "generic_reload_pat_soft"),
new Ev(0.3f, 5, "generic_reload_foley_subtle"),
new Ev(0.7f, 5, "generic_reload_foley_quick"),
new Ev(1f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.2f, 5, "pistol_reload_3_grab_mag"),
new Ev(1.5f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.8f, 5, "cannon_reload_foley_move"),
new Ev(2f, 6, null),
new Ev(2.15f, 5, "generic_reload_pat_soft"),
new Ev(2.88f, 7, null)
}, null),
new Target(isStock: false, 21u, "Front_Precision_1", new Ev[16]
{
new Ev(0f, 0, "Front_Precision_1_reload"),
new Ev(0f, 1, "Front_Precision_1_reload"),
new Ev(0f, 2, "Front_Precision_1_reload"),
new Ev(0f, 5, "generic_reload_foley_subtle"),
new Ev(0.2f, 5, "cannon_reload_foley_move"),
new Ev(0.52f, 10, "drop"),
new Ev(0.6f, 5, "cannon_reload_mag_out"),
new Ev(0.75f, 5, "generic_reload_foley_quick_soft"),
new Ev(0.8f, 10, "show"),
new Ev(1.04f, 5, "generic_reload_foley_quick"),
new Ev(1.7f, 5, "carbine_mag_bump"),
new Ev(2f, 5, "cannon_reload_mag_in"),
new Ev(2f, 6, null),
new Ev(2.2f, 5, "cannon_reload_foley_move"),
new Ev(2.6f, 5, "generic_reload_grab_heavy_weapon"),
new Ev(2.9f, 7, null)
}, new Ev[16]
{
new Ev(0f, 0, "Front_Precision_1_reload"),
new Ev(0f, 1, "Front_Precision_1_reload"),
new Ev(0f, 2, "Front_Precision_1_reload"),
new Ev(0f, 5, "generic_reload_foley_subtle"),
new Ev(0.2f, 5, "cannon_reload_foley_move"),
new Ev(0.52f, 10, "drop"),
new Ev(0.6f, 5, "cannon_reload_mag_out"),
new Ev(0.75f, 5, "generic_reload_foley_quick_soft"),
new Ev(0.8f, 10, "show"),
new Ev(1.04f, 5, "generic_reload_foley_quick"),
new Ev(1.95f, 5, "carbine_mag_bump"),
new Ev(2.4f, 5, "cannon_reload_mag_in"),
new Ev(2.4f, 6, null),
new Ev(2.6f, 5, "cannon_reload_foley_move"),
new Ev(2.7f, 5, "generic_reload_grab_heavy_weapon"),
new Ev(2.9f, 7, null)
}, null),
new Target(isStock: false, 24u, "Front_SMG_1", new Ev[13]
{
new Ev(0f, 0, "SMG_Front_1_Reload"),
new Ev(0f, 1, "SMG_Front_1_Reload"),
new Ev(0f, 2, "SMG_Front_1_Reload"),
new Ev(0f, 9, "SMG_Front_1_Reload"),
new Ev(0.2f, 5, "carbine_reload_4_pat_mag"),
new Ev(0.3f, 5, "carbine_reload_1_mag_out"),
new Ev(0.4f, 10, "drop"),
new Ev(0.7f, 5, "carbine_reload_3_foley"),
new Ev(0.8f, 5, "carbine_reload_3_grab_mag "),
new Ev(0.8f, 10, "show"),
new Ev(0.85f, 6, null),
new Ev(1.3f, 5, "carbine_reload_2_mag_in"),
new Ev(1.9f, 5, "carbine_reload_4_pat_mag")
}, new Ev[13]
{
new Ev(0f, 0, "SMG_Front_1_Reload"),
new Ev(0f, 1, "SMG_Front_1_Reload"),
new Ev(0f, 2, "SMG_Front_1_Reload"),
new Ev(0f, 9, "SMG_Front_1_Reload"),
new Ev(0.2f, 5, "carbine_reload_4_pat_mag"),
new Ev(0.3f, 5, "carbine_reload_1_mag_out"),
new Ev(0.4f, 10, "drop"),
new Ev(0.7f, 5, "carbine_reload_3_foley"),
new Ev(1.1f, 6, null),
new Ev(1.1f, 5, "carbine_reload_3_grab_mag "),
new Ev(1.2f, 10, "show"),
new Ev(1.4f, 5, "carbine_reload_2_mag_in"),
new Ev(1.9f, 5, "carbine_reload_4_pat_mag")
}, null),
new Target(isStock: false, 35u, "Front_Revolver_2", new Ev[23]
{
new Ev(0f, 0, "Stock_Revolver_2_Reload"),
new Ev(0f, 1, "Front_Revolver_2_Reload"),
new Ev(0f, 2, "Front_Revolver_2_Reload"),
new Ev(0f, 4, "Front_Revolver_2_Reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.25f, 5, "revolver_open"),
new Ev(0.26f, 5, "carbine_reload_5_pull_slide"),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.4f, 5, "revolver_reload_grab_mag"),
new Ev(0.75f, 5, "revolver_reload_foley"),
new Ev(0.85f, 6, null),
new Ev(1.1f, 5, "revolver_mag_in"),
new Ev(1.4f, 5, "generic_reload_foley_subtle"),
new Ev(1.6f, 5, "revolver_close"),
new Ev(1.9f, 5, "generic_reload_foley_subtle"),
new Ev(2f, 7, null),
new Ev(2.3f, 5, "revolver_reload_foley"),
new Ev(2.5f, 5, "generic_reload_foley_subtle")
}, new Ev[23]
{
new Ev(0f, 0, "Stock_Revolver_2_Reload"),
new Ev(0f, 1, "Front_Revolver_2_Reload"),
new Ev(0f, 2, "Front_Revolver_2_Reload"),
new Ev(0f, 4, "Front_Revolver_2_Reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.25f, 5, "revolver_open"),
new Ev(0.26f, 5, "carbine_reload_5_pull_slide"),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.36f, 11, null),
new Ev(0.4f, 5, "revolver_reload_grab_mag"),
new Ev(0.75f, 5, "revolver_reload_foley"),
new Ev(1.1f, 6, null),
new Ev(1.2f, 5, "revolver_mag_in"),
new Ev(1.5f, 5, "generic_reload_foley_subtle"),
new Ev(1.65f, 5, "revolver_close"),
new Ev(1.9f, 5, "generic_reload_foley_subtle"),
new Ev(2.3f, 5, "revolver_reload_foley"),
new Ev(2.5f, 5, "generic_reload_foley_subtle"),
new Ev(2f, 7, null)
}, null),
new Target(isStock: false, 37u, "Front_Short_Shotgun_1", new Ev[16]
{
new Ev(0f, 0, "Short_Shotgun_2_Weapon_Reload"),
new Ev(0f, 1, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 4, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 8, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 2, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 9, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 5, "carbine_reload_3_foley"),
new Ev(0.2f, 5, "shotgun_reload_break_open"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(1.25f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.5f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.6f, 5, "generic_reload_foley_quick"),
new Ev(1.7f, 5, "shotgun_reload_break_close"),
new Ev(2f, 6, null),
new Ev(2.25f, 5, "generic_reload_grab_heavy_weapon"),
new Ev(2.5f, 7, null)
}, new Ev[6]
{
new Ev(0f, 0, "ShotgunReload_bump"),
new Ev(0f, 5, "carbine_reload_3_foley"),
new Ev(0.95f, 5, "shotgun_reload_1_shell_in"),
new Ev(1f, 6, null),
new Ev(1.5f, 5, "shotgun_reload_2_cock"),
new Ev(2f, 7, null)
}, null),
new Target(isStock: false, 47u, "Front_Short_Shotgun_2", new Ev[16]
{
new Ev(0f, 0, "Short_Shotgun_2_Weapon_Reload"),
new Ev(0f, 1, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 4, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 8, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 2, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 9, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 5, "carbine_reload_3_foley"),
new Ev(0.2f, 5, "shotgun_reload_break_open"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(1.25f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.5f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.6f, 5, "generic_reload_foley_quick"),
new Ev(1.7f, 5, "shotgun_reload_break_close"),
new Ev(2f, 6, null),
new Ev(2.25f, 5, "generic_reload_grab_heavy_weapon"),
new Ev(2.5f, 7, null)
}, new Ev[16]
{
new Ev(0f, 0, "Short_Shotgun_2_Weapon_Reload"),
new Ev(0f, 1, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 4, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 8, "Short_Shotgun_2_Parts_Reload"),
new Ev(0f, 2, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 9, "Short_Shotgun_2_Player_Reload"),
new Ev(0f, 5, "carbine_reload_3_foley"),
new Ev(0.2f, 5, "shotgun_reload_break_open"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(1.25f, 5, "shotgun_reload_1_shell_in"),
new Ev(1.5f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.7f, 5, "generic_reload_foley_quick"),
new Ev(2f, 5, "shotgun_reload_break_close"),
new Ev(2.25f, 5, "generic_reload_grab_heavy_weapon"),
new Ev(2f, 6, null),
new Ev(2.5f, 7, null)
}, null),
new Target(isStock: true, 17u, "Stock_Bullpop_1", new Ev[17]
{
new Ev(0f, 0, "Stock_Bullpup_1_reload"),
new Ev(0f, 8, "Stock_Bullpup_1_reload"),
new Ev(0f, 2, "Stock_Bullpup_1_reload"),
new Ev(0f, 9, "Stock_Bullpup_1_reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.3f, 5, "generic_reload_pat_soft"),
new Ev(0.4f, 5, "bullpup_reload_mag_out"),
new Ev(0.65f, 10, "drop"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(0.9f, 10, "show"),
new Ev(1.15f, 6, ""),
new Ev(1.15f, 5, "bullpup_reload_mag_in"),
new Ev(1.3f, 5, "generic_reload_foley_subtle"),
new Ev(1.6f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.9f, 5, "generic_reload_grab_heavy_weapon_soft"),
new Ev(2f, 7, null),
new Ev(2.1f, 7, "")
}, new Ev[17]
{
new Ev(0f, 0, "Stock_Bullpup_1_reload"),
new Ev(0f, 8, "Stock_Bullpup_1_reload"),
new Ev(0f, 2, "Stock_Bullpup_1_reload"),
new Ev(0f, 9, "Stock_Bullpup_1_reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.3f, 5, "generic_reload_pat_soft"),
new Ev(0.4f, 5, "bullpup_reload_mag_out"),
new Ev(0.65f, 10, "drop"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(0.9f, 10, "show"),
new Ev(1.15f, 5, "bullpup_reload_mag_in"),
new Ev(1.3f, 5, "generic_reload_foley_subtle"),
new Ev(1.6f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.9f, 5, "generic_reload_grab_heavy_weapon_soft"),
new Ev(2.1f, 7, ""),
new Ev(1f, 6, ""),
new Ev(2f, 7, null)
}, new Ev[17]
{
new Ev(0f, 0, "Stock_Bullpup_1_reload"),
new Ev(0f, 8, "Stock_Bullpup_1_reload"),
new Ev(0f, 2, "Stock_Bullpup_1_reload"),
new Ev(0f, 9, "Stock_Bullpup_1_reload"),
new Ev(0f, 5, "generic_reload_foley_quick"),
new Ev(0.3f, 5, "generic_reload_pat_soft"),
new Ev(0.4f, 5, "bullpup_reload_mag_out"),
new Ev(0.65f, 10, "drop"),
new Ev(0.8f, 5, "smg_reload_3_grab_mag"),
new Ev(0.9f, 10, "show"),
new Ev(1f, 6, ""),
new Ev(1.15f, 5, "bullpup_reload_mag_in"),
new Ev(1.3f, 5, "generic_reload_foley_subtle"),
new Ev(1.6f, 5, "generic_reload_foley_quick_soft"),
new Ev(1.9f, 5, "generic_reload_grab_heavy_weapon_soft"),
new Ev(2f, 7, null),
new Ev(2.1f, 7, "")
})
};
}