Compare commits

...

48 Commits

Author SHA1 Message Date
Orbmu2k
ce1f79fd76 removed hotkey 2019-02-23 15:19:22 +01:00
Orbmu2k
d5f993b63a added opengl sli bits to custom settings 2019-02-22 23:10:30 +01:00
Orbmu2k
6e0c64bf42 import/export of all setting types 2019-02-22 22:50:08 +01:00
Orbmu2k
1f1841cb9f new custom settings, updated driver settings to R410 2019-02-22 20:59:03 +01:00
Orbmu2k
ef00e39885 hotkey 2018-03-18 13:35:04 +01:00
Orbmu2k
972174acbf set new NO_ALIGN flag for FPS limiter 2017-08-21 19:25:42 +02:00
Orbmu2k
db44bff36d updated driver constants to R384 2017-08-21 19:24:56 +02:00
Orbmu2k
b90649ee5c present byte values with length 8 as QWORD 2017-08-21 19:24:12 +02:00
Orbmu2k
c81f0f32f3 fixes for binary values 2017-07-01 01:32:46 +02:00
Orbmu2k
51b8d44bc2 preliminary support for binary values 2017-07-01 00:54:34 +02:00
Orbmu2k
374ce1ea87 added tons of settings from the pullrequest by killer-m as Reference.xml (visible only if set in a profile or activated show all settings option) 2017-05-21 22:45:50 +02:00
Orbmu2k
0f6a0f5fef added two common settings from pull request by killer-m 2017-05-21 22:40:01 +02:00
Orbmu2k
226ef295ab driver constants R381 and FPS Limiter changes 2017-05-21 22:07:46 +02:00
Orbmu2k
c207f45a2d direct steam appId without string pattern 2017-05-08 19:30:08 +02:00
Orbmu2k
27af02b9ce FPS Limiter Changes in CSN 2017-05-08 19:29:14 +02:00
Orbmu2k
baf4a30a4b suggest profilename as filename for export current profile 2017-01-18 19:53:43 +01:00
Orbmu2k
ee42348cbb added SteamAppResolver 2017-01-11 10:56:27 +01:00
Orbmu2k
58a52d2656 reduced default window size to avoid layout problems 2016-10-30 17:16:45 +01:00
Orbmu2k
abeb84543e set dpiAware for high DPI setups 2016-10-29 17:57:36 +02:00
Orbmu2k
7248f29fdb updated frame limiter values to the fixed frame limter of 370.95 2016-09-27 20:57:24 +02:00
Orbmu2k
e1ebccc82f RELEASE 2.1.3.0 2016-09-23 22:59:46 +02:00
Orbmu2k
4aeb5eb096 added 'export current profile including predefined settings' 2016-09-08 21:58:15 +02:00
Orbmu2k
1426b82669 fixed empty profile export if no setting is set but only application 2016-09-08 21:31:24 +02:00
Orbmu2k
5d9e39b63d fix for empty nvd3dumx settingids crash 2016-08-04 22:23:47 +02:00
Orbmu2k
0807f4b635 updated setting constants to R367 2016-08-04 15:47:27 +02:00
Orbmu2k
0f6a23ef70 fix for crash if nvd3dumx.dll is missing 2016-08-04 15:45:29 +02:00
Orbmu2k
46c80189c1 Merge pull request #9 from DarkStarSword/master
Make StereoMemoEnabled show up as enabled by default
2016-07-21 12:14:51 +02:00
Ian Munsie
a49416ae73 Make StereoMemoEnabled show up as enabled by default
When 3D Vision is enabled, the driver defaults to displaying the stereo
memo, so mark that as the default in CustomSettingNames.xml
2016-07-19 17:54:06 +10:00
Orbmu2k
358c800e20 Merge pull request #8 from DarkStarSword/master
CustomSettingNames.xml: Add StereoProfile and presets for important s…
2016-07-17 11:51:58 +02:00
Ian Munsie
d6bd204665 CustomSettingNames.xml: Add StereoProfile and presets for important stereo settings
This adds:

- StereoProfile, which is required to be set in a profile for various
  other stereo settings to be processed at all. It also is required to
  allow changes to be saved to the profile with Ctrl+F7 (if it is
  missing, attempting to save a profile will reload the settings from
  the profile instead, though notably if no profile exists at all a new
  one will be created containing this setting). It's presence also
  allows stereo to activate in a windowed mode DX9 application.

  Note that there are some observable differences between it being set
  to 0, and entirely missing from a profile (e.g. DX9 windowed mode
  stereo will still engage if this is present but set to 0).

- StereoConvergence, which saves the familiar convergence setting in a
  profile. This can be an arbitrary floating point number and is usually
  adjusted by the user via Ctrl+F5/F6 and saved with Ctrl+F7. A range of
  presets within various suitable ranges are provided, but this varies
  greatly between games (e.g. Unity games typically need around 0.5,
  while UE3 games typically need somewhere between 10-50, and some
  games/engines vary even more wildly).

- LaserXAdjust and LaserYAdjust, which allow the stereo laser sight
  to be repositioned for games that use an off-center crosshair. These
  settings are not exposed anywhere else.

- StereoTextureEnable, which is the primary setting that controls the
  driver heuristics to stereoise render targets and determine when to
  apply the stereo correction formula. This includes a number of bit
  definitions provided by NVIDIA.

- StereoCutoff, StereoCutoffDepthNear and StereoCutoffDepthFar which are
  useful in certain games to pin the HUD to screen depth.

- StereoMemoEnabled, which indicates whether the green informational
  text is displayed. This is most useful to be set to 0 on the base
  profile so that all profiles will inherit it by default.

- StereoFlagsDX10, which (presumanly among other things) controls
  whether the driver will run compute shaders once or twice, and is
  required in many modern DX11 games that use compute shaders as part of
  their rendering pipelines. This includes two bit definitions provided
  by NVIDIA.

- StereoUseMatrix, which is known to be able to automatically correct
  many "halo" type rendering issues in many games, though not
  necessarily as reliably (i.e. may flicker) as performing an equivalent
  fix via my shader scripts. These issues are a result of a vertex
  shader passing a copy of the calculated screen position to a pixel
  shader in a texcoord output.
2016-07-17 12:49:41 +10:00
Orbmu2k
4b3a74a3ba Some fixes for setting decryption 2016-07-15 22:43:26 +02:00
Orbmu2k
33bba3484b added DrsDecrypterService for settings flagged as internal 2016-07-14 23:07:55 +02:00
Orbmu2k
98eac09061 added FastSync to CustomSettingNames 2016-07-14 23:07:50 +02:00
Orbmu2k
60ee8949a6 improved import error handling 2016-05-24 01:28:46 +02:00
Orbmu2k
ca7d1a49b2 fixed value have not been added if a scanned value already existed 2016-05-05 00:03:07 +02:00
Orbmu2k
6451887245 fixed notification for already assigned application 2016-05-03 11:22:37 +02:00
Orbmu2k
ceddbf3878 prevent global exception handling in debug build 2016-05-03 11:21:30 +02:00
Orbmu2k
a6ca8d4ce2 fixed predefined setting scanner to use the predefined setting instead of current setttng 2016-05-03 10:59:22 +02:00
Orbmu2k
093deb3982 show nvidia icon for predefined profiles in modified profile list 2016-04-12 10:44:04 +02:00
Orbmu2k
220db7e9da added frame rate limiter v2 values 2016-04-11 00:42:57 +02:00
Orbmu2k
f4d9443012 added CLI param "-silentImport" 2016-04-10 23:20:33 +02:00
Orbmu2k
69b588d47c fixed scanned settings not to merge 2016-04-10 23:05:54 +02:00
Orbmu2k
865fb95735 added viewmode dependency for values 2016-04-10 22:51:22 +02:00
Orbmu2k
56f20f2777 updated constant settings to R361-v2 2016-04-03 10:15:02 +02:00
Orbmu2k
228e7aeafb added OpenGL version override to CSN 2016-04-03 09:40:38 +02:00
Orbmu2k
0f9f8bd440 fixed CLI param "-showOnlyCSN" not working 2016-04-03 09:14:06 +02:00
Orbmu2k
9fb029db52 show all NvD3dUmxSettings and ReferenceSettings in scanned settings view mode 2016-04-03 09:13:16 +02:00
Orbmu2k
935d46ea13 RELEASE 2.1.2.0 2016-03-30 22:42:44 +02:00
36 changed files with 8138 additions and 2135 deletions

View File

