Skip to content

Commit

Permalink
Removed Profile Link
Browse files Browse the repository at this point in the history
Dynamically reads .replayinfo
Dynamically shows teammates
  • Loading branch information
EpicKitten committed Feb 2, 2018
1 parent 8505ced commit adf94f7
Show file tree
Hide file tree
Showing 66 changed files with 2,250 additions and 12,082 deletions.
4 changes: 4 additions & 0 deletions PUBG_Replay_Manager/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
1,039 changes: 524 additions & 515 deletions PUBG_Replay_Manager/Main.Designer.cs

Large diffs are not rendered by default.

1,250 changes: 449 additions & 801 deletions PUBG_Replay_Manager/Main.cs

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion PUBG_Replay_Manager/PUBG_Replay_Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -23,7 +26,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand All @@ -49,6 +51,10 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -128,5 +134,17 @@
<ItemGroup>
<None Include="erangel.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.0.0\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.0\build\dotnet\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
</Project>
Binary file not shown.
3 changes: 0 additions & 3 deletions PUBG_Replay_Manager/bin/Debug/PUBG_Replay_Manager.exe.config

This file was deleted.

Binary file not shown.
Binary file removed PUBG_Replay_Manager/bin/Release/Newtonsoft.Json.dll
Binary file not shown.
10,760 changes: 0 additions & 10,760 deletions PUBG_Replay_Manager/bin/Release/Newtonsoft.Json.xml

This file was deleted.

Binary file not shown.
Binary file modified PUBG_Replay_Manager/bin/Release/PUBG_Replay_Manager.exe
Binary file not shown.
Binary file modified PUBG_Replay_Manager/bin/Release/PUBG_Replay_Manager.pdb
Binary file not shown.
297 changes: 297 additions & 0 deletions PUBG_Replay_Manager/obj/Debug/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading;

static class Common
{
private const int DelayUntilReboot = 4;

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags);

[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);

[Conditional("DEBUG")]
public static void Log(string format, params object[] args)
{
// Should this be trace?
Debug.WriteLine("=== COSTURA === " + string.Format(format, args));
}

static void CopyTo(Stream source, Stream destination)
{
var array = new byte[81920];
int count;
while ((count = source.Read(array, 0, array.Length)) != 0)
{
destination.Write(array, 0, count);
}
}

static void CreateDirectory(string tempBasePath)
{
if (!Directory.Exists(tempBasePath))
{
Directory.CreateDirectory(tempBasePath);
}
}

static byte[] ReadStream(Stream stream)
{
var data = new Byte[stream.Length];
stream.Read(data, 0, data.Length);
return data;
}

public static string CalculateChecksum(string filename)
{
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
using (var bs = new BufferedStream(fs))
using (var sha1 = new SHA1CryptoServiceProvider())
{
var hash = sha1.ComputeHash(bs);
var formatted = new StringBuilder(2 * hash.Length);
foreach (var b in hash)
{
formatted.AppendFormat("{0:X2}", b);
}
return formatted.ToString();
}
}

public static Assembly ReadExistingAssembly(AssemblyName name)
{
var currentDomain = AppDomain.CurrentDomain;
var assemblies = currentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
var currentName = assembly.GetName();
if (string.Equals(currentName.Name, name.Name, StringComparison.InvariantCultureIgnoreCase) &&
string.Equals(CultureToString(currentName.CultureInfo), CultureToString(name.CultureInfo), StringComparison.InvariantCultureIgnoreCase))
{
Log("Assembly '{0}' already loaded, returning existing assembly", assembly.FullName);

return assembly;
}
}
return null;
}

static string CultureToString(CultureInfo culture)
{
if (culture == null)
return "";

return culture.Name;
}

public static Assembly ReadFromDiskCache(string tempBasePath, AssemblyName requestedAssemblyName)
{
var name = requestedAssemblyName.Name.ToLowerInvariant();

if (requestedAssemblyName.CultureInfo != null && !String.IsNullOrEmpty(requestedAssemblyName.CultureInfo.Name))
name = $"{requestedAssemblyName.CultureInfo.Name}.{name}";

var bittyness = IntPtr.Size == 8 ? "64" : "32";
var assemblyTempFilePath = Path.Combine(tempBasePath, String.Concat(name, ".dll"));
if (File.Exists(assemblyTempFilePath))
{
return Assembly.LoadFile(assemblyTempFilePath);
}
assemblyTempFilePath = Path.ChangeExtension(assemblyTempFilePath, "exe");
if (File.Exists(assemblyTempFilePath))
{
return Assembly.LoadFile(assemblyTempFilePath);
}
assemblyTempFilePath = Path.Combine(Path.Combine(tempBasePath, bittyness), String.Concat(name, ".dll"));
if (File.Exists(assemblyTempFilePath))
{
return Assembly.LoadFile(assemblyTempFilePath);
}
assemblyTempFilePath = Path.ChangeExtension(assemblyTempFilePath, "exe");
if (File.Exists(assemblyTempFilePath))
{
return Assembly.LoadFile(assemblyTempFilePath);
}
return null;
}

