Broken, some garbage errors or something

This commit is contained in:
Garry Newman 2016-09-29 16:07:59 +01:00
parent 14b426b48a
commit b509b92b38
3 changed files with 151 additions and 1 deletions

View File

@ -306,7 +306,9 @@ public void Rules()
for ( int i = 0; i < 1000; i++ )
{
GC.Collect();
client.Update();
GC.Collect();
System.Threading.Thread.Sleep( 10 );
if ( query.Responded.Count > 20 )
@ -320,13 +322,17 @@ public void Rules()
foreach ( var server in query.Responded.Take( 20 ) )
{
GC.Collect();
server.FetchRules();
GC.Collect();
int i = 0;
while ( !server.HasRules )
{
i++;
GC.Collect();
client.Update();
GC.Collect();
System.Threading.Thread.Sleep( 2 );
if ( i > 100 )

View File

@ -119,6 +119,7 @@
<Compile Include="Client.ServerList.Request.cs" />
<Compile Include="Client.Auth.cs" />
<Compile Include="Client.cs" />
<Compile Include="Client.ServerList.Server.cs" />
<Compile Include="Client\App.cs" />
<Compile Include="Client\Friends.cs" />
<Compile Include="Client\Image.cs" />
@ -126,10 +127,11 @@
<Compile Include="Client\Screenshots.cs" />
<Compile Include="Client\Stats.cs" />
<Compile Include="Client\Voice.cs" />
<Compile Include="Interop\ServerRules.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
<Compile Include="steam_api_interop.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>

View File

@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Facepunch.Steamworks.Interop
{
class ServerRules
{
private GCHandle thisPin;
private IntPtr vTablePtr;
private GCHandle vTableHandle;
private ServerList.Server Server;
public ServerRules( ServerList.Server server, uint address, int queryPort )
{
Server = server;
InstallVTable();
Valve.Interop.NativeEntrypoints.SteamAPI_ISteamMatchmakingServers_ServerRules( Server.Client.native.servers.GetIntPtr(), address, (short) queryPort, GetPtr() );
}
void InstallVTable()
{
GC.KeepAlive( Server );
GC.SuppressFinalize( Server );
if ( Server.Client.UseThisCall )
{
var t = new ThisVTable()
{
m_VTRulesResponded = ( _, k, v ) => InternalOnRulesResponded( k, v ),
m_VTRulesFailedToRespond = ( _ ) => InternalOnRulesFailedToRespond(),
m_VTRulesRefreshComplete = ( _ ) => InternalOnRulesRefreshComplete(),
};
vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( ThisVTable ) ) );
Marshal.StructureToPtr( t, vTablePtr, false );
vTableHandle = GCHandle.Alloc( vTablePtr, GCHandleType.Pinned );
}
else
{
var t = new StdVTable()
{
m_VTRulesResponded = InternalOnRulesResponded,
m_VTRulesFailedToRespond = InternalOnRulesFailedToRespond,
m_VTRulesRefreshComplete = InternalOnRulesRefreshComplete
};
vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( StdVTable ) ) );
Marshal.StructureToPtr( t, vTablePtr, false );
vTableHandle = GCHandle.Alloc( vTablePtr, GCHandleType.Pinned );
}
}
void Unpin()
{
if ( vTablePtr != IntPtr.Zero )
{
Marshal.FreeHGlobal( vTablePtr );
}
if ( vTableHandle.IsAllocated )
{
vTableHandle.Free();
}
if ( thisPin.IsAllocated )
{
thisPin.Free();
}
}
private void InternalOnRulesResponded( IntPtr k, IntPtr v )
{
// Server.Rules.Add( k, v );
}
private void InternalOnRulesFailedToRespond()
{
Server.OnServerRulesReceiveFinished( false );
}
private void InternalOnRulesRefreshComplete()
{
Server.OnServerRulesReceiveFinished( true );
}
[StructLayout( LayoutKind.Sequential )]
private class StdVTable
{
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesResponded m_VTRulesResponded;
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesFailedToRespond m_VTRulesFailedToRespond;
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesRefreshComplete m_VTRulesRefreshComplete;
[UnmanagedFunctionPointer( CallingConvention.StdCall )]
public delegate void InternalRulesResponded( IntPtr pchRule, IntPtr pchValue );
[UnmanagedFunctionPointer( CallingConvention.StdCall )]
public delegate void InternalRulesFailedToRespond();
[UnmanagedFunctionPointer( CallingConvention.StdCall )]
public delegate void InternalRulesRefreshComplete();
}
[StructLayout( LayoutKind.Sequential )]
private class ThisVTable
{
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesResponded m_VTRulesResponded;
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesFailedToRespond m_VTRulesFailedToRespond;
[NonSerialized]
[MarshalAs(UnmanagedType.FunctionPtr)]
public InternalRulesRefreshComplete m_VTRulesRefreshComplete;
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
public delegate void InternalRulesResponded( IntPtr thisptr, IntPtr pchRule, IntPtr pchValue );
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
public delegate void InternalRulesFailedToRespond( IntPtr thisptr );
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
public delegate void InternalRulesRefreshComplete( IntPtr thisptr );
}
public System.IntPtr GetPtr()
{
return vTableHandle.AddrOfPinnedObject();
}
};
}