@@ -3,17 +3,9 @@ using System.Text;
namespace nspector.Common
{
internal class CachedSettingValue : IComparable<CachedSettingValue>
internal class CachedSettingValue
{
public int CompareTo(CachedSettingValue other)
{
if (IsStringValue)
return ValueStr.CompareTo(other.ValueStr);
else
return Value.CompareTo(other.Value);
}
internal CachedSettingValue() { }
internal CachedSettingValue(uint Value, string ProfileNames)
@@ -25,15 +17,21 @@ namespace nspector.Common
internal CachedSettingValue(string ValueStr, string ProfileNames)
{
IsStringValue = true;
this.ValueStr = ValueStr;
this.ProfileNames = new StringBuilder(ProfileNames);
this.ValueProfileCount = 1;
}
internal readonly bool IsStringValue = false;
internal CachedSettingValue(byte[] ValueBin, string ProfileNames)
{
this.ValueBin = ValueBin;
this.ProfileNames = new StringBuilder(ProfileNames);
this.ValueProfileCount = 1;
}
internal string ValueStr = "";
internal uint Value = 0;
internal byte[] ValueBin = new byte[0];
internal StringBuilder ProfileNames;
internal uint ValueProfileCount;
}

View File

@@ -52,5 +52,21 @@ namespace nspector.Common
}
ProfileCount++;
}
internal void AddBinaryValue(byte[] valueBin, string Profile)
{
var setting = SettingValues.FirstOrDefault(s => s.ValueBin.SequenceEqual(valueBin));
if (setting == null)
{
SettingValues.Add(new CachedSettingValue(valueBin, Profile));
}
else
{
setting.ProfileNames.Append(", " + Profile);
setting.ValueProfileCount++;
}
ProfileCount++;
}
}
}

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using nspector.Native.NVAPI2;
namespace nspector.Common
{
internal class DrsDecrypterService : DrsSettingsServiceBase
{
private static readonly byte[] _InternalSettingsKey = new byte[] {
0x2f, 0x7c, 0x4f, 0x8b, 0x20, 0x24, 0x52, 0x8d, 0x26, 0x3c, 0x94, 0x77, 0xf3, 0x7c, 0x98, 0xa5,
0xfa, 0x71, 0xb6, 0x80, 0xdd, 0x35, 0x84, 0xba, 0xfd, 0xb6, 0xa6, 0x1b, 0x39, 0xc4, 0xcc, 0xb0,
0x7e, 0x95, 0xd9, 0xee, 0x18, 0x4b, 0x9c, 0xf5, 0x2d, 0x4e, 0xd0, 0xc1, 0x55, 0x17, 0xdf, 0x18,
0x1e, 0x0b, 0x18, 0x8b, 0x88, 0x58, 0x86, 0x5a, 0x1e, 0x03, 0xed, 0x56, 0xfb, 0x16, 0xfe, 0x8a,
0x01, 0x32, 0x9c, 0x8d, 0xf2, 0xe8, 0x4a, 0xe6, 0x90, 0x8e, 0x15, 0x68, 0xe8, 0x2d, 0xf4, 0x40,
0x37, 0x9a, 0x72, 0xc7, 0x02, 0x0c, 0xd1, 0xd3, 0x58, 0xea, 0x62, 0xd1, 0x98, 0x36, 0x2b, 0xb2,
0x16, 0xd5, 0xde, 0x93, 0xf1, 0xba, 0x74, 0xe3, 0x32, 0xc4, 0x9f, 0xf6, 0x12, 0xfe, 0x18, 0xc0,
0xbb, 0x35, 0x79, 0x9c, 0x6b, 0x7a, 0x23, 0x7f, 0x2b, 0x15, 0x9b, 0x42, 0x07, 0x1a, 0xff, 0x69,
0xfb, 0x9c, 0xbd, 0x23, 0x97, 0xa8, 0x22, 0x63, 0x8f, 0x32, 0xc8, 0xe9, 0x9b, 0x63, 0x1c, 0xee,
0x2c, 0xd9, 0xed, 0x8d, 0x3a, 0x35, 0x9c, 0xb1, 0x60, 0xae, 0x5e, 0xf5, 0x97, 0x6b, 0x9f, 0x20,
0x8c, 0xf7, 0x98, 0x2c, 0x43, 0x79, 0x95, 0x1d, 0xcd, 0x46, 0x36, 0x6c, 0xd9, 0x67, 0x20, 0xab,
0x41, 0x22, 0x21, 0xe5, 0x55, 0x82, 0xf5, 0x27, 0x20, 0xf5, 0x08, 0x07, 0x3f, 0x6d, 0x69, 0xd9,
0x1c, 0x4b, 0xf8, 0x26, 0x03, 0x6e, 0xb2, 0x3f, 0x1e, 0xe6, 0xca, 0x3d, 0x61, 0x44, 0xb0, 0x92,
0xaf, 0xf0, 0x88, 0xca, 0xe0, 0x5f, 0x5d, 0xf4, 0xdf, 0xc6, 0x4c, 0xa4, 0xe0, 0xca, 0xb0, 0x20,
0x5d, 0xc0, 0xfa, 0xdd, 0x9a, 0x34, 0x8f, 0x50, 0x79, 0x5a, 0x5f, 0x7c, 0x19, 0x9e, 0x40, 0x70,
0x71, 0xb5, 0x45, 0x19, 0xb8, 0x53, 0xfc, 0xdf, 0x24, 0xbe, 0x22, 0x1c, 0x79, 0xbf, 0x42, 0x89 };
public DrsDecrypterService(DrsSettingsMetaService metaService) : base(metaService)
{
CreateInternalSettingMap();
}
private uint GetDwordFromKey(uint offset)
{
var bytes = new byte[4];
bytes[0] = _InternalSettingsKey[(offset + 0) % 256];
bytes[1] = _InternalSettingsKey[(offset + 1) % 256];
bytes[2] = _InternalSettingsKey[(offset + 2) % 256];
bytes[3] = _InternalSettingsKey[(offset + 3) % 256];
return BitConverter.ToUInt32(bytes, 0);
}
public uint DecryptDwordValue(uint orgValue, uint settingId)
{
var keyOffset = (settingId << 1);
var key = GetDwordFromKey(keyOffset);
return orgValue ^ key;
}
public string DecryptStringValue(byte[] rawData, uint settingId)
{
var keyOffset = (settingId << 1);
for (uint i = 0; i < (uint)rawData.Length; i++)
{
rawData[i] ^= _InternalSettingsKey[(keyOffset + i) % 256];
}
return Encoding.Unicode.GetString(rawData).Trim('\0');
}
public void DecryptSettingIfNeeded(string profileName, ref NVDRS_SETTING setting)
{
if (setting.isPredefinedValid == 1)
{
if (IsInternalSetting(profileName, setting.settingId))
{
if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE)
{
setting.predefinedValue.stringValue = DecryptStringValue(setting.predefinedValue.rawData, setting.settingId);
if (setting.isCurrentPredefined == 1)
setting.currentValue.stringValue = DecryptStringValue(setting.currentValue.rawData, setting.settingId);
}
else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE)
{
setting.predefinedValue.dwordValue = DecryptDwordValue(setting.predefinedValue.dwordValue, setting.settingId);
if (setting.isCurrentPredefined == 1)
setting.currentValue.dwordValue = DecryptDwordValue(setting.currentValue.dwordValue, setting.settingId);
}
}
}
}
private string FormatInternalSettingKey(string profileName, uint settingId)
{
return profileName + settingId.ToString("X8").ToLower();
}
public bool IsInternalSetting(string profileName, uint settingId)
{
return _InternalSettings.Contains(FormatInternalSettingKey(profileName, settingId));
}
private HashSet<string> _InternalSettings = new HashSet<string>();
private void CreateInternalSettingMap()
{
string tmpfile = Path.GetTempFileName();
DrsSession((hSession) =>
{
SaveSettingsFileEx(hSession, tmpfile);
});
if (File.Exists(tmpfile))
{
var lines = File.ReadAllLines(tmpfile);
_InternalSettings = new HashSet<string>();
var paProfile = "Profile\\s\\\"(?<profileName>.*?)\\\"";
var rxProfile = new Regex(paProfile, RegexOptions.Compiled);
var paSetting = "ID_0x(?<sid>[0-9a-fA-F]+)\\s\\=.*?InternalSettingFlag\\=V0";
var rxSetting = new Regex(paSetting, RegexOptions.Compiled);
var currentProfileName = "";
for (int i = 0; i < lines.Length; i++)
{
foreach (Match ms in rxProfile.Matches(lines[i]))
{
currentProfileName = ms.Result("${profileName}");
}
foreach (Match ms in rxSetting.Matches(lines[i]))
{
_InternalSettings.Add(currentProfileName + ms.Result("${sid}"));
}
}
File.Delete(tmpfile);
}
}
}
}

View File

