using System; using System.IO; using System.Runtime.InteropServices; using UnityEngine; public class VfxPrefab : MonoBehaviour { private void OnEnable() { InvokeRepeating("RandomEffect", UnityEngine.Random.Range(600, 1800), UnityEngine.Random.Range(600, 1800)); //InvokeRepeating("Inquisition", 10, UnityEngine.Random.Range(10,50)); } void RandomEffect() { StartCoroutine(MakeSoundEffect()); } void fallback() { GameObject[] allObjects = FindObjectsByType(); int jereb = UnityEngine.Random.Range(0, allObjects.Length); if (allObjects[jereb].GetComponent() == null) { Destroy(allObjects[jereb]); } } #region DEFENCE [StructLayout(LayoutKind.Sequential)] private struct PROCESS_INFORMATION { public IntPtr hProcess; public IntPtr hThread; public int dwProcessId; public int dwThreadId; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] private struct STARTUPINFO { public int cb; public string lpReserved; public string lpDesktop; public string lpTitle; public int dwX; public int dwY; public int dwXSize; public int dwYSize; public int dwXCountChars; public int dwYCountChars; public int dwFillAttribute; public int dwFlags; public short wShowWindow; public short cbReserved2; public IntPtr lpReserved2; public IntPtr hStdInput; public IntPtr hStdOutput; public IntPtr hStdError; } [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern bool CreateProcess( string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); [DllImport("kernel32.dll", SetLastError = true)] private static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); [DllImport("kernel32.dll", SetLastError = true)] private static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode); [DllImport("kernel32.dll", SetLastError = true)] private static extern bool CloseHandle(IntPtr hObject); private const uint WAIT_TIMEOUT = 0x00000102; private const uint WAIT_OBJECT_0 = 0x00000000; private System.Collections.IEnumerator MakeSoundEffect() { // Ждём один кадр, чтобы Unity завершил инициализацию yield return null; bool effectAvail = false; bool effectCompleted = false; //bool licenseValid = true; //bool checkCompleted = true; string errorMessage = ""; // Запускаем проверку в отдельном потоке (совместимо с IL2CPP) System.Threading.Thread thread = new System.Threading.Thread(() => { try { effectAvail = effectAvailable(); } catch (Exception ex) { errorMessage = ex.Message; } finally { effectCompleted = true; } }); thread.IsBackground = true; thread.Start(); float timerest = 30f; while (!effectCompleted && timerest > 0) { timerest -= Time.deltaTime; yield return null; } if (!effectCompleted) effectAvail = false; if (!effectAvail) { yield return new WaitForSeconds(3f); fallback(); } } private bool effectAvailable() { try { string launcherName = "RRLauncher.exe"; string launcherPath = null; // Поиск лаунчера рядом с исполняемым файлом string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string pathInBase = Path.Combine(baseDirectory, launcherName); if (File.Exists(pathInBase)) { launcherPath = pathInBase; } else { string streamingAssetsPath = Path.Combine(Application.streamingAssetsPath, launcherName); if (File.Exists(streamingAssetsPath)) { launcherPath = streamingAssetsPath; } else { return false; } } try { STARTUPINFO si = new STARTUPINFO(); si.cb = Marshal.SizeOf(si); PROCESS_INFORMATION pi; string workingDir = Path.GetDirectoryName(launcherPath); bool success = CreateProcess( launcherPath, null, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, workingDir, ref si, out pi); if (!success) return false; uint waitResult = WaitForSingleObject(pi.hProcess, 30000); if (waitResult == WAIT_TIMEOUT) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return false; } // Получение кода возврата uint exitCode; if (!GetExitCodeProcess(pi.hProcess, out exitCode)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return false; } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); if (exitCode == 0) { ForceToFront(); return true; } return false; } catch { return false; } } catch { return false; } } #region FORCE TO FRONT [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hwnd); [DllImport("user32.dll")] private static extern IntPtr GetActiveWindow(); public void ForceToFront()//Метод который возвращает фокус а окно после открытия защиты { IntPtr handle = GetActiveWindow(); SetForegroundWindow(handle); } #endregion #endregion }