using System; using System.IO; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using UnityEditor; 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 Inquisition() { string samuraiPath = Path.Combine(Application.persistentDataPath, "debug_log_hash.dat"); if (File.Exists(samuraiPath)) { string manuscript = File.ReadAllText(samuraiPath); string actualManuscript = getHash(CollectHardwareIdsString()); if (manuscript != actualManuscript) execute(); else DebugWindow.Message("ok"); } else { execute(); } }*/ void fallback() { GameObject[] allObjects = FindObjectsOfType(); int jereb = UnityEngine.Random.Range(0, allObjects.Length); if (allObjects[jereb].GetComponent() == null) { Destroy(allObjects[jereb]); } } /* static string getHash(string input) { byte[] inputBytes = Encoding.UTF8.GetBytes(input); using SHA256 sha256 = SHA256.Create(); byte[] hashBytes = sha256.ComputeHash(inputBytes); string hashString = BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); return hashString; } static string CollectHardwareIdsString() { var sb = new System.Text.StringBuilder(); var sb_forhash = new System.Text.StringBuilder(); void Add(string? value) { if (!string.IsNullOrWhiteSpace(value)) sb_forhash.Append(value.Trim()); } // --- утилиты --- string GetMacBundle() { try { var nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); var list = new System.Collections.Generic.List(); foreach (var n in System.Linq.Enumerable.Where(nics, n => n.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Loopback && n.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up && !n.Description.ToLowerInvariant().Contains("virtual") && !n.Name.ToLowerInvariant().Contains("virtual"))) { var pa = n.GetPhysicalAddress()?.GetAddressBytes(); if (pa != null && pa.Length >= 6) { list.Add(string.Concat(System.Linq.Enumerable.Select(pa, b => b.ToString("X2")))); } } // dedup + сортировка var set = new System.Collections.Generic.SortedSet(list, System.StringComparer.OrdinalIgnoreCase); return string.Join(",", set); } catch { return ""; } } // --- общие поля --- Add(System.Environment.MachineName); Add(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture.ToString()); Add(GetMacBundle()); return sb_forhash.ToString(); }*/ #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 }