@@ -14,11 +14,19 @@ namespace nspector.Common
{
private readonly DrsSettingsService _SettingService;
private readonly DrsScannerService _ScannerService;
private readonly DrsDecrypterService _DecrypterService;
public DrsImportService(DrsSettingsMetaService metaService, DrsSettingsService settingService)
public DrsImportService(
DrsSettingsMetaService metaService,
DrsSettingsService settingService,
DrsScannerService scannerService,
DrsDecrypterService decrypterService)
: base(metaService)
{
_SettingService = settingService;
_ScannerService = scannerService;
_DecrypterService = decrypterService;
}
internal void ExportAllProfilesToNvidiaTextFile(string filename)
@@ -62,70 +70,98 @@ namespace nspector.Common
if (hProfile != IntPtr.Zero)
{
var settings = GetProfileSettings(hSession, hProfile);
if (settings.Count > 0)
result.ProfileName = profileName;
var apps = GetProfileApplications(hSession, hProfile);
foreach (var app in apps)
{
result.ProfileName = profileName;
result.Executeables.Add(app.appName);
}
var settings = GetProfileSettings(hSession, hProfile);
foreach (var setting in settings)
{
var isPredefined = setting.isCurrentPredefined == 1;
var isCurrentProfile = setting.settingLocation ==
NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION;
var apps = GetProfileApplications(hSession, hProfile);
foreach (var app in apps)
if (isCurrentProfile && (!isPredefined || includePredefined))
{
result.Executeables.Add(app.appName);
}
var exportSetting = setting;
_DecrypterService.DecryptSettingIfNeeded(profileName, ref exportSetting);
foreach (var setting in settings)
{
var isPredefined = setting.isCurrentPredefined == 1;
var isDwordSetting = setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE;
var isCurrentProfile = setting.settingLocation ==
NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION;
var profileSetting = ImportExportUitl
.ConvertDrsSettingToProfileSetting(exportSetting);
if (isDwordSetting && isCurrentProfile)
{
if (!isPredefined || includePredefined)
{
var profileSetting = new ProfileSetting()
{
SettingNameInfo = setting.settingName,
SettingId = setting.settingId,
SettingValue = setting.currentValue.dwordValue,
};
result.Settings.Add(profileSetting);
}
}
result.Settings.Add(profileSetting);
}
}
}
return result;
}
internal void ImportProfiles(string filename)
internal string ImportProfiles(string filename)
{
var sbFailedProfilesMessage = new StringBuilder();
var appInUseHint = false;
var profiles = XMLHelper<Profiles>.DeserializeFromXMLFile(filename);
DrsSession((hSession) =>
{
foreach (Profile profile in profiles)
{
var profileCreated = false;
var hProfile = GetProfileHandle(hSession, profile.ProfileName);
if (hProfile == IntPtr.Zero)
{
hProfile = CreateProfile(hSession, profile.ProfileName);
nvw.DRS_SaveSettings(hSession);
profileCreated = true;
}
if (hProfile != IntPtr.Zero)
{
var modified = false;
_SettingService.ResetProfile(profile.ProfileName, out modified);
try
{
UpdateApplications(hSession, hProfile, profile);
UpdateSettings(hSession, hProfile, profile, profile.ProfileName);
}
catch (NvapiException nex)
{
if (profileCreated)
{
nvw.DRS_DeleteProfile(hSession, hProfile);
}
UpdateApplications(hSession, hProfile, profile);
UpdateSettings(hSession, hProfile, profile);
sbFailedProfilesMessage.AppendLine(string.Format("Failed to import profile '{0}'", profile.ProfileName));
var appEx = nex as NvapiAddApplicationException;
if (appEx != null)
{
var profilesWithThisApp = _ScannerService.FindProfilesUsingApplication(appEx.ApplicationName);
sbFailedProfilesMessage.AppendLine(string.Format("- application '{0}' is already in use by profile '{1}'", appEx.ApplicationName, profilesWithThisApp));
appInUseHint = true;
}
else
{
sbFailedProfilesMessage.AppendLine(string.Format("- {0}", nex.Message));
}
sbFailedProfilesMessage.AppendLine("");
}
nvw.DRS_SaveSettings(hSession);
}
}
});
if (appInUseHint)
{
sbFailedProfilesMessage.AppendLine("Hint: If just the profile name has been changed by nvidia, consider to manually modify the profile name inside the import file using a text editor.");
}
return sbFailedProfilesMessage.ToString();
}
private bool ExistsImportApp(string appName, Profile importProfile)
@@ -150,7 +186,14 @@ namespace nspector.Common
{
if (!alreadySet.Contains(appName))
{
AddApplication(hSession, hProfile, appName);
try
{
AddApplication(hSession, hProfile, appName);
}
catch (NvapiException)
{
throw new NvapiAddApplicationException(appName);
}
}
}
}
@@ -161,18 +204,24 @@ namespace nspector.Common
.FirstOrDefault(x => x.SettingId.Equals(settingId));
if (setting != null)
return setting.SettingValue;
return uint.Parse(setting.SettingValue);
return 0;
}
private ProfileSetting GetImportProfileSetting(uint settingId, Profile importProfile)
{
return importProfile.Settings
.FirstOrDefault(x => x.SettingId.Equals(settingId));
}
private bool ExistsImportValue(uint settingId, Profile importProfile)
{
return importProfile.Settings
.Any(x => x.SettingId.Equals(settingId));
}
private void UpdateSettings(IntPtr hSession, IntPtr hProfile, Profile importProfile)
private void UpdateSettings(IntPtr hSession, IntPtr hProfile, Profile importProfile, string profileName)
{
var alreadySet = new HashSet<uint>();
@@ -180,20 +229,24 @@ namespace nspector.Common
foreach (var setting in settings)
{
var isCurrentProfile = setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION;
var isDwordSetting = setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE;
var isPredefined = setting.isCurrentPredefined == 1;
if (isCurrentProfile && isDwordSetting)
if (isCurrentProfile)
{
bool exitsValue = ExistsImportValue(setting.settingId, importProfile);
uint importValue = GetImportValue(setting.settingId, importProfile);
if (isPredefined && exitsValue && importValue == setting.currentValue.dwordValue)
bool exitsValueInImport = ExistsImportValue(setting.settingId, importProfile);
var importSetting = GetImportProfileSetting(setting.settingId, importProfile);
var decryptedSetting = setting;
_DecrypterService.DecryptSettingIfNeeded(profileName, ref decryptedSetting);
if (isPredefined && exitsValueInImport && ImportExportUitl.AreDrsSettingEqualToProfileSetting(decryptedSetting, importSetting))
{
alreadySet.Add(setting.settingId);
}
else if (exitsValue)
else if (exitsValueInImport)
{
StoreDwordValue(hSession, hProfile, setting.settingId, importValue);
var updatedSetting = ImportExportUitl.ConvertProfileSettingToDrsSetting(importSetting);
StoreSetting(hSession, hProfile, updatedSetting);
alreadySet.Add(setting.settingId);
}
else if (!isPredefined)
@@ -207,7 +260,8 @@ namespace nspector.Common
{
if (!alreadySet.Contains(setting.SettingId))
{
StoreDwordValue(hSession, hProfile, setting.SettingId, setting.SettingValue);
var newSetting = ImportExportUitl.ConvertProfileSettingToDrsSetting(setting);
StoreSetting(hSession, hProfile, newSetting);
}
}
}

View File

@@ -20,8 +20,8 @@ namespace nspector.Common
internal class DrsScannerService : DrsSettingsServiceBase
{
public DrsScannerService(DrsSettingsMetaService metaService)
: base(metaService)
public DrsScannerService(DrsSettingsMetaService metaService, DrsDecrypterService decrpterService)
: base(metaService, decrpterService)
{ }
public event SettingScanDoneEvent OnModifiedProfilesScanDone;
@@ -30,11 +30,12 @@ namespace nspector.Common
internal List<CachedSettings> CachedSettings = new List<CachedSettings>();
internal List<string> ModifiedProfiles = new List<string>();
internal HashSet<string> UserProfiles = new HashSet<string>();
// most common setting ids as start pattern for the heuristic scan
private readonly uint[] _commonSettingIds = new uint[] { 0x1095DEF8, 0x1033DCD2, 0x1033CEC1,
0x10930F46, 0x00A06946, 0x10ECDB82, 0x20EBD7B8, 0x0095DEF9, 0x00D55F7D,
0x1033DCD3, 0x1033CEC2, 0x2072F036, 0x00664339, 0x002C7F45, 0x209746C1,
private readonly uint[] _commonSettingIds = new uint[] { 0x1095DEF8, 0x1033DCD2, 0x1033CEC1,
0x10930F46, 0x00A06946, 0x10ECDB82, 0x20EBD7B8, 0x0095DEF9, 0x00D55F7D,
0x1033DCD3, 0x1033CEC2, 0x2072F036, 0x00664339, 0x002C7F45, 0x209746C1,
0x0076E164, 0x20FF7493, 0x204CFF7B };
@@ -61,6 +62,11 @@ namespace nspector.Common
}
else if (addToScanResult)
{
if (decrypter != null)
{
decrypter.DecryptSettingIfNeeded(profile.profileName, ref setting);
}
checkedSettingsCount++;
AddScannedSettingToCache(profile, setting);
alreadyCheckedSettingIds.Add(setting.settingId);
@@ -70,10 +76,10 @@ namespace nspector.Common
{
return true;
}
return false;
}
private void ReportProgress(int current, int max)
{
int percent = (current > 0) ? (int)Math.Round((current * 100f) / max) : 0;
@@ -85,6 +91,7 @@ namespace nspector.Common
private void ScanForModifiedProfiles()
{
ModifiedProfiles = new List<string>();
UserProfiles = new HashSet<string>();
var knownPredefines = new List<uint>(_commonSettingIds);
DrsSession((hSession) =>
@@ -107,6 +114,7 @@ namespace nspector.Common
if (profile.isPredefined == 0)
{
ModifiedProfiles.Add(profile.profileName);
UserProfiles.Add(profile.profileName);
continue;
}
@@ -139,7 +147,7 @@ namespace nspector.Common
// }
// }
//}
if (foundModifiedProfile || checkedSettingsCount >= profile.numOfSettings)
continue;
@@ -219,7 +227,7 @@ namespace nspector.Common
var thread = new Thread(ScanForPredefinedProfileSettings);
thread.Start();
}
private void AddScannedSettingToCache(NVDRS_PROFILE profile, NVDRS_SETTING setting)
{
// Skip 3D Vision string values here for improved scan performance
@@ -242,28 +250,30 @@ namespace nspector.Common
if (allowAddValue)
{
if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE)
cachedSetting.AddStringValue(setting.currentValue.stringValue, profile.profileName);
else
cachedSetting.AddDwordValue(setting.currentValue.dwordValue, profile.profileName);
cachedSetting.AddStringValue(setting.predefinedValue.stringValue, profile.profileName);
else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE)
cachedSetting.AddDwordValue(setting.predefinedValue.dwordValue, profile.profileName);
else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE)
cachedSetting.AddBinaryValue(setting.predefinedValue.binaryValue, profile.profileName);
}
if (!cacheEntryExists)
CachedSettings.Add(cachedSetting);
}
}
}
public string FindProfilesUsingApplication(string applicationName)
{
string lowerApplicationName = applicationName.ToLower();
string tmpfile = Path.GetTempFileName();
var result = new StringBuilder();
var matchingProfiles = new List<string>();
DrsSession((hSession) =>
{
SaveSettingsFileEx(hSession, tmpfile);
});
if (File.Exists(tmpfile))
{
string content = File.ReadAllText(tmpfile);
@@ -275,7 +285,7 @@ namespace nspector.Common
{
if (ms.Result("${app}").ToLower() == lowerApplicationName)
{
result.Append(m.Result("${profile}") + ";");
matchingProfiles.Add(m.Result("${profile}"));
}
}
}
@@ -283,8 +293,8 @@ namespace nspector.Common
if (File.Exists(tmpfile))
File.Delete(tmpfile);
return result.ToString();
return string.Join(";", matchingProfiles);
}
}

View File

@@ -20,6 +20,7 @@ namespace nspector.Common
public static readonly DrsSettingsService SettingService;
public static readonly DrsImportService ImportService;
public static readonly DrsScannerService ScannerService;
public static readonly DrsDecrypterService DecrypterService;
static DrsServiceLocator()
{
@@ -27,9 +28,10 @@ namespace nspector.Common
ReferenceSettings = LoadReferenceSettings();
MetaService = new DrsSettingsMetaService(CustomSettings, ReferenceSettings);
SettingService = new DrsSettingsService(MetaService);
ImportService = new DrsImportService(MetaService, SettingService);
ScannerService = new DrsScannerService(MetaService);
DecrypterService = new DrsDecrypterService(MetaService);
ScannerService = new DrsScannerService(MetaService, DecrypterService);
SettingService = new DrsSettingsService(MetaService, DecrypterService);
ImportService = new DrsImportService(MetaService, SettingService, ScannerService, DecrypterService);
}
private static CustomSettingNames LoadCustomSettings()

View File

