From 484b0a38201224609706d99fb648710878e2ea1b Mon Sep 17 00:00:00 2001
From: ApfelTeeSaft <91074565+ApfelTeeSaft@users.noreply.github.com>
Date: Mon, 23 Sep 2024 01:15:24 +0200
Subject: [PATCH] Multiplayer Code lol
---
.gitignore | 72 +++++++++++++++++++
Multikill/Multikill.sln | 25 +++++++
Multikill/Multikill/Multikill.cs | 51 +++++++++++++
Multikill/Multikill/Multikill.csproj | 32 +++++++++
.../Multikill/Multikill/ConsoleManager.cs | 59 +++++++++++++++
.../Multikill/Multikill/NetworkManager.cs | 65 +++++++++++++++++
Multikill/Multikill/Multikill/UIManager.cs | 50 +++++++++++++
7 files changed, 354 insertions(+)
create mode 100644 .gitignore
create mode 100644 Multikill/Multikill.sln
create mode 100644 Multikill/Multikill/Multikill.cs
create mode 100644 Multikill/Multikill/Multikill.csproj
create mode 100644 Multikill/Multikill/Multikill/ConsoleManager.cs
create mode 100644 Multikill/Multikill/Multikill/NetworkManager.cs
create mode 100644 Multikill/Multikill/Multikill/UIManager.cs
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9f9f716
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,72 @@
+# Ignore Visual Studio temporary files, build results, and
+# build logs.
+[vb]*.user
+[vb]*.suo
+[vb]*.userosscache
+[vb]*.sln.docstates
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# Mono Auto Generated Files
+mono_crash.*
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows shortcuts
+*.lnk
+
+# Visual Studio Code settings
+.vscode/
+
+# Rider settings
+.idea/
+*.sln.iml
+
+# DotNet core settings
+*.pidb
+*.svd
+*.suo
+*.user
+*.userprefs
+*.csproj.user
+*.csproj.vspscc
+*.csproj.vssscc
+*.vs/
+.vscode/
+.idea/
+build/
+out/
+temp/
+backup/
+# Build directories
+bin/
+obj/
+
+# Log files
+*.log
+
+# NuGet Packages
+*.nupkg
+*.snupkg
+*.nuspec
+packages/
+
+# Windows
+*.DS_Store
+*.env
+
+# JetBrains Rider project-specific files
+.idea/
\ No newline at end of file
diff --git a/Multikill/Multikill.sln b/Multikill/Multikill.sln
new file mode 100644
index 0000000..68210db
--- /dev/null
+++ b/Multikill/Multikill.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35027.167
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multikill", "Multikill\Multikill.csproj", "{3AA568A4-EF62-4515-BEE0-A313E7B9E1A0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {3AA568A4-EF62-4515-BEE0-A313E7B9E1A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3AA568A4-EF62-4515-BEE0-A313E7B9E1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3AA568A4-EF62-4515-BEE0-A313E7B9E1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3AA568A4-EF62-4515-BEE0-A313E7B9E1A0}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {B514BB2B-8C7B-415C-9801-88BC684B8220}
+ EndGlobalSection
+EndGlobal
diff --git a/Multikill/Multikill/Multikill.cs b/Multikill/Multikill/Multikill.cs
new file mode 100644
index 0000000..8f1c4e6
--- /dev/null
+++ b/Multikill/Multikill/Multikill.cs
@@ -0,0 +1,51 @@
+using BepInEx;
+using UnityEngine;
+
+
+namespace Multikill
+{
+ [BepInPlugin("com.apfelteesaft.multikillmod", "MultikillMod", "1.0.0")]
+ public class MultiplayerMod : BaseUnityPlugin
+ {
+ private Multikill.ConsoleManager consoleManager;
+ private Multikill.UIManager uiManager;
+ private Multikill.NetworkManager networkManager;
+
+ void Awake()
+ {
+ consoleManager = new Multikill.ConsoleManager();
+ consoleManager.InitializeConsole();
+
+ uiManager = new Multikill.UIManager();
+ uiManager.SetupUI(ConnectToServer);
+
+ networkManager = new Multikill.NetworkManager();
+ networkManager.InitializeNetwork();
+ }
+
+ void Update()
+ {
+ networkManager.PollNetworkEvents();
+
+ if (Input.GetKeyDown(KeyCode.F4))
+ {
+ consoleManager.ToggleConsole();
+ }
+
+ if (Input.GetKeyDown(KeyCode.F1))
+ {
+ uiManager.ToggleUIVisibility();
+ }
+ }
+
+ private void ConnectToServer(string ip, int port)
+ {
+ networkManager.ConnectToServer(ip, port);
+ }
+
+ void OnDestroy()
+ {
+ consoleManager.Cleanup();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Multikill/Multikill/Multikill.csproj b/Multikill/Multikill/Multikill.csproj
new file mode 100644
index 0000000..0b242c2
--- /dev/null
+++ b/Multikill/Multikill/Multikill.csproj
@@ -0,0 +1,32 @@
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\Assembly-CSharp.dll
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\BepInEx\core\BepInEx.dll
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\UnityEngine.dll
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\UnityEngine.CoreModule.dll
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\UnityEngine.UI.dll
+
+
+ D:\SteamLibrary\steamapps\common\ULTRAKILL\ULTRAKILL_Data\Managed\UnityEngine.UIModule.dll
+
+
+
+
diff --git a/Multikill/Multikill/Multikill/ConsoleManager.cs b/Multikill/Multikill/Multikill/ConsoleManager.cs
new file mode 100644
index 0000000..af2f6ce
--- /dev/null
+++ b/Multikill/Multikill/Multikill/ConsoleManager.cs
@@ -0,0 +1,59 @@
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+using UnityEngine;
+
+namespace Multikill.Multikill
+{
+ public class ConsoleManager
+ {
+ [DllImport("kernel32.dll", SetLastError = true)]
+ private static extern bool AllocConsole();
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ private static extern bool FreeConsole();
+
+ private bool consoleVisible = false;
+
+ public void InitializeConsole()
+ {
+ if (AllocConsole())
+ {
+ var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
+ Console.SetOut(writer);
+ Console.SetError(writer);
+
+ Debug.Log("Console allocated.");
+ Application.logMessageReceived += HandleLog;
+ }
+ }
+
+ private void HandleLog(string logString, string stackTrace, LogType type)
+ {
+ Console.WriteLine($"{type}: {logString}");
+ if (type == LogType.Exception)
+ {
+ Console.WriteLine(stackTrace);
+ }
+ }
+
+ public void ToggleConsole()
+ {
+ consoleVisible = !consoleVisible;
+ if (consoleVisible)
+ {
+ AllocConsole();
+ }
+ else
+ {
+ FreeConsole();
+ }
+ }
+
+ public void Cleanup()
+ {
+ Application.logMessageReceived -= HandleLog;
+ FreeConsole();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Multikill/Multikill/Multikill/NetworkManager.cs b/Multikill/Multikill/Multikill/NetworkManager.cs
new file mode 100644
index 0000000..3b1be80
--- /dev/null
+++ b/Multikill/Multikill/Multikill/NetworkManager.cs
@@ -0,0 +1,65 @@
+using LiteNetLib;
+using LiteNetLib.Utils;
+using System.Net;
+using System.Net.Sockets;
+using UnityEngine;
+
+namespace Multikill.Multikill
+{
+ public class NetworkManager : INetEventListener
+ {
+ private NetManager client;
+ private NetPeer serverPeer;
+
+ public void InitializeNetwork()
+ {
+ client = new NetManager(this);
+ client.Start();
+ }
+
+ public void ConnectToServer(string ip, int port)
+ {
+ serverPeer = client.Connect(ip, port, "ConnectionKey");
+ Debug.Log($"Attempting to connect to {ip}:{port}");
+ }
+
+ public void PollNetworkEvents()
+ {
+ client.PollEvents();
+ }
+
+ public void OnPeerConnected(NetPeer peer)
+ {
+ Debug.Log("Connected to server!");
+ }
+
+ public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
+ {
+ Debug.Log($"Disconnected from server: {disconnectInfo.Reason}");
+ }
+
+ public void OnNetworkError(IPEndPoint endPoint, SocketError socketErrorCode)
+ {
+ Debug.LogError($"Network error: {socketErrorCode}");
+ }
+
+ public void OnConnectionRequest(ConnectionRequest request)
+ {
+ request.Accept();
+ }
+
+ public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliveryMethod)
+ {
+ Debug.Log("Received data from server.");
+ }
+
+ public void OnNetworkReceiveUnconnected(IPEndPoint remoteEndPoint, NetPacketReader reader, UnconnectedMessageType messageType)
+ {
+ }
+
+ public void OnNetworkLatencyUpdate(NetPeer peer, int latency)
+ {
+ Debug.Log($"Latency update: {latency} ms");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Multikill/Multikill/Multikill/UIManager.cs b/Multikill/Multikill/Multikill/UIManager.cs
new file mode 100644
index 0000000..552be0e
--- /dev/null
+++ b/Multikill/Multikill/Multikill/UIManager.cs
@@ -0,0 +1,50 @@
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace Multikill.Multikill
+{
+ public class UIManager
+ {
+ private GameObject panel;
+ private InputField ipInput;
+ private InputField portInput;
+ private Button connectButton;
+
+ public void SetupUI(System.Action onConnectButtonClick)
+ {
+ panel = new GameObject("MultiplayerPanel");
+ panel.AddComponent