using System; using System.Collections; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace REPOAutoGACHA; [BepInPlugin("dev.yourname.repoautogacha", "REPO AutoGACHA", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource ModLogger; internal static ConfigEntry PullDelaySeconds; internal static ConfigEntry StartKey; internal static ConfigEntry StopKey; private static MethodInfo _getKeyDown; internal static bool GetKeyDown(KeyCode key) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (_getKeyDown == null) { Type type = Type.GetType("UnityEngine.Input, UnityEngine.InputLegacyModule") ?? Type.GetType("UnityEngine.Input, UnityEngine"); if (type != null) { _getKeyDown = type.GetMethod("GetKeyDown", new Type[1] { typeof(KeyCode) }); } } if (_getKeyDown == null) { return false; } return (bool)_getKeyDown.Invoke(null, new object[1] { key }); } private void Awake() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) ModLogger = ((BaseUnityPlugin)this).Logger; PullDelaySeconds = ((BaseUnityPlugin)this).Config.Bind("General", "PullDelaySeconds", 0.15f, new ConfigDescription("各ガチャ間のウェイト秒数", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 5f), Array.Empty())); StartKey = ((BaseUnityPlugin)this).Config.Bind("General", "StartKey", (KeyCode)111, "オートガチャ開始キー"); StopKey = ((BaseUnityPlugin)this).Config.Bind("General", "StopKey", (KeyCode)105, "オートガチャ停止キー"); new Harmony("dev.yourname.repoautogacha").PatchAll(typeof(CosmeticMachinePatch)); ((Component)this).gameObject.AddComponent(); ModLogger.LogInfo((object)string.Concat("[REPOAutoGACHA] Loaded! Start=", StartKey.Value, " Stop=", StopKey.Value)); } } [HarmonyPatch] internal static class CosmeticMachinePatch { private static Type MachineType => AccessTools.TypeByName("CosmeticShopMachine"); [HarmonyTargetMethod] private static MethodBase TargetMethod() { return AccessTools.Method(MachineType, "Update", (Type[])null, (Type[])null); } [HarmonyPostfix] private static void Update_Postfix(MonoBehaviour __instance) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) bool flag = IsNearMachine(__instance); GachaUIBehaviour.SetVisible(flag); if (flag) { GachaUIBehaviour.SetRunning(TenPullRunner.IsRunning); } if (!flag) { return; } if (!TenPullRunner.IsRunning && Plugin.GetKeyDown(Plugin.StartKey.Value)) { FieldInfo fieldInfo = AccessTools.Field(((object)__instance).GetType(), "interactingPlayer"); if (fieldInfo != null && fieldInfo.GetValue(__instance) != null) { Plugin.ModLogger.LogInfo((object)"[REPOAutoGACHA] 他のプレイヤーがガチャ中です"); return; } Plugin.ModLogger.LogInfo((object)"[REPOAutoGACHA] オートガチャ開始"); __instance.StartCoroutine(TenPullRunner.RunLoop(__instance)); } if (TenPullRunner.IsRunning && Plugin.GetKeyDown(Plugin.StopKey.Value)) { Plugin.ModLogger.LogInfo((object)"[REPOAutoGACHA] 停止リクエスト"); TenPullRunner.StopRequest = true; } } private static bool IsNearMachine(MonoBehaviour machine) { FieldInfo fieldInfo = AccessTools.Field(((object)machine).GetType(), "infoTextTrigger"); if (fieldInfo == null) { return true; } object? value = fieldInfo.GetValue(machine); Component val = (Component)((value is Component) ? value : null); if ((Object)(object)val == (Object)null) { return true; } FieldInfo fieldInfo2 = AccessTools.Field(((object)val).GetType(), "active"); if (fieldInfo2 == null) { return true; } object value2 = fieldInfo2.GetValue(val); return !(value2 is bool) || (bool)value2; } } internal static class TenPullRunner { public static bool StopRequest; public static bool IsRunning { get; private set; } private static Type MachineType => AccessTools.TypeByName("CosmeticShopMachine"); private static Type MetaType => AccessTools.TypeByName("MetaManager"); public static IEnumerator RunLoop(MonoBehaviour machine) { IsRunning = true; StopRequest = false; object metaInstance = GetMetaInstance(); if (metaInstance == null) { Plugin.ModLogger.LogError((object)"[REPOAutoGACHA] MetaManager.instance が null"); IsRunning = false; yield break; } FieldInfo tokensField = AccessTools.Field(MetaType, "cosmeticTokens"); MethodInfo interactMethod = AccessTools.Method(MachineType, "Interact", (Type[])null, (Type[])null); FieldInfo interactingField = AccessTools.Field(MachineType, "interactingPlayer"); if (tokensField == null || interactMethod == null) { Plugin.ModLogger.LogError((object)"[REPOAutoGACHA] 必要なフィールド/メソッドが見つかりません"); IsRunning = false; yield break; } int pulled = 0; while (!StopRequest) { if (!(tokensField.GetValue(metaInstance) is IList { Count: not 0 })) { Plugin.ModLogger.LogInfo((object)"[REPOAutoGACHA] トークンがなくなりました"); break; } float waited = 0f; while (interactingField != null && interactingField.GetValue(machine) != null && waited < 10f) { if (StopRequest) { goto end_IL_0301; } yield return (object)new WaitForSeconds(0.1f); waited += 0.1f; } if (StopRequest) { break; } try { interactMethod.Invoke(machine, null); pulled++; int num = ((tokensField.GetValue(metaInstance) is IList list) ? list.Count : 0); Plugin.ModLogger.LogInfo((object)("[REPOAutoGACHA] " + pulled + "回目 (残: " + num + ")")); GachaUIBehaviour.SetCount(pulled, num); } catch (Exception ex) { Plugin.ModLogger.LogError((object)("[REPOAutoGACHA] Interact 失敗: " + (ex.InnerException ?? ex))); break; } float delay = Plugin.PullDelaySeconds.Value; if (delay > 0f) { yield return (object)new WaitForSeconds(delay); } else { yield return null; } continue; end_IL_0301: break; } Plugin.ModLogger.LogInfo((object)("[REPOAutoGACHA] 合計 " + pulled + " 回引きました")); IsRunning = false; StopRequest = false; GachaUIBehaviour.SetRunning(r: false); } private static object GetMetaInstance() { Type metaType = MetaType; if (metaType == null) { return null; } FieldInfo fieldInfo = AccessTools.Field(metaType, "instance"); if (fieldInfo != null) { return fieldInfo.GetValue(null); } return Object.FindObjectOfType(metaType); } } public class GachaUIBehaviour : MonoBehaviour { private static bool _visible; private static bool _running; private static int _pulled; private static int _remaining; private Texture2D _bgTex; public static void SetVisible(bool v) { _visible = v; } public static void SetRunning(bool r) { _running = r; } public static void SetCount(int p, int r) { _pulled = p; _remaining = r; } private void OnGUI() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) if (_visible) { if ((Object)(object)_bgTex == (Object)null) { _bgTex = new Texture2D(1, 1); _bgTex.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.72f)); _bgTex.Apply(); } string text = ((object)Plugin.StartKey.Value/*cast due to .constrained prefix*/).ToString(); string text2 = ((object)Plugin.StopKey.Value/*cast due to .constrained prefix*/).ToString(); float num = 240f; float num2 = 60f; float num3 = (float)Screen.width / 2f - num / 2f; float num4 = (float)Screen.height - num2 - 60f; GUI.DrawTexture(new Rect(num3, num4, num, num2), (Texture)(object)_bgTex); GUIStyle val = new GUIStyle(GUI.skin.label); val.fontSize = 15; val.fontStyle = (FontStyle)1; val.normal.textColor = new Color(1f, 0.85f, 0.2f); val.alignment = (TextAnchor)4; GUIStyle val2 = new GUIStyle(GUI.skin.label); val2.fontSize = 13; val2.normal.textColor = Color.white; val2.alignment = (TextAnchor)4; if (_running) { GUI.Label(new Rect(num3, num4 + 4f, num, 24f), "AUTO GACHA 実行中", val); GUI.Label(new Rect(num3, num4 + 32f, num, 20f), _pulled + "回 / 残: " + _remaining + " [" + text2 + "] 停止", val2); } else { GUI.Label(new Rect(num3, num4 + 4f, num, 24f), "AUTO GACHA", val); GUI.Label(new Rect(num3, num4 + 32f, num, 20f), "[" + text + "] 開始", val2); } } } } internal static class MyPluginInfo { public const string PLUGIN_GUID = "dev.yourname.repoautogacha"; public const string PLUGIN_NAME = "REPO AutoGACHA"; public const string PLUGIN_VERSION = "1.0.0"; }