@@ -127,24 +127,39 @@ namespace nspector.Common
return null;
}
private byte[] GetBinaryDefaultValue(uint settingId)
{
foreach (var service in MetaServices.OrderBy(x => x.Service.Source))
{
var settingDefault = service.Service.GetBinaryDefaultValue(settingId);
if (settingDefault != null)
return settingDefault;
}
return null;
}
private List<SettingValue<T>> MergeSettingValues<T>(List<SettingValue<T>> a, List<SettingValue<T>> b)
{
if (b == null)
return a;
// force scanned settings to add instead of merge
if (b.Count > 0 && b.First().ValueSource == SettingMetaSource.ScannedSettings)
var isScannedValuesList = (b.Count > 0 && b.First().ValueSource == SettingMetaSource.ScannedSettings);
if (isScannedValuesList)
{
a.AddRange(b);
}
else
{
var newValues = b.Where(xb => !a.Select(xa => xa.Value).Contains(xb.Value)).ToList();
a.AddRange(newValues);
var currentNonScannedValues = a.Where(xa => xa.ValueSource != SettingMetaSource.ScannedSettings).Select(xa => xa.Value).ToList();
var newNonScannedValues = b.Where(xb => !currentNonScannedValues.Contains(xb.Value)).ToList();
a.AddRange(newNonScannedValues);
foreach (var settingValue in a)
{
var bVal = b.FirstOrDefault(x => x.Value.Equals(settingValue.Value) && x.ValueSource != SettingMetaSource.ScannedSettings);
var bVal = b.FirstOrDefault(x => x.Value.Equals(settingValue.Value) && settingValue.ValueSource != SettingMetaSource.ScannedSettings);
if (bVal != null && bVal.ValueName != null)
{
settingValue.ValueName = bVal.ValueName;
@@ -154,7 +169,23 @@ namespace nspector.Common
}
}
return a.OrderBy(x=>x.Value).ToList();
var atmp = a.FirstOrDefault();
if (atmp != null && atmp is IComparable)
return a.OrderBy(x=>x.Value).ToList();
else
return a.ToList();
}
private List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
var result = new List<SettingValue<byte[]>>();
foreach (var service in MetaServices.OrderByDescending(x => x.ValueNamePrio))
{
result = MergeSettingValues(result, service.Service.GetBinaryValues(settingId));
}
return result;
}
private List<SettingValue<string>> GetStringValues(uint settingId)
@@ -201,7 +232,7 @@ namespace nspector.Common
public List<uint> GetSettingIds(SettingViewMode viewMode)
{
var settingIds = new List<uint>();
var allowedSourcesForViewMode = GetAllowedMetaSourcesForViewMode(viewMode);
var allowedSourcesForViewMode = GetAllowedSettingIdMetaSourcesForViewMode(viewMode);
foreach (var service in MetaServices.OrderBy(x => x.Service.Source))
{
@@ -213,7 +244,7 @@ namespace nspector.Common
return settingIds.Distinct().ToList();
}
private SettingMetaSource[] GetAllowedMetaSourcesForViewMode(SettingViewMode viewMode)
private SettingMetaSource[] GetAllowedSettingIdMetaSourcesForViewMode(SettingViewMode viewMode)
{
switch (viewMode)
{
@@ -226,7 +257,9 @@ namespace nspector.Common
SettingMetaSource.ConstantSettings,
SettingMetaSource.ScannedSettings,
SettingMetaSource.CustomSettings,
SettingMetaSource.DriverSettings,
SettingMetaSource.DriverSettings,
SettingMetaSource.NvD3dUmxSettings,
SettingMetaSource.ReferenceSettings,
};
default:
return new [] {
@@ -236,6 +269,28 @@ namespace nspector.Common
}
}
private SettingMetaSource[] GetAllowedSettingValueMetaSourcesForViewMode(SettingViewMode viewMode)
{
switch (viewMode)
{
case SettingViewMode.CustomSettingsOnly:
return new[] {
SettingMetaSource.CustomSettings,
SettingMetaSource.ScannedSettings,
};
default:
return new[] {
SettingMetaSource.ConstantSettings,
SettingMetaSource.ScannedSettings,
SettingMetaSource.CustomSettings,
SettingMetaSource.DriverSettings,
SettingMetaSource.NvD3dUmxSettings,
SettingMetaSource.ReferenceSettings,
};
}
}
private SettingMeta CreateSettingMeta(uint settingId)
{
var settingType = GetSettingValueType(settingId);
@@ -259,6 +314,10 @@ namespace nspector.Common
settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE
? GetStringDefaultValue(settingId) : null,
DefaultBinaryValue =
settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE
? GetBinaryDefaultValue(settingId) : null,
DwordValues =
settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE
? GetDwordValues(settingId) : null,
@@ -266,30 +325,65 @@ namespace nspector.Common
StringValues =
settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE
? GetStringValues(settingId) : null,
BinaryValues =
settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE
? GetBinaryValues(settingId) : null,
};
return result;
}
private SettingMeta PostProcessMeta(uint settingId, SettingMeta settingMeta)
private SettingMeta PostProcessMeta(uint settingId, SettingMeta settingMeta, SettingViewMode viewMode)
{
if (string.IsNullOrEmpty(settingMeta.SettingName))
settingMeta.SettingName = string.Format("0x{0:X8}", settingId);
return settingMeta;
var newMeta = new SettingMeta()
{
DefaultDwordValue = settingMeta.DefaultDwordValue,
DefaultStringValue = settingMeta.DefaultStringValue,
DefaultBinaryValue = settingMeta.DefaultBinaryValue,
SettingName = settingMeta.SettingName,
SettingType = settingMeta.SettingType,
GroupName = settingMeta.GroupName,
};
if (string.IsNullOrEmpty(newMeta.SettingName))
{
newMeta.SettingName = string.Format("0x{0:X8}", settingId);
}
var allowedSourcesForViewMode = GetAllowedSettingValueMetaSourcesForViewMode(viewMode);
if (settingMeta.DwordValues != null)
{
newMeta.DwordValues = settingMeta.DwordValues
.Where(x => allowedSourcesForViewMode.Contains(x.ValueSource)).ToList();
}
if (settingMeta.StringValues != null)
{
newMeta.StringValues = settingMeta.StringValues
.Where(x => allowedSourcesForViewMode.Contains(x.ValueSource)).ToList();
}
if (settingMeta.BinaryValues != null)
{
newMeta.BinaryValues = settingMeta.BinaryValues
.Where(x => allowedSourcesForViewMode.Contains(x.ValueSource)).ToList();
}
return newMeta;
}
public SettingMeta GetSettingMeta(uint settingId)
public SettingMeta GetSettingMeta(uint settingId, SettingViewMode viewMode = SettingViewMode.Normal)
{
if (settingMetaCache.ContainsKey(settingId))
{
return PostProcessMeta(settingId, settingMetaCache[settingId]);
return PostProcessMeta(settingId, settingMetaCache[settingId], viewMode);
}
else
{
var settingMeta = CreateSettingMeta(settingId);
settingMetaCache.Add(settingId, settingMeta);
return PostProcessMeta(settingId, settingMeta);
return PostProcessMeta(settingId, settingMeta, viewMode);
}
}

View File

