Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
andruzzzhka committed Oct 8, 2020
1 parent bc50480 commit 9d3b34d
Show file tree
Hide file tree
Showing 12 changed files with 1,063 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CustomServersClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomServersClient", "CustomServersClient\CustomServersClient.csproj", "{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5940C64A-7B4D-4DE5-8214-0D585143E960}
EndGlobalSection
EndGlobal
25 changes: 25 additions & 0 deletions CustomServersClient/CustomServerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace CustomServersClient
{
public class CustomServerInfo
{
public string name;
public string ip;
public int port;

public int hash;

public CustomServerInfo(string name, string ip, int port)
{
this.name = name;
this.ip = ip;
this.port = port;

hash = name.GetHashCode() + ip.GetHashCode() + port.GetHashCode();
}

public override string ToString()
{
return $"{name} ({ip}:{port})";
}
}
}
113 changes: 113 additions & 0 deletions CustomServersClient/CustomServersClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomServersClient</RootNamespace>
<AssemblyName>CustomServersClient</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx.Core">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx.IL2CPP">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.IL2CPP.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Il2Cppmscorlib">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\Il2Cppmscorlib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnhollowerBaseLib">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\UnhollowerBaseLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomServerInfo.cs" />
<Compile Include="CustomServersPlugin.cs" />
<Compile Include="CustomServersPatches.cs" />
<Compile Include="UI\EditServerForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\EditServerForm.designer.cs">
<DependentUpon>EditServerForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\ServersManagementForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\ServersManagementForm.designer.cs">
<DependentUpon>ServersManagementForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="UI\EditServerForm.resx">
<DependentUpon>EditServerForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\ServersManagementForm.resx">
<DependentUpon>ServersManagementForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
151 changes: 151 additions & 0 deletions CustomServersClient/CustomServersPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using HarmonyLib;
using InnerNet;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnhollowerBaseLib;
using CustomServersClient.UI;

using RegionMenuLambda = RegionMenu.IOCEJPCJFKF;
using RegionInfo = KMDGIDEDGGM;
using ServerInfo = EEKGADNPDBH;

namespace CustomServersClient
{
public static class CustomServersPatches
{
public static List<CustomServerInfo> customServers = new List<CustomServerInfo>();

static RegionInfo[] _defaultRegions = new RegionInfo[3];

static bool _firstRun = true;
static ServersManagementForm _managementForm;

[HarmonyDebug]
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SetEndpoint), typeof(string), typeof(ushort))]
public static class InnerNetClientSetEndPointPatch
{
public static bool Prefix(string EMFDKKLLHCL, ushort JOBBGKDMALK, ref InnerNetClient __instance)
{
var customServer = customServers.FirstOrDefault(x => x.ToString() == EMFDKKLLHCL);

if (customServer != default)
{
CustomServersPlugin.Logger.LogDebug($"Setting IP and port for custom server \"{customServer.name}\"!");
__instance.HECFEPIMCOE = customServer.ip;
__instance.DNGDMFHEJBA = customServer.port;
}
else
{
__instance.HECFEPIMCOE = EMFDKKLLHCL;
__instance.DNGDMFHEJBA = JOBBGKDMALK;
}

return false;
}
}

[HarmonyDebug]
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.OnEnable))]
public static class RegionMenuOnEnablePatch
{
public static bool forceReloadServers;

public static bool Prefix(ref RegionMenu __instance)
{
ClearOnClickAction(__instance.ButtonPool);

if (_firstRun)
{
for (int i = 0; i < 3; i++)
{
_defaultRegions[i] = ServerManager.DefaultRegions[i];
}

_firstRun = false;
}

Directory.CreateDirectory(CustomServersPlugin.userDataPath);

if (File.Exists(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)))
{
customServers = JsonConvert.DeserializeObject<List<CustomServerInfo>>(File.ReadAllText(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)));
CustomServersPlugin.Logger.LogDebug("Loaded custom servers list from file!");
}
else
{
CustomServersPlugin.Logger.LogWarning("Custom servers list file not found!");
}

if (ServerManager.DefaultRegions.Count != 4 + customServers.Count || forceReloadServers)
{
var regions = new RegionInfo[4 + customServers.Count];

regions[0] = new RegionInfo("Manage servers...", "MANAGE_SERVERS", null);

for (int i = 0; i < 3; i++)
{
regions[i + 1] = _defaultRegions[i];
}

for (int i = 0; i < customServers.Count; i++)
{
Il2CppReferenceArray<ServerInfo> servers = new ServerInfo[1] { new ServerInfo(customServers[i].name, customServers[i].ToString(), (ushort)customServers[i].port) };

regions[i + 4] = new RegionInfo(customServers[i].name, "0", servers);
}

ServerManager.DefaultRegions = regions;
}

return true;
}

public static void ClearOnClickAction(ObjectPoolBehavior buttonPool)
{
foreach (var button in buttonPool.activeChildren)
{
var buttonComponent = button.GetComponent<PassiveButton>();
if (buttonComponent != null)
buttonComponent.OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
}

foreach (var button in buttonPool.inactiveChildren)
{
var buttonComponent = button.GetComponent<PassiveButton>();
if (buttonComponent != null)
buttonComponent.OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
}
}
}

[HarmonyDebug]
[HarmonyPatch(typeof(RegionMenuLambda), nameof(RegionMenuLambda.Method_Internal_Void_0))]
public static class RegionMenuChooseOptionPatch
{
public static bool Prefix(ref RegionMenuLambda __instance)
{
if (__instance.region.NCDMJOGPKOL == "MANAGE_SERVERS")
{
if(_managementForm == null || _managementForm.IsDisposed)
_managementForm = new ServersManagementForm();

_managementForm.regionMenu = __instance.field_Public_RegionMenu_0;

if (_managementForm.Visible)
_managementForm.Focus();
else
_managementForm.ShowDialog();

return false;
}
else
{
return true;
}

}
}
}
}
27 changes: 27 additions & 0 deletions CustomServersClient/CustomServersPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using BepInEx;
using BepInEx.IL2CPP;
using HarmonyLib;
using System.Reflection;

namespace CustomServersClient
{
[BepInPlugin("com.andruzzzhka.customserversclient", "Custom Servers Client", "1.0.0.0")]
public class CustomServersPlugin : BasePlugin
{
public const string userDataPath = "UserData";
public const string customServersFilePath = "CustomServers.json";

static internal BepInEx.Logging.ManualLogSource Logger;

static Harmony _harmony;

public override void Load()
{
Logger = Log;

_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "andruzzzhka.customserversclient");

Logger.LogDebug("Applied Harmony patches!");
}
}
}
35 changes: 35 additions & 0 deletions CustomServersClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CustomServersClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomServersClient")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8424c5d8-334f-4cab-b3c8-4d7635283b7f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 9d3b34d

Please sign in to comment.