mirror of
https://github.com/JDM170/SteamAchievementManager
synced 2025-12-10 05:37:18 +07:00
Properly handle encoding of strings in Steam API. Fixes #5.
This commit is contained in:
141
SAM.API/NativeStrings.cs
Normal file
141
SAM.API/NativeStrings.cs
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/* Copyright (c) 2017 Rick (rick 'at' gibbed 'dot' us)
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would
|
||||||
|
* be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not
|
||||||
|
* be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Win32.SafeHandles;
|
||||||
|
|
||||||
|
namespace SAM.API
|
||||||
|
{
|
||||||
|
internal class NativeStrings
|
||||||
|
{
|
||||||
|
public sealed class StringHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||||
|
{
|
||||||
|
internal StringHandle(IntPtr preexistingHandle, bool ownsHandle)
|
||||||
|
: base(ownsHandle)
|
||||||
|
{
|
||||||
|
this.SetHandle(preexistingHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr Handle
|
||||||
|
{
|
||||||
|
get { return this.handle; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ReleaseHandle()
|
||||||
|
{
|
||||||
|
if (handle != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
Marshal.FreeHGlobal(handle);
|
||||||
|
handle = IntPtr.Zero;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe StringHandle StringToStringHandle(string value)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
return new StringHandle(IntPtr.Zero, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = Encoding.UTF8.GetBytes(value);
|
||||||
|
var length = bytes.Length;
|
||||||
|
|
||||||
|
var p = Marshal.AllocHGlobal(length + 1);
|
||||||
|
Marshal.Copy(bytes, 0, p, bytes.Length);
|
||||||
|
((byte*)p)[length] = 0;
|
||||||
|
return new StringHandle(p, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(sbyte* bytes)
|
||||||
|
{
|
||||||
|
if (bytes == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int running = 0;
|
||||||
|
|
||||||
|
var b = bytes;
|
||||||
|
if (*b == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((*b++) != 0)
|
||||||
|
{
|
||||||
|
running++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(bytes, 0, running, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(byte* bytes)
|
||||||
|
{
|
||||||
|
return PointerToString((sbyte*)bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(IntPtr nativeData)
|
||||||
|
{
|
||||||
|
return PointerToString((sbyte*)nativeData.ToPointer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(sbyte* bytes, int length)
|
||||||
|
{
|
||||||
|
if (bytes == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int running = 0;
|
||||||
|
|
||||||
|
var b = bytes;
|
||||||
|
if (length == 0 || *b == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((*b++) != 0 &&
|
||||||
|
running < length)
|
||||||
|
{
|
||||||
|
running++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(bytes, 0, running, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(byte* bytes, int length)
|
||||||
|
{
|
||||||
|
return PointerToString((sbyte*)bytes, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe string PointerToString(IntPtr nativeData, int length)
|
||||||
|
{
|
||||||
|
return PointerToString((sbyte*)nativeData.ToPointer(), length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
@@ -50,6 +51,7 @@
|
|||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@@ -69,6 +71,7 @@
|
|||||||
<Compile Include="Callbacks\AppDataChanged.cs" />
|
<Compile Include="Callbacks\AppDataChanged.cs" />
|
||||||
<Compile Include="Callbacks\UserStatsReceived.cs" />
|
<Compile Include="Callbacks\UserStatsReceived.cs" />
|
||||||
<Compile Include="ICallback.cs" />
|
<Compile Include="ICallback.cs" />
|
||||||
|
<Compile Include="NativeStrings.cs" />
|
||||||
<Compile Include="Types\CallbackMessage.cs" />
|
<Compile Include="Types\CallbackMessage.cs" />
|
||||||
<Compile Include="Wrappers\SteamUserStats007.cs" />
|
<Compile Include="Wrappers\SteamUserStats007.cs" />
|
||||||
<Compile Include="Types\AccountType.cs" />
|
<Compile Include="Types\AccountType.cs" />
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using SAM.API.Interfaces;
|
using SAM.API.Interfaces;
|
||||||
|
|
||||||
namespace SAM.API.Wrappers
|
namespace SAM.API.Wrappers
|
||||||
@@ -34,22 +33,27 @@ namespace SAM.API.Wrappers
|
|||||||
private delegate int NativeGetAppData(
|
private delegate int NativeGetAppData(
|
||||||
IntPtr self,
|
IntPtr self,
|
||||||
uint appId,
|
uint appId,
|
||||||
string key,
|
IntPtr key,
|
||||||
StringBuilder valueBuffer,
|
IntPtr value,
|
||||||
int valueLength);
|
int valueLength);
|
||||||
|
|
||||||
public string GetAppData(uint appId, string key)
|
public string GetAppData(uint appId, string key)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
using (var nativeHandle = NativeStrings.StringToStringHandle(key))
|
||||||
sb.EnsureCapacity(1024);
|
{
|
||||||
|
const int valueLength = 1024;
|
||||||
|
var valuePointer = Marshal.AllocHGlobal(valueLength);
|
||||||
int result = this.Call<int, NativeGetAppData>(
|
int result = this.Call<int, NativeGetAppData>(
|
||||||
this.Functions.GetAppData,
|
this.Functions.GetAppData,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
appId,
|
appId,
|
||||||
key,
|
nativeHandle.Handle,
|
||||||
sb,
|
valuePointer,
|
||||||
sb.Capacity);
|
valueLength);
|
||||||
return result == 0 ? null : sb.ToString();
|
var value = result == 0 ? null : NativeStrings.PointerToString(valuePointer, valueLength);
|
||||||
|
Marshal.FreeHGlobal(valuePointer);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace SAM.API.Wrappers
|
|||||||
var languagePointer = this.Call<IntPtr, NativeGetCurrentGameLanguage>(
|
var languagePointer = this.Call<IntPtr, NativeGetCurrentGameLanguage>(
|
||||||
this.Functions.GetCurrentGameLanguage,
|
this.Functions.GetCurrentGameLanguage,
|
||||||
this.ObjectAddress);
|
this.ObjectAddress);
|
||||||
return Marshal.PtrToStringAnsi(languagePointer);
|
return NativeStrings.PointerToString(languagePointer);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,21 +95,24 @@ namespace SAM.API.Wrappers
|
|||||||
|
|
||||||
#region GetISteamUser
|
#region GetISteamUser
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate IntPtr NativeGetISteamUser(IntPtr self, int user, int pipe, string version);
|
private delegate IntPtr NativeGetISteamUser(IntPtr self, int user, int pipe, IntPtr version);
|
||||||
|
|
||||||
private TClass GetISteamUser<TClass>(int user, int pipe, string version)
|
private TClass GetISteamUser<TClass>(int user, int pipe, string version)
|
||||||
where TClass : INativeWrapper, new()
|
where TClass : INativeWrapper, new()
|
||||||
|
{
|
||||||
|
using (var nativeVersion = NativeStrings.StringToStringHandle(version))
|
||||||
{
|
{
|
||||||
IntPtr address = this.Call<IntPtr, NativeGetISteamUser>(
|
IntPtr address = this.Call<IntPtr, NativeGetISteamUser>(
|
||||||
this.Functions.GetISteamUser,
|
this.Functions.GetISteamUser,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
user,
|
user,
|
||||||
pipe,
|
pipe,
|
||||||
version);
|
nativeVersion.Handle);
|
||||||
var result = new TClass();
|
var result = new TClass();
|
||||||
result.SetupFunctions(address);
|
result.SetupFunctions(address);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetSteamUser012
|
#region GetSteamUser012
|
||||||
@@ -121,21 +124,24 @@ namespace SAM.API.Wrappers
|
|||||||
|
|
||||||
#region GetISteamUserStats
|
#region GetISteamUserStats
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate IntPtr NativeGetISteamUserStats(IntPtr self, int user, int pipe, string version);
|
private delegate IntPtr NativeGetISteamUserStats(IntPtr self, int user, int pipe, IntPtr version);
|
||||||
|
|
||||||
private TClass GetISteamUserStats<TClass>(int user, int pipe, string version)
|
private TClass GetISteamUserStats<TClass>(int user, int pipe, string version)
|
||||||
where TClass : INativeWrapper, new()
|
where TClass : INativeWrapper, new()
|
||||||
|
{
|
||||||
|
using (var nativeVersion = NativeStrings.StringToStringHandle(version))
|
||||||
{
|
{
|
||||||
IntPtr address = this.Call<IntPtr, NativeGetISteamUserStats>(
|
IntPtr address = this.Call<IntPtr, NativeGetISteamUserStats>(
|
||||||
this.Functions.GetISteamUserStats,
|
this.Functions.GetISteamUserStats,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
user,
|
user,
|
||||||
pipe,
|
pipe,
|
||||||
version);
|
nativeVersion.Handle);
|
||||||
var result = new TClass();
|
var result = new TClass();
|
||||||
result.SetupFunctions(address);
|
result.SetupFunctions(address);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetSteamUserStats007
|
#region GetSteamUserStats007
|
||||||
@@ -147,20 +153,23 @@ namespace SAM.API.Wrappers
|
|||||||
|
|
||||||
#region GetISteamUtils
|
#region GetISteamUtils
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate IntPtr NativeGetISteamUtils(IntPtr self, int pipe, string version);
|
private delegate IntPtr NativeGetISteamUtils(IntPtr self, int pipe, IntPtr version);
|
||||||
|
|
||||||
public TClass GetISteamUtils<TClass>(int pipe, string version)
|
public TClass GetISteamUtils<TClass>(int pipe, string version)
|
||||||
where TClass : INativeWrapper, new()
|
where TClass : INativeWrapper, new()
|
||||||
|
{
|
||||||
|
using (var nativeVersion = NativeStrings.StringToStringHandle(version))
|
||||||
{
|
{
|
||||||
IntPtr address = this.Call<IntPtr, NativeGetISteamUtils>(
|
IntPtr address = this.Call<IntPtr, NativeGetISteamUtils>(
|
||||||
this.Functions.GetISteamUtils,
|
this.Functions.GetISteamUtils,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
pipe,
|
pipe,
|
||||||
version);
|
nativeVersion.Handle);
|
||||||
var result = new TClass();
|
var result = new TClass();
|
||||||
result.SetupFunctions(address);
|
result.SetupFunctions(address);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetSteamUtils004
|
#region GetSteamUtils004
|
||||||
@@ -171,16 +180,23 @@ namespace SAM.API.Wrappers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetISteamApps
|
#region GetISteamApps
|
||||||
private delegate IntPtr NativeGetISteamApps(int user, int pipe, string version);
|
private delegate IntPtr NativeGetISteamApps(int user, int pipe, IntPtr version);
|
||||||
|
|
||||||
private TClass GetISteamApps<TClass>(int user, int pipe, string version)
|
private TClass GetISteamApps<TClass>(int user, int pipe, string version)
|
||||||
where TClass : INativeWrapper, new()
|
where TClass : INativeWrapper, new()
|
||||||
{
|
{
|
||||||
IntPtr address = this.Call<IntPtr, NativeGetISteamApps>(this.Functions.GetISteamApps, user, pipe, version);
|
using (var nativeVersion = NativeStrings.StringToStringHandle(version))
|
||||||
|
{
|
||||||
|
IntPtr address = this.Call<IntPtr, NativeGetISteamApps>(
|
||||||
|
this.Functions.GetISteamApps,
|
||||||
|
user,
|
||||||
|
pipe,
|
||||||
|
nativeVersion.Handle);
|
||||||
var result = new TClass();
|
var result = new TClass();
|
||||||
result.SetupFunctions(address);
|
result.SetupFunctions(address);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetSteamApps001
|
#region GetSteamApps001
|
||||||
|
|||||||
@@ -42,55 +42,67 @@ namespace SAM.API.Wrappers
|
|||||||
#region GetStatValue (int)
|
#region GetStatValue (int)
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeGetStatInt(IntPtr self, string name, out int data);
|
private delegate bool NativeGetStatInt(IntPtr self, IntPtr name, out int data);
|
||||||
|
|
||||||
public bool GetStatValue(string name, out int value)
|
public bool GetStatValue(string name, out int value)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
var call = this.GetFunction<NativeGetStatInt>(this.Functions.GetStatInteger);
|
var call = this.GetFunction<NativeGetStatInt>(this.Functions.GetStatInteger);
|
||||||
return call(this.ObjectAddress, name, out value);
|
return call(this.ObjectAddress, nativeName.Handle, out value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetStatValue (float)
|
#region GetStatValue (float)
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeGetStatFloat(IntPtr self, string name, out float data);
|
private delegate bool NativeGetStatFloat(IntPtr self, IntPtr name, out float data);
|
||||||
|
|
||||||
public bool GetStatValue(string name, out float value)
|
public bool GetStatValue(string name, out float value)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
var call = this.GetFunction<NativeGetStatFloat>(this.Functions.GetStatFloat);
|
var call = this.GetFunction<NativeGetStatFloat>(this.Functions.GetStatFloat);
|
||||||
return call(this.ObjectAddress, name, out value);
|
return call(this.ObjectAddress, nativeName.Handle, out value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SetStatValue (int)
|
#region SetStatValue (int)
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeSetStatInt(IntPtr self, string name, int data);
|
private delegate bool NativeSetStatInt(IntPtr self, IntPtr name, int data);
|
||||||
|
|
||||||
public bool SetStatValue(string name, int value)
|
public bool SetStatValue(string name, int value)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
return this.Call<bool, NativeSetStatInt>(
|
return this.Call<bool, NativeSetStatInt>(
|
||||||
this.Functions.SetStatInteger,
|
this.Functions.SetStatInteger,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
name,
|
nativeName.Handle,
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SetStatValue (float)
|
#region SetStatValue (float)
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeSetStatFloat(IntPtr self, string name, float data);
|
private delegate bool NativeSetStatFloat(IntPtr self, IntPtr name, float data);
|
||||||
|
|
||||||
public bool SetStatValue(string name, float value)
|
public bool SetStatValue(string name, float value)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
return this.Call<bool, NativeSetStatFloat>(
|
return this.Call<bool, NativeSetStatFloat>(
|
||||||
this.Functions.SetStatFloat,
|
this.Functions.SetStatFloat,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
name,
|
nativeName.Handle,
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetAchievement
|
#region GetAchievement
|
||||||
@@ -98,33 +110,45 @@ namespace SAM.API.Wrappers
|
|||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeGetAchievement(
|
private delegate bool NativeGetAchievement(
|
||||||
IntPtr self,
|
IntPtr self,
|
||||||
string name,
|
IntPtr name,
|
||||||
[MarshalAs(UnmanagedType.I1)] out bool isAchieved);
|
[MarshalAs(UnmanagedType.I1)] out bool isAchieved);
|
||||||
|
|
||||||
public bool GetAchievementState(string name, out bool isAchieved)
|
public bool GetAchievementState(string name, out bool isAchieved)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
var call = this.GetFunction<NativeGetAchievement>(this.Functions.GetAchievement);
|
var call = this.GetFunction<NativeGetAchievement>(this.Functions.GetAchievement);
|
||||||
return call(this.ObjectAddress, name, out isAchieved);
|
return call(this.ObjectAddress, nativeName.Handle, out isAchieved);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SetAchievementState
|
#region SetAchievementState
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeSetAchievement(IntPtr self, string name);
|
private delegate bool NativeSetAchievement(IntPtr self, IntPtr name);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
[return: MarshalAs(UnmanagedType.I1)]
|
||||||
private delegate bool NativeClearAchievement(IntPtr self, string name);
|
private delegate bool NativeClearAchievement(IntPtr self, IntPtr name);
|
||||||
|
|
||||||
public bool SetAchievement(string name, bool state)
|
public bool SetAchievement(string name, bool state)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
if (state == false)
|
if (state == false)
|
||||||
{
|
{
|
||||||
return this.Call<bool, NativeClearAchievement>(this.Functions.ClearAchievement, this.ObjectAddress, name);
|
return this.Call<bool, NativeClearAchievement>(
|
||||||
|
this.Functions.ClearAchievement,
|
||||||
|
this.ObjectAddress,
|
||||||
|
nativeName.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.Call<bool, NativeSetAchievement>(this.Functions.SetAchievement, this.ObjectAddress, name);
|
return this.Call<bool, NativeSetAchievement>(
|
||||||
|
this.Functions.SetAchievement,
|
||||||
|
this.ObjectAddress,
|
||||||
|
nativeName.Handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -141,28 +165,36 @@ namespace SAM.API.Wrappers
|
|||||||
|
|
||||||
#region GetAchievementIcon
|
#region GetAchievementIcon
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate int NativeGetAchievementIcon(IntPtr self, string name);
|
private delegate int NativeGetAchievementIcon(IntPtr self, IntPtr name);
|
||||||
|
|
||||||
public int GetAchievementIcon(string name)
|
public int GetAchievementIcon(string name)
|
||||||
|
{
|
||||||
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
{
|
{
|
||||||
return this.Call<int, NativeGetAchievementIcon>(
|
return this.Call<int, NativeGetAchievementIcon>(
|
||||||
this.Functions.GetAchievementIcon,
|
this.Functions.GetAchievementIcon,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
name);
|
nativeName.Handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetAchievementDisplayAttribute
|
#region GetAchievementDisplayAttribute
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate string NativeGetAchievementDisplayAttribute(IntPtr self, string name, string key);
|
private delegate IntPtr NativeGetAchievementDisplayAttribute(IntPtr self, IntPtr name, IntPtr key);
|
||||||
|
|
||||||
public string GetAchievementDisplayAttribute(string name, string key)
|
public string GetAchievementDisplayAttribute(string name, string key)
|
||||||
{
|
{
|
||||||
return this.Call<string, NativeGetAchievementDisplayAttribute>(
|
using (var nativeName = NativeStrings.StringToStringHandle(name))
|
||||||
|
using (var nativeKey = NativeStrings.StringToStringHandle(key))
|
||||||
|
{
|
||||||
|
var result = this.Call<IntPtr, NativeGetAchievementDisplayAttribute>(
|
||||||
this.Functions.GetAchievementDisplayAttribute,
|
this.Functions.GetAchievementDisplayAttribute,
|
||||||
this.ObjectAddress,
|
this.ObjectAddress,
|
||||||
name,
|
nativeName.Handle,
|
||||||
key);
|
nativeKey.Handle);
|
||||||
|
return NativeStrings.PointerToString(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ namespace SAM.API.Wrappers
|
|||||||
|
|
||||||
#region GetIPCountry
|
#region GetIPCountry
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate string NativeGetIPCountry(IntPtr self);
|
private delegate IntPtr NativeGetIPCountry(IntPtr self);
|
||||||
|
|
||||||
public string GetIPCountry()
|
public string GetIPCountry()
|
||||||
{
|
{
|
||||||
return this.Call<string, NativeGetIPCountry>(this.Functions.GetIPCountry, this.ObjectAddress);
|
var result = this.Call<IntPtr, NativeGetIPCountry>(this.Functions.GetIPCountry, this.ObjectAddress);
|
||||||
|
return NativeStrings.PointerToString(result);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user