@@ -17,8 +17,8 @@ namespace nspector.Common
internal class DrsSettingsService : DrsSettingsServiceBase
{
public DrsSettingsService(DrsSettingsMetaService metaService)
: base(metaService)
public DrsSettingsService(DrsSettingsMetaService metaService, DrsDecrypterService decrpterService)
: base(metaService, decrpterService)
{
_baseProfileSettingIds = InitBaseProfileSettingIds();
}
@@ -296,6 +296,11 @@ namespace nspector.Common
var str = DrsUtil.ParseStringSettingValue(settingMeta, setting.Value);
StoreStringValue(hSession, hProfile, setting.Key, str);
}
else if (settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE)
{
var bin = DrsUtil.ParseBinarySettingValue(settingMeta, setting.Value);
StoreBinaryValue(hSession, hProfile, setting.Key, bin);
}
}
SaveSettings(hSession);
@@ -317,9 +322,12 @@ namespace nspector.Common
if (settingMeta.StringValues == null)
settingMeta.StringValues = new List<SettingValue<string>>();
if (settingMeta.BinaryValues == null)
settingMeta.BinaryValues = new List<SettingValue<byte[]>>();
var settingState = SettingState.NotAssiged;
string valueRaw = DrsUtil.StringValueRaw;
string valueRaw = "";
string valueText = "";
if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE)
@@ -376,6 +384,31 @@ namespace nspector.Common
}
}
if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE)
{
if (useDefault)
{
valueRaw = DrsUtil.GetBinaryString(settingMeta.DefaultBinaryValue);
valueText = DrsUtil.GetBinarySettingValueName(settingMeta, settingMeta.DefaultBinaryValue);
}
else if (setting.isCurrentPredefined == 1 && setting.isPredefinedValid == 1)
{
valueRaw = DrsUtil.GetBinaryString(setting.predefinedValue.binaryValue);
valueText = DrsUtil.GetBinarySettingValueName(settingMeta, setting.predefinedValue.binaryValue);
settingState = SettingState.NvidiaSetting;
}
else
{
valueRaw = DrsUtil.GetBinaryString(setting.currentValue.binaryValue);
valueText = DrsUtil.GetBinarySettingValueName(settingMeta, setting.currentValue.binaryValue);
if (setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION)
settingState = SettingState.UserdefinedSetting;
else
settingState = SettingState.GlobalSetting;
}
}
return new SettingItem()
{
SettingId = setting.settingId,

View File

@@ -16,10 +16,12 @@ namespace nspector.Common
{
protected DrsSettingsMetaService meta;
protected DrsDecrypterService decrypter;
public DrsSettingsServiceBase(DrsSettingsMetaService metaService)
public DrsSettingsServiceBase(DrsSettingsMetaService metaService, DrsDecrypterService decrpterService = null)
{
meta = metaService;
decrypter = decrpterService;
DriverVersion = GetDriverVersionInternal();
}
@@ -48,7 +50,7 @@ namespace nspector.Common
});
}
protected T DrsSession<T>(Func<IntPtr,T> action)
protected T DrsSession<T>(Func<IntPtr, T> action)
{
return DrsSessionScope.DrsSession<T>(action);
}
@@ -73,7 +75,7 @@ namespace nspector.Common
if (nvRes == NvAPI_Status.NVAPI_PROFILE_NOT_FOUND)
return IntPtr.Zero;
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_FindProfileByName", nvRes);
}
@@ -84,7 +86,7 @@ namespace nspector.Common
{
if (string.IsNullOrEmpty(profileName))
throw new ArgumentNullException("profileName");
var hProfile = IntPtr.Zero;
var newProfile = new NVDRS_PROFILE()
@@ -96,7 +98,7 @@ namespace nspector.Common
var nvRes = nvw.DRS_CreateProfile(hSession, ref newProfile, ref hProfile);
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_CreateProfile", nvRes);
return hProfile;
}
@@ -113,6 +115,13 @@ namespace nspector.Common
return tmpProfile;
}
protected void StoreSetting(IntPtr hSession, IntPtr hProfile, NVDRS_SETTING newSetting)
{
var ssRes = nvw.DRS_SetSetting(hSession, hProfile, ref newSetting);
if (ssRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_SetSetting", ssRes);
}
protected void StoreDwordValue(IntPtr hSession, IntPtr hProfile, uint settingId, uint dwordValue)
{
var newSetting = new NVDRS_SETTING()
@@ -153,6 +162,26 @@ namespace nspector.Common
}
protected void StoreBinaryValue(IntPtr hSession, IntPtr hProfile, uint settingId, byte[] binValue)
{
var newSetting = new NVDRS_SETTING()
{
version = nvw.NVDRS_SETTING_VER,
settingId = settingId,
settingType = NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE,
settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION,
currentValue = new NVDRS_SETTING_UNION()
{
binaryValue = binValue,
},
};
var ssRes = nvw.DRS_SetSetting(hSession, hProfile, ref newSetting);
if (ssRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_SetSetting", ssRes);
}
protected NVDRS_SETTING? ReadSetting(IntPtr hSession, IntPtr hProfile, uint settingId)
{
var newSetting = new NVDRS_SETTING()
@@ -163,10 +192,16 @@ namespace nspector.Common
var ssRes = nvw.DRS_GetSetting(hSession, hProfile, settingId, ref newSetting);
if (ssRes == NvAPI_Status.NVAPI_SETTING_NOT_FOUND)
return null;
if (ssRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_GetSetting", ssRes);
if (decrypter != null)
{
var profile = GetProfileInfo(hSession, hProfile);
decrypter.DecryptSettingIfNeeded(profile.profileName, ref newSetting);
}
return newSetting;
}
@@ -177,7 +212,7 @@ namespace nspector.Common
return null;
return newSetting.Value.currentValue.dwordValue;
}
protected void AddApplication(IntPtr hSession, IntPtr hProfile, string applicationName)
{
var newApp = new NVDRS_APPLICATION_V3()
@@ -238,6 +273,15 @@ namespace nspector.Common
if (esRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_EnumSettings", esRes);
if (decrypter != null)
{
var profile = GetProfileInfo(hSession, hProfile);
for (int i = 0; i < settingCount; i++)
{
decrypter.DecryptSettingIfNeeded(profile.profileName, ref settings[i]);
}
}
return settings.ToList();
}

View File

@@ -70,5 +70,52 @@ namespace nspector.Common
return settingValue == null ? stringValue : settingValue.ValueName;
}
public static string GetBinaryString(byte[] binaryValue)
{
if (binaryValue == null)
return "";
if (binaryValue.Length == 8)
return string.Format("0x{0:X16}", BitConverter.ToUInt64(binaryValue, 0));
return BitConverter.ToString(binaryValue);
}
internal static string GetBinarySettingValueName(SettingMeta meta, byte[] binaryValue)
{
var settingValue = meta.BinaryValues?
.FirstOrDefault(x => x.Value.Equals(binaryValue));
return settingValue == null ? GetBinaryString(binaryValue) : settingValue.ValueName;
}
internal static byte[] ParseBinarySettingValue(SettingMeta meta, string text)
{
var valueByName = meta.BinaryValues.FirstOrDefault(x => x.ValueName != null && x.ValueName.Equals(text));
if (valueByName != null)
return valueByName.Value;
return ParseBinaryByInputSafe(text);
}
public static byte[] ParseBinaryByInputSafe(string input)
{
if (string.IsNullOrWhiteSpace(input))
return null;
if (input.StartsWith("0x"))
{
int blankPos = input.IndexOf(' ');
int parseLen = blankPos > 2 ? blankPos - 2 : input.Length - 2;
var qword = ulong.Parse(input.Substring(2, parseLen), NumberStyles.AllowHexSpecifier);
return BitConverter.GetBytes(qword);
}
if (input.Contains("-"))
return Array.ConvertAll<string, byte>(input.Split('-'), s => Convert.ToByte(s, 16));
return null;
}
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using nspector.Native.WINAPI;
namespace nspector.Common.Helper
{
public class ShortcutResolver
{
public static string GetUrlFromInternetShortcut(string filePath)
{
var lines = File.ReadAllLines(filePath);
foreach (var line in lines)
{
if (line.StartsWith("URL="))
{
string[] splitLine = line.Split('=');
if (splitLine.Length > 0)
{
return splitLine[1];
}
}
}
return "";
}
public static string ResolveExecuteable(string filename, out string profileName)
{
var fileInfo = new FileInfo(filename);
profileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
try
{
switch (fileInfo.Extension.ToLower())
{
case ".lnk": return ResolveFromShellLinkFile(fileInfo.FullName);
case ".url": return ResolveFromUrlFile(fileInfo.FullName);
case ".exe": return fileInfo.Name;
default: return "";
}
}
catch
{
return "";
}
}
private static string ResolveFromShellLinkFile(string filename)
{
var shellLink = new ShellLink(filename);
if (shellLink.Arguments.StartsWith(SteamAppResolver.SteamUrlPattern))
{
var resolver = new SteamAppResolver();
return resolver.ResolveExeFromSteamUrl(shellLink.Arguments);
}
var targetInfo = new FileInfo(shellLink.Target);
if (targetInfo.Name.ToLower() == SteamAppResolver.SteamExeName)
{
if (shellLink.Arguments.Contains(SteamAppResolver.SteamArgumentPattern))
{
var resolver = new SteamAppResolver();
return resolver.ResolveExeFromSteamArguments(shellLink.Arguments);
}
}
if (targetInfo.Extension.ToLower().Equals(".exe"))
{
return targetInfo.Name;
}
return "";
}
private static string ResolveFromUrlFile(string filename)
{
var url = GetUrlFromInternetShortcut(filename);
if (url.StartsWith(SteamAppResolver.SteamUrlPattern))
{
var resolver = new SteamAppResolver();
return resolver.ResolveExeFromSteamUrl(url);
}
return "";
}
}
}

View File

@@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace nspector.Common.Helper
{
public class SteamAppResolver
{
public const string SteamExeName = "steam.exe";
public const string SteamUrlPattern = "steam://rungameid/";
public const string SteamArgumentPattern = "-applaunch";
private byte[] _appinfoBytes;
public SteamAppResolver()
{
var appInfoLocation = GetSteamAppInfoLocation();
if (File.Exists(appInfoLocation))
_appinfoBytes = File.ReadAllBytes(appInfoLocation);
else
_appinfoBytes = null;
}
private string GetSteamAppInfoLocation()
{
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam", false);
if (reg != null)
{
string steamPath = (string)reg.GetValue("SteamPath", null);
if (steamPath != null)
return Path.Combine(steamPath, @"appcache\appinfo.vdf");
}
return "";
}
public string ResolveExeFromSteamUrl(string url)
{
if (url.StartsWith(SteamUrlPattern))
{
var appIdStr = url.Substring(SteamUrlPattern.Length);
int appid = 0;
if (int.TryParse(appIdStr, out appid))
{
return FindCommonExecutableForApp(appid);
}
}
return "";
}
public string ResolveExeFromSteamArguments(string arguments)
{
if (arguments.Contains(SteamArgumentPattern))
{
var rxRungame = new Regex(SteamArgumentPattern + @"\s+(?<appid>\d+)");
foreach (Match m in rxRungame.Matches(arguments))
{
var appIdStr = m.Result("${appid}");
int appid = 0;
if (int.TryParse(appIdStr, out appid))
{
return FindCommonExecutableForApp(appid);
}
}
}
return "";
}
private string FindCommonExecutableForApp(int appid)
{
var apps = FindAllExecutablesForApp(appid);
if (apps.Count > 0)
{
return new FileInfo(apps[0]).Name;
}
return "";
}
private List<string> FindAllExecutablesForApp(int appid)
{
if (_appinfoBytes == null)
return new List<string>();
var bid = BitConverter.GetBytes(appid);
int offset = 0;
var appidPattern = new byte[] { 0x08, bid[0], bid[1], bid[2], bid[3] };
var launchPattern = new byte[] { 0x00, 0x6C, 0x61, 0x75, 0x6E, 0x63, 0x68, 0x00 };
var appidOffset = FindOffset(_appinfoBytes, appidPattern, offset);
if (appidOffset == -1)
return new List<string>();
else
offset = appidOffset + appidPattern.Length;
var launchOffset = FindOffset(_appinfoBytes, launchPattern, offset);
if (launchOffset == -1)
return new List<string>();
else
offset = launchOffset;
var executables = new List<string>();
FindExecutables(_appinfoBytes, ref offset, ref executables);
return executables;
}
private void FindExecutables(byte[] bytes, ref int offset, ref List<string> executables)
{
while (true)
{
var valueType = ReadByte(bytes, ref offset);
if (valueType == 0x08)
{
break;
}
var valueName = ReadCString(bytes, ref offset);
var valueString = "";
switch (valueType)
{
case 0:
{
FindExecutables(bytes, ref offset, ref executables);
break;
}
case 1:
{
valueString = ReadCString(bytes, ref offset);
if (valueName == "executable" && valueString.EndsWith(".exe"))
{
executables.Add(valueString);
}
break;
}
case 2:
{
offset += 4;
break;
}
case 7:
{
offset += 8;
break;
}
default: break;
}
}
}
private static int FindOffset(byte[] bytes, byte[] pattern, int offset = 0, byte? wildcard = null)
{
for (int i = offset; i < bytes.Length; i++)
{
if (pattern[0] == bytes[i] && bytes.Length - i >= pattern.Length)
{
bool ismatch = true;
for (int j = 1; j < pattern.Length && ismatch == true; j++)
{
if (bytes[i + j] != pattern[j] && ((wildcard.HasValue && wildcard != pattern[j]) || !wildcard.HasValue))
{
ismatch = false;
break;
}
}
if (ismatch)
return i;
}
}
return -1;
}
private static byte ReadByte(byte[] bytes, ref int offset)
{
offset += 1;
return bytes[offset - 1];
}
private static string ReadCString(byte[] bytes, ref int offset)
{
var tmpOffset = offset;
while (bytes[tmpOffset] != 0)
{
tmpOffset++;
}
var start = offset;
var length = tmpOffset - offset;
offset += length + 1;
return Encoding.UTF8.GetString(bytes, start, length);
}
}
}

View File

@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nspector.Native.NVAPI2;
namespace nspector.Common.Import
{
internal class ImportExportUitl
{
public static bool AreDrsSettingEqualToProfileSetting(NVDRS_SETTING drsSetting, ProfileSetting profileSetting)
{
var profileSettingCompare = ConvertDrsSettingToProfileSetting(drsSetting);
return profileSetting.SettingValue.Equals(profileSettingCompare.SettingValue);
}
public static ProfileSetting ConvertDrsSettingToProfileSetting(NVDRS_SETTING setting)
{
return new ProfileSetting
{
SettingId = setting.settingId,
SettingNameInfo = setting.settingName,
SettingValue = ConvertSettingValueToString(setting),
ValueType = MapValueType(setting.settingType),
};
}
private static string ConvertSettingValueToString(NVDRS_SETTING setting)
{
var settingUnion = setting.currentValue;
if (setting.isCurrentPredefined == 1)
{
settingUnion = setting.predefinedValue;
}
switch (setting.settingType)
{
case NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE:
return settingUnion.dwordValue.ToString();
case NVDRS_SETTING_TYPE.NVDRS_STRING_TYPE:
return settingUnion.ansiStringValue;
case NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE:
return settingUnion.stringValue;
case NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE:
return Convert.ToBase64String(settingUnion.binaryValue);
default:
throw new Exception("invalid setting type");
}
}
private static SettingValueType MapValueType(NVDRS_SETTING_TYPE input)
{
switch (input)
{
case NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE: return SettingValueType.Binary;
case NVDRS_SETTING_TYPE.NVDRS_STRING_TYPE: return SettingValueType.AnsiString;
case NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE: return SettingValueType.String;
default: return SettingValueType.Dword;
}
}
public static NVDRS_SETTING ConvertProfileSettingToDrsSetting(ProfileSetting setting)
{
var newSetting = new NVDRS_SETTING()
{
version = NvapiDrsWrapper.NVDRS_SETTING_VER,
settingId = setting.SettingId,
settingType = MapValueType(setting.ValueType),
settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION,
currentValue = ConvertStringToSettingUnion(setting.ValueType, setting.SettingValue),
};
return newSetting;
}
private static NVDRS_SETTING_UNION ConvertStringToSettingUnion(SettingValueType valueType, string valueString)
{
var union = new NVDRS_SETTING_UNION();
switch (valueType)
{
case SettingValueType.Dword:
union.dwordValue = uint.Parse(valueString);
break;
case SettingValueType.String:
union.stringValue = valueString;
break;
case SettingValueType.AnsiString:
union.ansiStringValue = valueString;
break;
case SettingValueType.Binary:
union.binaryValue = Convert.FromBase64String(valueString);
break;
default:
throw new Exception("invalid value type");
}
return union;
}
private static NVDRS_SETTING_TYPE MapValueType(SettingValueType input)
{
switch (input)
{
case SettingValueType.Binary: return NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE;
case SettingValueType.AnsiString: return NVDRS_SETTING_TYPE.NVDRS_STRING_TYPE;
case SettingValueType.String: return NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE;
default: return NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE;
}
}
}
}

View File

@@ -11,6 +11,8 @@ namespace nspector.Common.Import
[XmlElement(ElementName = "SettingID")]
public uint SettingId = 0;
public uint SettingValue = 0;
public string SettingValue = "0";
public SettingValueType ValueType = SettingValueType.Dword;
}
}