public static Assembly ReadFromEmbeddedResources(Dictionary<string, string> assemblyNames, Dictionary<string, string> symbolNames, AssemblyName requestedAssemblyName)
{
var name = requestedAssemblyName.Name.ToLowerInvariant();

if (requestedAssemblyName.CultureInfo != null && !String.IsNullOrEmpty(requestedAssemblyName.CultureInfo.Name))
name = $"{requestedAssemblyName.CultureInfo.Name}.{name}";

byte[] assemblyData;
using (var assemblyStream = LoadStream(assemblyNames, name))
{
if (assemblyStream == null)
{
return null;
}
assemblyData = ReadStream(assemblyStream);
}

using (var pdbStream = LoadStream(symbolNames, name))
{
if (pdbStream != null)
{
var pdbData = ReadStream(pdbStream);
return Assembly.Load(assemblyData, pdbData);
}
}

return Assembly.Load(assemblyData);
}

static Stream LoadStream(Dictionary<string, string> resourceNames, string name)
{
string value;
if (resourceNames.TryGetValue(name, out value))
return LoadStream(value);

return null;
}

static Stream LoadStream(string fullname)
{
var executingAssembly = Assembly.GetExecutingAssembly();

if (fullname.EndsWith(".compressed"))
{
using (var stream = executingAssembly.GetManifestResourceStream(fullname))
using (var compressStream = new DeflateStream(stream, CompressionMode.Decompress))
{
var memStream = new MemoryStream();
CopyTo(compressStream, memStream);
memStream.Position = 0;
return memStream;
}
}

return executingAssembly.GetManifestResourceStream(fullname);
}

// Mutex code from http://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c
public static void PreloadUnmanagedLibraries(string hash, string tempBasePath, IEnumerable<string> libs, Dictionary<string, string> checksums)
{
var mutexId = $"Global\\Costura{hash}";

using (var mutex = new Mutex(false, mutexId))
{
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
var securitySettings = new MutexSecurity();
securitySettings.AddAccessRule(allowEveryoneRule);
mutex.SetAccessControl(securitySettings);

var hasHandle = false;
try
{
try
{
hasHandle = mutex.WaitOne(60000, false);
if (hasHandle == false)
throw new TimeoutException("Timeout waiting for exclusive access");
}
catch (AbandonedMutexException)
{
hasHandle = true;
}

var bittyness = IntPtr.Size == 8 ? "64" : "32";
CreateDirectory(Path.Combine(tempBasePath, bittyness));
InternalPreloadUnmanagedLibraries(tempBasePath, libs, checksums);
}
finally
{
if (hasHandle)
mutex.ReleaseMutex();
}
}
}

static void InternalPreloadUnmanagedLibraries(string tempBasePath, IEnumerable<string> libs, Dictionary<string, string> checksums)
{
string name;

foreach (var lib in libs)
{
name = ResourceNameToPath(lib);

var assemblyTempFilePath = Path.Combine(tempBasePath, name);

if (File.Exists(assemblyTempFilePath))
{
var checksum = CalculateChecksum(assemblyTempFilePath);
if (checksum != checksums[lib])
File.Delete(assemblyTempFilePath);
}

if (!File.Exists(assemblyTempFilePath))
{
using (var copyStream = LoadStream(lib))
using (var assemblyTempFile = File.OpenWrite(assemblyTempFilePath))
{
CopyTo(copyStream, assemblyTempFile);
}
if (!MoveFileEx(assemblyTempFilePath, null, DelayUntilReboot))
{
//TODO: for now we ignore the return value.
}
}
}

SetDllDirectory(tempBasePath);

foreach (var lib in libs)
{
name = ResourceNameToPath(lib);

if (name.EndsWith(".dll"))
{
var assemblyTempFilePath = Path.Combine(tempBasePath, name);

LoadLibrary(assemblyTempFilePath);
}
}
}

static string ResourceNameToPath(string lib)
{
var bittyness = IntPtr.Size == 8 ? "64" : "32";

var name = lib;

if (lib.StartsWith(String.Concat("costura", bittyness, ".")))
{
name = Path.Combine(bittyness, lib.Substring(10));
}
else if (lib.StartsWith("costura."))
{
name = lib.Substring(8);
}

if (name.EndsWith(".compressed"))
{
name = name.Substring(0, name.Length - 11);
}

return name;
}
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit adf94f7

Please sign in to comment.