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

Commit 9d3b34d

Browse files
committed
Add project files.
1 parent bc50480 commit 9d3b34d

12 files changed

+1063
-0
lines changed

CustomServersClient.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30320.27
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomServersClient", "CustomServersClient\CustomServersClient.csproj", "{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5940C64A-7B4D-4DE5-8214-0D585143E960}
24+
EndGlobalSection
25+
EndGlobal
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace CustomServersClient
2+
{
3+
public class CustomServerInfo
4+
{
5+
public string name;
6+
public string ip;
7+
public int port;
8+
9+
public int hash;
10+
11+
public CustomServerInfo(string name, string ip, int port)
12+
{
13+
this.name = name;
14+
this.ip = ip;
15+
this.port = port;
16+
17+
hash = name.GetHashCode() + ip.GetHashCode() + port.GetHashCode();
18+
}
19+
20+
public override string ToString()
21+
{
22+
return $"{name} ({ip}:{port})";
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{8424C5D8-334F-4CAB-B3C8-4D7635283B7F}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CustomServersClient</RootNamespace>
11+
<AssemblyName>CustomServersClient</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="0Harmony">
35+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\0Harmony.dll</HintPath>
36+
<Private>False</Private>
37+
</Reference>
38+
<Reference Include="Assembly-CSharp">
39+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll</HintPath>
40+
<Private>False</Private>
41+
</Reference>
42+
<Reference Include="BepInEx.Core">
43+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.Core.dll</HintPath>
44+
<Private>False</Private>
45+
</Reference>
46+
<Reference Include="BepInEx.IL2CPP">
47+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.IL2CPP.dll</HintPath>
48+
<Private>False</Private>
49+
</Reference>
50+
<Reference Include="Il2Cppmscorlib">
51+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\Il2Cppmscorlib.dll</HintPath>
52+
<Private>False</Private>
53+
</Reference>
54+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
55+
<SpecificVersion>False</SpecificVersion>
56+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\Newtonsoft.Json.dll</HintPath>
57+
<Private>False</Private>
58+
</Reference>
59+
<Reference Include="System" />
60+
<Reference Include="System.Core" />
61+
<Reference Include="System.Drawing" />
62+
<Reference Include="System.Windows.Forms" />
63+
<Reference Include="System.Xml.Linq" />
64+
<Reference Include="System.Data.DataSetExtensions" />
65+
<Reference Include="Microsoft.CSharp" />
66+
<Reference Include="System.Data" />
67+
<Reference Include="System.Net.Http" />
68+
<Reference Include="System.Xml" />
69+
<Reference Include="UnhollowerBaseLib">
70+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\UnhollowerBaseLib.dll</HintPath>
71+
<Private>False</Private>
72+
</Reference>
73+
<Reference Include="UnityEngine">
74+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.dll</HintPath>
75+
<Private>False</Private>
76+
</Reference>
77+
<Reference Include="UnityEngine.CoreModule">
78+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.CoreModule.dll</HintPath>
79+
<Private>False</Private>
80+
</Reference>
81+
<Reference Include="UnityEngine.UI">
82+
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\UnityEngine.UI.dll</HintPath>
83+
<Private>False</Private>
84+
</Reference>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<Compile Include="CustomServerInfo.cs" />
88+
<Compile Include="CustomServersPlugin.cs" />
89+
<Compile Include="CustomServersPatches.cs" />
90+
<Compile Include="UI\EditServerForm.cs">
91+
<SubType>Form</SubType>
92+
</Compile>
93+
<Compile Include="UI\EditServerForm.designer.cs">
94+
<DependentUpon>EditServerForm.cs</DependentUpon>
95+
</Compile>
96+
<Compile Include="Properties\AssemblyInfo.cs" />
97+
<Compile Include="UI\ServersManagementForm.cs">
98+
<SubType>Form</SubType>
99+
</Compile>
100+
<Compile Include="UI\ServersManagementForm.designer.cs">
101+
<DependentUpon>ServersManagementForm.cs</DependentUpon>
102+
</Compile>
103+
</ItemGroup>
104+
<ItemGroup>
105+
<EmbeddedResource Include="UI\EditServerForm.resx">
106+
<DependentUpon>EditServerForm.cs</DependentUpon>
107+
</EmbeddedResource>
108+
<EmbeddedResource Include="UI\ServersManagementForm.resx">
109+
<DependentUpon>ServersManagementForm.cs</DependentUpon>
110+
</EmbeddedResource>
111+
</ItemGroup>
112+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
113+
</Project>
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
using HarmonyLib;
2+
using InnerNet;
3+
using Newtonsoft.Json;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using UnhollowerBaseLib;
8+
using CustomServersClient.UI;
9+
10+
using RegionMenuLambda = RegionMenu.IOCEJPCJFKF;
11+
using RegionInfo = KMDGIDEDGGM;
12+
using ServerInfo = EEKGADNPDBH;
13+
14+
namespace CustomServersClient
15+
{
16+
public static class CustomServersPatches
17+
{
18+
public static List<CustomServerInfo> customServers = new List<CustomServerInfo>();
19+
20+
static RegionInfo[] _defaultRegions = new RegionInfo[3];
21+
22+
static bool _firstRun = true;
23+
static ServersManagementForm _managementForm;
24+
25+
[HarmonyDebug]
26+
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SetEndpoint), typeof(string), typeof(ushort))]
27+
public static class InnerNetClientSetEndPointPatch
28+
{
29+
public static bool Prefix(string EMFDKKLLHCL, ushort JOBBGKDMALK, ref InnerNetClient __instance)
30+
{
31+
var customServer = customServers.FirstOrDefault(x => x.ToString() == EMFDKKLLHCL);
32+
33+
if (customServer != default)
34+
{
35+
CustomServersPlugin.Logger.LogDebug($"Setting IP and port for custom server \"{customServer.name}\"!");
36+
__instance.HECFEPIMCOE = customServer.ip;
37+
__instance.DNGDMFHEJBA = customServer.port;
38+
}
39+
else
40+
{
41+
__instance.HECFEPIMCOE = EMFDKKLLHCL;
42+
__instance.DNGDMFHEJBA = JOBBGKDMALK;
43+
}
44+
45+
return false;
46+
}
47+
}
48+
49+
[HarmonyDebug]
50+
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.OnEnable))]
51+
public static class RegionMenuOnEnablePatch
52+
{
53+
public static bool forceReloadServers;
54+
55+
public static bool Prefix(ref RegionMenu __instance)
56+
{
57+
ClearOnClickAction(__instance.ButtonPool);
58+
59+
if (_firstRun)
60+
{
61+
for (int i = 0; i < 3; i++)
62+
{
63+
_defaultRegions[i] = ServerManager.DefaultRegions[i];
64+
}
65+
66+
_firstRun = false;
67+
}
68+
69+
Directory.CreateDirectory(CustomServersPlugin.userDataPath);
70+
71+
if (File.Exists(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)))
72+
{
73+
customServers = JsonConvert.DeserializeObject<List<CustomServerInfo>>(File.ReadAllText(Path.Combine(CustomServersPlugin.userDataPath, CustomServersPlugin.customServersFilePath)));
74+
CustomServersPlugin.Logger.LogDebug("Loaded custom servers list from file!");
75+
}
76+
else
77+
{
78+
CustomServersPlugin.Logger.LogWarning("Custom servers list file not found!");
79+
}
80+
81+
if (ServerManager.DefaultRegions.Count != 4 + customServers.Count || forceReloadServers)
82+
{
83+
var regions = new RegionInfo[4 + customServers.Count];
84+
85+
regions[0] = new RegionInfo("Manage servers...", "MANAGE_SERVERS", null);
86+
87+
for (int i = 0; i < 3; i++)
88+
{
89+
regions[i + 1] = _defaultRegions[i];
90+
}
91+
92+
for (int i = 0; i < customServers.Count; i++)
93+
{
94+
Il2CppReferenceArray<ServerInfo> servers = new ServerInfo[1] { new ServerInfo(customServers[i].name, customServers[i].ToString(), (ushort)customServers[i].port) };
95+
96+
regions[i + 4] = new RegionInfo(customServers[i].name, "0", servers);
97+
}
98+
99+
ServerManager.DefaultRegions = regions;
100+
}
101+
102+
return true;
103+
}
104+
105+
public static void ClearOnClickAction(ObjectPoolBehavior buttonPool)
106+
{
107+
foreach (var button in buttonPool.activeChildren)
108+
{
109+
var buttonComponent = button.GetComponent<PassiveButton>();
110+
if (buttonComponent != null)
111+
buttonComponent.OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
112+
}
113+
114+
foreach (var button in buttonPool.inactiveChildren)
115+
{
116+
var buttonComponent = button.GetComponent<PassiveButton>();
117+
if (buttonComponent != null)
118+
buttonComponent.OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
119+
}
120+
}
121+
}
122+
123+
[HarmonyDebug]
124+
[HarmonyPatch(typeof(RegionMenuLambda), nameof(RegionMenuLambda.Method_Internal_Void_0))]
125+
public static class RegionMenuChooseOptionPatch
126+
{
127+
public static bool Prefix(ref RegionMenuLambda __instance)
128+
{
129+
if (__instance.region.NCDMJOGPKOL == "MANAGE_SERVERS")
130+
{
131+
if(_managementForm == null || _managementForm.IsDisposed)
132+
_managementForm = new ServersManagementForm();
133+
134+
_managementForm.regionMenu = __instance.field_Public_RegionMenu_0;
135+
136+
if (_managementForm.Visible)
137+
_managementForm.Focus();
138+
else
139+
_managementForm.ShowDialog();
140+
141+
return false;
142+
}
143+
else
144+
{
145+
return true;
146+
}
147+
148+
}
149+
}
150+
}
151+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using BepInEx;
2+
using BepInEx.IL2CPP;
3+
using HarmonyLib;
4+
using System.Reflection;
5+
6+
namespace CustomServersClient
7+
{
8+
[BepInPlugin("com.andruzzzhka.customserversclient", "Custom Servers Client", "1.0.0.0")]
9+
public class CustomServersPlugin : BasePlugin
10+
{
11+
public const string userDataPath = "UserData";
12+
public const string customServersFilePath = "CustomServers.json";
13+
14+
static internal BepInEx.Logging.ManualLogSource Logger;
15+
16+
static Harmony _harmony;
17+
18+
public override void Load()
19+
{
20+
Logger = Log;
21+
22+
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "andruzzzhka.customserversclient");
23+
24+
Logger.LogDebug("Applied Harmony patches!");
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("CustomServersClient")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("CustomServersClient")]
12+
[assembly: AssemblyCopyright("Copyright © 2020")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("8424c5d8-334f-4cab-b3c8-4d7635283b7f")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)