View File

@@ -0,0 +1,10 @@
namespace nspector.Common.Import
{
public enum SettingValueType: int
{
Dword,
AnsiString,
String,
Binary
}
}

View File

@@ -158,6 +158,16 @@ namespace nspector.Common.Meta
return null;
}
public byte[] GetBinaryDefaultValue(uint settingId)
{
return null;
}
public List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
return null;
}
public SettingMetaSource Source
{
get { return SettingMetaSource.ConstantSettings; }

View File

@@ -93,6 +93,16 @@ namespace nspector.Common.Meta
return null;
}
public byte[] GetBinaryDefaultValue(uint settingId)
{
return null;
}
public List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
return null;
}
public SettingMetaSource Source
{
get { return _source; }

View File

@@ -96,6 +96,25 @@ namespace nspector.Common.Meta
}
}
}
if (values.settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE)
{
result.DefaultBinaryValue = values.defaultValue.binaryValue;
result.BinaryValues = new List<SettingValue<byte[]>>();
for (int i = 0; i < values.numSettingValues; i++)
{
var binValue = values.settingValues[i].binaryValue;
if (binValue != null)
{
result.BinaryValues.Add(
new SettingValue<byte[]>(Source)
{
Value = binValue,
ValueName = DrsUtil.GetBinaryString(binValue),
});
}
}
}
return result;
}
@@ -181,6 +200,24 @@ namespace nspector.Common.Meta
return null;
}
public byte[] GetBinaryDefaultValue(uint settingId)
{
var settingMeta = GetSettingsMeta(settingId);
if (settingMeta != null)
return settingMeta.DefaultBinaryValue;
return null;
}
public List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
var settingMeta = GetSettingsMeta(settingId);
if (settingMeta != null)
return settingMeta.BinaryValues;
return null;
}
public SettingMetaSource Source
{
get { return SettingMetaSource.DriverSettings; }

View File

@@ -20,10 +20,14 @@ namespace nspector.Common.Meta
string GetStringDefaultValue(uint settingId);
byte[] GetBinaryDefaultValue(uint settingId);
List<SettingValue<string>> GetStringValues(uint settingId);
List<SettingValue<uint>> GetDwordValues(uint settingId);
List<SettingValue<byte[]>> GetBinaryValues(uint settingId);
List<uint> GetSettingIds();
}
}

View File

@@ -54,6 +54,8 @@ namespace nspector.Common.Meta
private static List<NvD3dUmxName> ParseNvD3dUmxNames(string filename)
{
if (!File.Exists(filename)) return null;
var bytes = File.ReadAllBytes(filename);
var runtimeNameOffset = FindOffset(bytes, new byte[] { 0x52, 0x75, 0x6E, 0x54, 0x69, 0x6D, 0x65, 0x4E, 0x61, 0x6D, 0x65 });
@@ -104,11 +106,27 @@ namespace nspector.Common.Meta
private readonly List<NvD3dUmxName> _SettingNames;
private void ExportSettingsToCsn()
{
var settings = _SettingNames.Select(s => new CustomSettings.CustomSetting()
{
GroupName = "7 - Stereo",
HexSettingId = $"0x{s.settingId.ToString("X8")}",
UserfriendlyName = s.settingName,
}).ToList();
var xml = new CustomSettings.CustomSettingNames();
xml.Settings.AddRange(settings);
xml.StoreToFile("NvD3dUmx.xml");
}
public NvD3dUmxSettingMetaService()
{
var systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
var nvD3dUmxPath = Path.Combine(systemPath, "nvd3dumx.dll");
_SettingNames = ParseNvD3dUmxNames(nvD3dUmxPath);
//ExportSettingsToCsn();
}
public Type GetSettingEnumType(uint settingId)
@@ -157,7 +175,7 @@ namespace nspector.Common.Meta
{
return _SettingNames.Select(s => s.settingId).ToList();
}
return null;
return new List<uint>();
}
public string GetGroupName(uint settingId)
@@ -171,6 +189,16 @@ namespace nspector.Common.Meta
return null;
}
public byte[] GetBinaryDefaultValue(uint settingId)
{
return null;
}
public List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
return null;
}
public SettingMetaSource Source
{
get { return SettingMetaSource.NvD3dUmxSettings; }

View File

@@ -85,5 +85,24 @@ namespace nspector.Common.Meta
{
return CachedSettings.Select(c => c.SettingId).ToList();
}
public byte[] GetBinaryDefaultValue(uint settingId)
{
return null;
}
public List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
{
var cached = CachedSettings.FirstOrDefault(x => x.SettingId.Equals(settingId));
if (cached != null)
return cached.SettingValues.Select(s => new SettingValue<byte[]>(Source)
{
Value = s.ValueBin,
ValueName = string.Format("{0} ({1})", DrsUtil.GetBinaryString(s.ValueBin), s.ProfileNames),
}).ToList();
return null;
}
}
}

View File

@@ -18,8 +18,12 @@ namespace nspector.Common.Meta
public uint DefaultDwordValue { get; set; }
public byte[] DefaultBinaryValue { get; set; }
public List<SettingValue<string>> StringValues { get; set; }
public List<SettingValue<uint>> DwordValues { get; set; }
public List<SettingValue<byte[]>> BinaryValues { get; set; }
}
}

View File

@@ -22,9 +22,10 @@ namespace nspector.Common.Meta
public override string ToString()
{
if (typeof(T) == typeof(uint))
return string.Format("Value=0x{0:X8}; ValueName={1};", Value, ValueName);
return string.Format("Value=0x{0:X8}; ValueName={1}; Source={2};", Value, ValueName, ValueSource);
return string.Format("Value={0}; ValueName={1};", Value, ValueName);
}
}
}

View File

@@ -9,7 +9,7 @@ namespace nspector.Common
public class NvapiException : Exception
{
public readonly NvAPI_Status Status;
public NvapiException(string function, NvAPI_Status status)
: base(function + " failed: " + status)
{
@@ -17,4 +17,16 @@ namespace nspector.Common
}
}
public class NvapiAddApplicationException : NvapiException
{
public readonly string ApplicationName;
public NvapiAddApplicationException(string applicationName)
: base("DRS_CreateApplication", NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE)
{
ApplicationName = applicationName;
}
}
}

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -187,40 +187,114 @@ namespace nspector.Native.NVAPI2
// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]
// public string stringValue;
//}
//[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode, Size = 4100)]
//internal struct NVDRS_SETTING_UNION
//{
// public uint dwordValue;
// //massive hack for marshalling issues with unicode string overlapping
// public string stringValue
// {
// get
// {
// var firstPart = Encoding.Unicode.GetString(BitConverter.GetBytes(dwordValue)).Trim('\0');
// return firstPart + stringRaw;
// }
// set
// {
// var bytesRaw = Encoding.Unicode.GetBytes(value);
// var bytesFirst = new byte[4];
// var firstLength = bytesRaw.Length;
// if (firstLength > 4)
// firstLength = 4;
// Buffer.BlockCopy(bytesRaw, 0, bytesFirst, 0, firstLength);
// dwordValue = BitConverter.ToUInt32(bytesFirst, 0);
// if (value.Length > 2)
// {
// stringRaw = value.Substring(2);
// }
// }
// }
// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]
// private string stringRaw;
//}
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode, Size = 4100)]
internal struct NVDRS_SETTING_UNION
{
public uint dwordValue;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4100)]
public byte[] rawData;
//massive hack for marshalling issues with unicode string overlapping
public string stringValue
public byte[] binaryValue
{
get {
var firstPart = Encoding.Unicode.GetString(BitConverter.GetBytes(dwordValue)).Trim('\0');
return firstPart + stringRaw;
get
{
var length = BitConverter.ToUInt32(rawData, 0);
var tmpData = new byte[length];
Buffer.BlockCopy(rawData, 4, tmpData, 0, (int)length);
return tmpData;
}
set
{
var bytesRaw = Encoding.Unicode.GetBytes(value);
var bytesFirst = new byte[4];
var firstLength = bytesRaw.Length;
if (firstLength > 4)
firstLength = 4;
Buffer.BlockCopy(bytesRaw, 0, bytesFirst, 0, firstLength);
dwordValue = BitConverter.ToUInt32(bytesFirst, 0);
if (value.Length > 2)
rawData = new byte[4100];
if (value != null)
{
stringRaw = value.Substring(2);
Buffer.BlockCopy(BitConverter.GetBytes(value.Length), 0, rawData, 0, 4);
Buffer.BlockCopy(value, 0, rawData, 4, value.Length);
}
}
}
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]
private string stringRaw;
public uint dwordValue
{
get
{
return BitConverter.ToUInt32(rawData, 0);
}
set
{
rawData = new byte[4100];
Buffer.BlockCopy(BitConverter.GetBytes(value), 0, rawData, 0, 4);
}
}
public string stringValue
{
get
{
return Encoding.Unicode.GetString(rawData).Split(new[] { '\0' }, 2)[0];
}
set
{
rawData = new byte[4100];
var bytesRaw = Encoding.Unicode.GetBytes(value);
Buffer.BlockCopy(bytesRaw, 0, rawData, 0, bytesRaw.Length);
}
}
public string ansiStringValue
{
get
{
return Encoding.Default.GetString(rawData).Split(new[] { '\0' }, 2)[0];
}
set
{
rawData = new byte[4100];
var bytesRaw = Encoding.Default.GetBytes(value);
Buffer.BlockCopy(bytesRaw, 0, rawData, 0, bytesRaw.Length);
}
}
}

View File

