public static void SetEnvironment(HWSettings settings) { IntPtr myUsernamePointer = getenv("USERNAME"); string myUsername = Marshal.PtrToStringAnsi(myUsernamePointer); Utility.Util.CheckCreateDirectorys(settings.WindowsUserLogin); _putenv("COMPUTERNAME=" + settings.Computername.ToUpper()); _putenv("USERDOMAIN=" + settings.Computername.ToUpper()); _putenv("USERDOMAIN_ROAMINGPROFILE=" + settings.Computername.ToUpper()); _putenv("USERNAME="******"TMP=C:\Users\" + settings.WindowsUserLogin + @"\AppData\Local\Temp"); _putenv("VISUALSTUDIODIR="); if (settings.ProcessorIdent != null && settings.ProcessorIdent != null && settings.ProcessorCoreAmount != null && settings.ProcessorLevel != null) { _putenv("PROCESSOR_IDENTIFIER=" + settings.ProcessorIdent); _putenv("PROCESSOR_REVISION=" + settings.ProcessorRev); _putenv("NUMBER_OF_PROCESSORS=" + settings.ProcessorCoreAmount); _putenv("PROCESSOR_LEVEL=" + settings.ProcessorLevel); } _putenv(@"USERPROFILE=C:\Users\" + settings.WindowsUserLogin); _putenv(@"HOMEPATH=C:\Users\" + settings.WindowsUserLogin); _putenv(@"LOCALAPPDATA=C:\Users\" + settings.WindowsUserLogin + @"\AppData\Local"); _putenv(@"TEMP=C:\Users\" + settings.WindowsUserLogin + @"\AppData\Local\Temp"); _putenv(@"APPDATA=C:\Users\" + settings.WindowsUserLogin + @"\AppData\Roaming"); var pathPointer = getenv("PATH"); var path = Marshal.PtrToStringAnsi(pathPointer); path = path.Replace(myUsername, settings.WindowsUserLogin, StringComparison.InvariantCultureIgnoreCase); _putenv("PATH=" + path); }
public DX9Controller(HWSettings settings) { this._settings = settings; this.Name = typeof(DX9Controller).Name; IntPtr direct3D = Direct3DCreate9(32); try { if (direct3D == IntPtr.Zero){ MessageBox.Show("error"); throw new Exception("Failed to create D3D."); } IntPtr adapterIdentPtr = Marshal.ReadIntPtr(Marshal.ReadIntPtr(direct3D), 20); GetAdapterIdentifierOriginal = (GetAdapterIdentifierDelegate)Marshal.GetDelegateForFunctionPointer(adapterIdentPtr, typeof(GetAdapterIdentifierDelegate)); _name = string.Format("GetAdapterIdentHook_{0:X}", adapterIdentPtr.ToInt32()); _hook = LocalHook.Create(adapterIdentPtr, new GetAdapterIdentifierDelegate(GetAdapterIdentifierDetour), this); _hook.ThreadACL.SetExclusiveACL(new Int32[] { 1 }); } catch (Exception ex) { HookManager.Log("[DX9Controller] Exception: " + ex.ToString()); this.Error = true; } }