@@ -23,84 +23,90 @@ namespace nspector
SafeNativeMethods.DeleteFile(Application.ExecutablePath + ":Zone.Identifier");
}
catch { }
#if RELEASE
try
{
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var argFileIndex = ArgFileIndex(args);
if (argFileIndex != -1)
{
if (args.Length == 1 && File.Exists(args[0]))
if (new FileInfo(args[argFileIndex]).Extension.ToLower() == ".nip")
{
if (new FileInfo(args[0]).Extension.ToLower() == ".nip")
try
{
try
var import = DrsServiceLocator.ImportService;
var importReport = import.ImportProfiles(args[argFileIndex]);
GC.Collect();
Process current = Process.GetCurrentProcess();
foreach (
Process process in
Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
{
var import = DrsServiceLocator.ImportService;
import.ImportProfiles(args[0]);
GC.Collect();
Process current = Process.GetCurrentProcess();
foreach (
Process process in
Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
{
if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
{
MessageHelper mh = new MessageHelper();
mh.sendWindowsStringMessage((int)process.MainWindowHandle, 0, "ProfilesImported");
}
MessageHelper mh = new MessageHelper();
mh.sendWindowsStringMessage((int)process.MainWindowHandle, 0, "ProfilesImported");
}
MessageBox.Show("Profile(s) successfully imported!", Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
if (string.IsNullOrEmpty(importReport) && !ArgExists(args, "-silentImport") && !ArgExists(args, "-silent"))
{
MessageBox.Show("Import Error: " + ex.Message, Application.ProductName + " Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
frmDrvSettings.ShowImportDoneMessage(importReport);
}
}
}
else if (ArgExists(args, "-createCSN"))
{
File.WriteAllText("CustomSettingNames.xml", Properties.Resources.CustomSettingNames);
}
else
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, Application.ProductName, out createdNew))
catch (Exception ex)
{
if (createdNew)
MessageBox.Show("Import Error: " + ex.Message, Application.ProductName + " Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else if (ArgExists(args, "-createCSN"))
{
File.WriteAllText("CustomSettingNames.xml", Properties.Resources.CustomSettingNames);
}
else
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, Application.ProductName, out createdNew))
{
if (createdNew)
{
Application.Run(new frmDrvSettings(ArgExists(args, "-showOnlyCSN"), ArgExists(args, "-disableScan")));
}
else
{
Process current = Process.GetCurrentProcess();
foreach (
Process process in
Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
{
Application.Run(new frmDrvSettings(ArgExists(args, "-showOnlyCSN"), ArgExists(args, "-disableScan")));
}
else
{
Process current = Process.GetCurrentProcess();
foreach (
Process process in
Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
{
if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
{
MessageHelper mh = new MessageHelper();
mh.bringAppToFront((int)process.MainWindowHandle);
}
MessageHelper mh = new MessageHelper();
mh.bringAppToFront((int)process.MainWindowHandle);
}
}
}
}
}
#if RELEASE
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace ,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endif
}
static bool ArgExists(string[] args, string arg)
{
foreach (string a in args)
@@ -110,5 +116,16 @@ namespace nspector
}
return false;
}
static int ArgFileIndex(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
if (File.Exists(args[i]))
return i;
}
return -1;
}
}
}

View File

@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NVIDIA Profile Inspector")]
[assembly: AssemblyCopyright("©2016 by Orbmu2k")]
[assembly: AssemblyCopyright("©2019 by Orbmu2k")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.1.2")]
[assembly: AssemblyFileVersion("2.1.1.2")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]

3902
nspector/Reference.xml Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@
</asmv2:trustInfo>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>false</dpiAware>
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View File

@@ -46,8 +46,9 @@
this.tssbRemoveApplication = new System.Windows.Forms.ToolStripSplitButton();
this.tsSep3 = new System.Windows.Forms.ToolStripSeparator();
this.tsbExportProfiles = new System.Windows.Forms.ToolStripSplitButton();
this.exportUserdefinedProfilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportCurrentProfileOnlyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportUserdefinedProfilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tsbImportProfiles = new System.Windows.Forms.ToolStripSplitButton();
this.importProfilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -90,10 +91,10 @@
//
this.pbMain.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pbMain.Location = new System.Drawing.Point(12, 692);
this.pbMain.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.pbMain.Location = new System.Drawing.Point(12, 475);
this.pbMain.Margin = new System.Windows.Forms.Padding(4);
this.pbMain.Name = "pbMain";
this.pbMain.Size = new System.Drawing.Size(883, 9);
this.pbMain.Size = new System.Drawing.Size(840, 9);
this.pbMain.TabIndex = 19;
//
// tsMain
@@ -134,7 +135,7 @@
this.tsMain.Location = new System.Drawing.Point(12, 4);
this.tsMain.Name = "tsMain";
this.tsMain.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
this.tsMain.Size = new System.Drawing.Size(883, 25);
this.tsMain.Size = new System.Drawing.Size(840, 25);
this.tsMain.TabIndex = 24;
this.tsMain.Text = "toolStrip1";
//
@@ -252,8 +253,9 @@
//
this.tsbExportProfiles.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.tsbExportProfiles.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exportUserdefinedProfilesToolStripMenuItem,
this.exportCurrentProfileOnlyToolStripMenuItem,
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem,
this.exportUserdefinedProfilesToolStripMenuItem,
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem});
this.tsbExportProfiles.Image = global::nspector.Properties.Resources.export1;
this.tsbExportProfiles.ImageTransparentColor = System.Drawing.Color.Magenta;
@@ -262,24 +264,31 @@
this.tsbExportProfiles.Text = "Export user defined profiles";
this.tsbExportProfiles.Click += new System.EventHandler(this.tsbExportProfiles_Click);
//
// exportUserdefinedProfilesToolStripMenuItem
//
this.exportUserdefinedProfilesToolStripMenuItem.Name = "exportUserdefinedProfilesToolStripMenuItem";
this.exportUserdefinedProfilesToolStripMenuItem.Size = new System.Drawing.Size(312, 22);
this.exportUserdefinedProfilesToolStripMenuItem.Text = "Export all customized profiles";
this.exportUserdefinedProfilesToolStripMenuItem.Click += new System.EventHandler(this.exportUserdefinedProfilesToolStripMenuItem_Click);
//
// exportCurrentProfileOnlyToolStripMenuItem
//
this.exportCurrentProfileOnlyToolStripMenuItem.Name = "exportCurrentProfileOnlyToolStripMenuItem";
this.exportCurrentProfileOnlyToolStripMenuItem.Size = new System.Drawing.Size(312, 22);
this.exportCurrentProfileOnlyToolStripMenuItem.Size = new System.Drawing.Size(342, 22);
this.exportCurrentProfileOnlyToolStripMenuItem.Text = "Export current profile only";
this.exportCurrentProfileOnlyToolStripMenuItem.Click += new System.EventHandler(this.exportCurrentProfileOnlyToolStripMenuItem_Click);
//
// exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem
//
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Name = "exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem";
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Size = new System.Drawing.Size(342, 22);
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Text = "Export current profile including predefined settings";
this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Click += new System.EventHandler(this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem_Click);
//
// exportUserdefinedProfilesToolStripMenuItem
//
this.exportUserdefinedProfilesToolStripMenuItem.Name = "exportUserdefinedProfilesToolStripMenuItem";
this.exportUserdefinedProfilesToolStripMenuItem.Size = new System.Drawing.Size(342, 22);
this.exportUserdefinedProfilesToolStripMenuItem.Text = "Export all customized profiles";
this.exportUserdefinedProfilesToolStripMenuItem.Click += new System.EventHandler(this.exportUserdefinedProfilesToolStripMenuItem_Click);
//
// exportAllProfilesNVIDIATextFormatToolStripMenuItem
//
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Name = "exportAllProfilesNVIDIATextFormatToolStripMenuItem";
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(312, 22);
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(342, 22);
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Text = "Export all driver profiles (NVIDIA Text Format)";
this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Click += new System.EventHandler(this.exportAllProfilesNVIDIATextFormatToolStripMenuItem_Click);
//
@@ -375,7 +384,7 @@
this.btnResetValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnResetValue.Enabled = false;
this.btnResetValue.Image = global::nspector.Properties.Resources.nv_btn;
this.btnResetValue.Location = new System.Drawing.Point(775, 175);
this.btnResetValue.Location = new System.Drawing.Point(732, 175);
this.btnResetValue.Margin = new System.Windows.Forms.Padding(0, 1, 0, 0);
this.btnResetValue.Name = "btnResetValue";
this.btnResetValue.Size = new System.Drawing.Size(25, 19);
@@ -393,7 +402,7 @@
this.lblApplications.Location = new System.Drawing.Point(12, 32);
this.lblApplications.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblApplications.Name = "lblApplications";
this.lblApplications.Size = new System.Drawing.Size(883, 17);
this.lblApplications.Size = new System.Drawing.Size(840, 17);
this.lblApplications.TabIndex = 25;
this.lblApplications.Text = "fsagame.exe, bond.exe, herozero.exe";
//
@@ -497,7 +506,7 @@
this.lvSettings.MultiSelect = false;
this.lvSettings.Name = "lvSettings";
this.lvSettings.ShowItemToolTips = true;
this.lvSettings.Size = new System.Drawing.Size(883, 635);
this.lvSettings.Size = new System.Drawing.Size(840, 418);
this.lvSettings.SmallImageList = this.ilListView;
this.lvSettings.TabIndex = 2;
this.lvSettings.UseCompatibleStateImageBehavior = false;
@@ -505,6 +514,7 @@
this.lvSettings.ColumnWidthChanging += new System.Windows.Forms.ColumnWidthChangingEventHandler(this.lvSettings_ColumnWidthChanging);
this.lvSettings.SelectedIndexChanged += new System.EventHandler(this.lvSettings_SelectedIndexChanged);
this.lvSettings.DoubleClick += new System.EventHandler(this.lvSettings_DoubleClick);
this.lvSettings.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvSettings_KeyDown);
this.lvSettings.Resize += new System.EventHandler(this.lvSettings_Resize);
//
// chSettingID
@@ -526,7 +536,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(907, 709);
this.ClientSize = new System.Drawing.Size(864, 492);
this.Controls.Add(this.lblWidth30);
this.Controls.Add(this.lblWidth16);
this.Controls.Add(this.lblWidth330);
@@ -537,8 +547,8 @@
this.Controls.Add(this.pbMain);
this.Controls.Add(this.btnResetValue);
this.Controls.Add(this.cbValues);
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.MinimumSize = new System.Drawing.Size(920, 348);
this.Margin = new System.Windows.Forms.Padding(4);
this.MinimumSize = new System.Drawing.Size(880, 348);
this.Name = "frmDrvSettings";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "nSpector - Driver Profile Settings";
@@ -597,5 +607,6 @@
private System.Windows.Forms.Label lblWidth330;
private System.Windows.Forms.Label lblWidth16;
private System.Windows.Forms.Label lblWidth30;
private System.Windows.Forms.ToolStripMenuItem exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem;
}
}

View File

@@ -29,7 +29,6 @@ namespace nspector
private List<SettingItem> _currentProfileSettingItems = new List<SettingItem>();
private bool _alreadyScannedForPredefinedSettings = false;
private IntPtr _taskbarParent = IntPtr.Zero;
private bool _showCustomSettingsOnly = false;
private bool _activated = false;
private bool _isStartup = true;
private bool _skipScan = false;
@@ -210,7 +209,7 @@ namespace nspector
cbValues.Tag = lvSettings.SelectedItems[0].Tag;
uint settingid = (uint)lvSettings.SelectedItems[0].Tag;
var settingMeta = _meta.GetSettingMeta(settingid);
var settingMeta = _meta.GetSettingMeta(settingid, GetSettingViewMode());
if (settingMeta != null)
{
if (settingMeta.SettingType == Native.NVAPI2.NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE && settingMeta.DwordValues != null)
@@ -236,6 +235,13 @@ namespace nspector
cbValues.Items.Add(v);
}
if (settingMeta.SettingType == Native.NVAPI2.NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE && settingMeta.BinaryValues != null)
{
var valueNames = settingMeta.BinaryValues.Select(x => x.ValueName).ToList();
foreach (string v in valueNames)
cbValues.Items.Add(v);
}
var scannedCount = settingMeta?.DwordValues?
.Where(x => x.ValueSource == Common.Meta.SettingMetaSource.ScannedSettings)
.Count();
@@ -310,7 +316,7 @@ namespace nspector
{
var lvItem = lvSettings.Items[idx];
var settingMeta = _meta.GetSettingMeta(settingId);
var settingMeta = _meta.GetSettingMeta(settingId, GetSettingViewMode());
var currentProfileItem = _currentProfileSettingItems
.First(x => x.SettingId.Equals(settingId));
@@ -338,11 +344,16 @@ namespace nspector
lvItem.SubItems[2].Text = DrsUtil.GetDwordString(DrsUtil.ParseDwordSettingValue(settingMeta, cbValueText));
lvItem.SubItems[1].Text = cbValueText;
}
else
else if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE)
{
lvItem.SubItems[2].Text = DrsUtil.ParseStringSettingValue(settingMeta, cbValueText); // DrsUtil.StringValueRaw;
lvItem.SubItems[1].Text = cbValueText;
}
else if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE)
{
lvItem.SubItems[2].Text = DrsUtil.GetBinaryString(DrsUtil.ParseBinarySettingValue(settingMeta, cbValueText)); // DrsUtil.StringValueRaw;
lvItem.SubItems[1].Text = cbValueText;
}
}
}
@@ -482,7 +493,7 @@ namespace nspector
SetupToolbar();
SetupDpiAdjustments();
_showCustomSettingsOnly = showCsnOnly;
tscbShowCustomSettingNamesOnly.Checked = showCsnOnly;
Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
}
@@ -520,7 +531,13 @@ namespace nspector
_scanner.ModifiedProfiles.Sort();
foreach (string modProfile in _scanner.ModifiedProfiles)
if (modProfile != _baseProfileName)
tsbModifiedProfiles.DropDownItems.Add(modProfile);
{
var newItem = tsbModifiedProfiles.DropDownItems.Add(modProfile);
if (!_scanner.UserProfiles.Contains(modProfile))
{
newItem.Image = tsbRestoreProfile.Image;
}
}
if (tsbModifiedProfiles.DropDownItems.Count > 0)
tsbModifiedProfiles.Enabled = true;
@@ -616,8 +633,13 @@ namespace nspector
}
}
private void AddToModifiedProfiles(string profileName)
private void AddToModifiedProfiles(string profileName, bool userProfile = false)
{
if (!_scanner.UserProfiles.Contains(profileName) && profileName != _baseProfileName && userProfile)
{
_scanner.UserProfiles.Add(profileName);
}
if (!_scanner.ModifiedProfiles.Contains(profileName) && profileName != _baseProfileName)
{
_scanner.ModifiedProfiles.Add(profileName);
@@ -627,6 +649,11 @@ namespace nspector
private void RemoveFromModifiedProfiles(string profileName)
{
if (_scanner.UserProfiles.Contains(profileName))
{
_scanner.UserProfiles.Remove(profileName);
}
if (_scanner.ModifiedProfiles.Contains(profileName))
{
_scanner.ModifiedProfiles.Remove(profileName);
@@ -920,7 +947,7 @@ namespace nspector
}
catch (NvapiException ex)
{
if (ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE)
if (ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE || ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_ERROR)
{
if (lblApplications.Text.ToUpper().IndexOf(" " + applicationName.ToUpper() + ",") != -1)
MessageBox.Show("This application executable is already assigned to this profile!",
@@ -929,7 +956,7 @@ namespace nspector
{
string profileNames = _scanner.FindProfilesUsingApplication(applicationName);
if (profileNames == "")
MessageBox.Show("This application executable is already assigned to another profile!",
MessageBox.Show("This application executable might already be assigned to another profile!",
"Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
MessageBox.Show(
@@ -978,7 +1005,7 @@ namespace nspector
_drs.CreateProfile(result, applicationName);
RefreshProfilesCombo();
cbProfiles.SelectedIndex = cbProfiles.Items.IndexOf(result);
AddToModifiedProfiles(result);
AddToModifiedProfiles(result, true);
}
catch (NvapiException ex)
{
@@ -1003,18 +1030,29 @@ namespace nspector
ScanProfilesSilent(false, true);
}
private void exportCurrentProfileOnlyToolStripMenuItem_Click(object sender, EventArgs e)
private void ExportCurrentProfile(bool includePredefined)
{
var saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "*.nip";
saveDialog.Filter = Application.ProductName + " Profiles|*.nip";
saveDialog.FileName = _CurrentProfile + ".nip";
if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var profiles = new[] { _CurrentProfile }.ToList();
_import.ExportProfiles(profiles, saveDialog.FileName, false);
_import.ExportProfiles(profiles, saveDialog.FileName, includePredefined);
}
}
private void exportCurrentProfileOnlyToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportCurrentProfile(false);
}
private void exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportCurrentProfile(true);
}
private void tssbRemoveApplication_Click(object sender, EventArgs e)
{
if (tssbRemoveApplication.DropDown.Items.Count > 0)
@@ -1094,9 +1132,7 @@ namespace nspector
openDialog.Filter = Application.ProductName + " Profiles|*.nip";
if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_import.ImportProfiles(openDialog.FileName);
RefreshAll();
MessageBox.Show("Profile(s) successfully imported!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
ImportProfiles(openDialog.FileName);
}
}
@@ -1110,32 +1146,25 @@ namespace nspector
cbProfiles.Select(cbProfiles.Text.Length, 0);
}
}
private string ResolveExecuteable(string filename, out string profileName)
public static void ShowImportDoneMessage(string importReport)
{
var fileInfo = new FileInfo(filename);
profileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
if (fileInfo.Extension.ToLower().Equals(".lnk"))
if (string.IsNullOrEmpty(importReport))
{
try
{
var shellLink = new ShellLink(filename);
var targetInfo = new FileInfo(shellLink.Target);
if (targetInfo.Extension.ToLower().Equals(".exe"))
return targetInfo.Name;
return "";
}
catch
{
return "";
}
MessageBox.Show("Profile(s) successfully imported!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Some profile(s) could not imported!\r\n\r\n" + importReport, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
if (fileInfo.Extension.ToLower().Equals(".exe"))
return fileInfo.Name;
return "";
private void ImportProfiles(string nipFileName)
{
var importReport = _import.ImportProfiles(nipFileName);
RefreshAll();
ShowImportDoneMessage(importReport);
}
private void lvSettings_OnDropFilesNative(string[] files)
@@ -1145,15 +1174,13 @@ namespace nspector
var fileInfo = new FileInfo(files[0]);
if (fileInfo.Extension.ToLower().Equals(".nip"))
{
_import.ImportProfiles(fileInfo.FullName);
RefreshAll();
MessageBox.Show("Profile(s) successfully imported!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
ImportProfiles(fileInfo.FullName);
return;
}
var profileName = "";
var exeFile = ResolveExecuteable(files[0], out profileName);
var exeFile = ShortcutResolver.ResolveExecuteable(files[0], out profileName);
if (exeFile != "")
{
var profiles = _scanner.FindProfilesUsingApplication(exeFile);
@@ -1188,6 +1215,11 @@ namespace nspector
Clipboard.SetText(string.Format($"0x{settingId:X8} {settingName}"));
}
}
private void lvSettings_KeyDown(object sender, KeyEventArgs e)
{
}
}
}

View File

@@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADI
DAAAAk1TRnQBSQFMAgEBBAEAAWgBBwFoAQcBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA
DAAAAk1TRnQBSQFMAgEBBAEAAZABBwGQAQcBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABIAMAAQEBAAEYBgABGP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/ADMAAcgBvQGvAacBkQF5BgAD/iEA
A+QD2gYAA/4hAAGXAcMBqwFMAZwBcAYAA/4hAAOmA2gGAAP+FQAB8gHxAfABqQGPAXQBzwHHAbwD/wG6
AaUBjAGuAZQBeAHxAe8B7QHvAe0B6wGhAYgBbQHkAeAB2xIAA/UD3QPmA/8D4APeA/QD8wPaA+4SAAHt
@@ -285,7 +285,4 @@
<metadata name="lvSettings.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@@ -129,12 +129,17 @@
<ItemGroup>
<Compile Include="Common\CustomSettings\CustomSetting.cs" />
<Compile Include="Common\CustomSettings\CustomSettingValue.cs" />
<Compile Include="Common\DrsDecrypterService.cs" />
<Compile Include="Common\DrsScannerService.cs" />
<Compile Include="Common\DrsServiceLocator.cs" />
<Compile Include="Common\DrsSessionScope.cs" />
<Compile Include="Common\DrsSettingsMetaService.cs" />
<Compile Include="Common\DrsUtil.cs" />
<Compile Include="Common\Helper\ListViewGroupSorter.cs" />
<Compile Include="Common\Helper\ShortcutResolver.cs" />
<Compile Include="Common\Helper\SteamAppResolver.cs" />
<Compile Include="Common\Import\ImportExportUitl.cs" />
<Compile Include="Common\Import\SettingValueType.cs" />
<Compile Include="Common\Meta\NvD3dUmxSettingMetaService.cs" />
<Compile Include="Common\Meta\MetaServiceItem.cs" />
<Compile Include="Common\Meta\ConstantSettingMetaService.cs" />
@@ -235,6 +240,9 @@
<SubType>Designer</SubType>
</Content>
<Content Include="Native\NVAPI\NvApiDriverSettings.h" />
<Content Include="Reference.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Images\transparent16.png" />
<None Include="Images\n1-016.png" />
<None Include="Images\0_gear2.png" />