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

Commit 0fad765

Browse files
committed
E
1 parent f5f811b commit 0fad765

24 files changed

+348
-1441
lines changed

ModSourceGenerator/ModSourceGenerator.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="CSharpPoet" Version="0.3.0" />
12-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0-3.final" />
12+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0-2.final" />
1313
</ItemGroup>
1414
</Project>

TheOtherUs/Chat/CommandEvent.cs

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
using System;
2-
using System.Net;
2+
using System.Collections.Generic;
33

44
namespace TheOtherUs.Chat;
55

6-
public class CommandEvent
6+
public class CommandEvent(string command, Action<CommandEvent> onEvent, CommandPermissions permissions = CommandPermissions.All)
77
{
8-
public string[] Command { get; init; }
9-
public Action<CommandInfo> Event { get; set; }
10-
public CommandPermissions permission { get; set; }
11-
12-
public CommandEvent RegisterEvent(Action<CommandInfo> e)
13-
{
14-
Event += e;
15-
return this;
16-
}
17-
18-
public void Start(string text)
19-
{
20-
21-
}
8+
public string Command { get; init; } = command;
9+
public CommandPermissions permission { get; set; } = permissions;
10+
public Action<CommandEvent> OnEvent = onEvent;
11+
public List<string> Context { get; set; }
2212
}
2313

2414
[Flags]
@@ -30,6 +20,4 @@ public enum CommandPermissions
3020
Lobby,
3121
OnGame,
3222
Debug
33-
}
34-
35-
public record CommandInfo();
23+
}

TheOtherUs/Chat/CommandManager.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
3+
namespace TheOtherUs.Chat;
4+
5+
public class CommandManager : ManagerBase<CommandManager>
6+
{
7+
public readonly List<CommandEvent> commandEvents = [];
8+
9+
public bool Clear = false;
10+
11+
public void Register(CommandEvent @event)
12+
{
13+
commandEvents.RemoveAll(n => n.Command == @event.Command);
14+
commandEvents.Add(@event);
15+
}
16+
17+
public void Register(IEnumerable<CommandEvent> events) => events.Do(Register);
18+
19+
/*public List<CommandEvent> Find(string[] texts)
20+
{
21+
var list = new List<CommandEvent>();
22+
foreach (var e in commandEvents)
23+
{
24+
var command = e.Command;
25+
for (var i = 0; i < texts.Length - 1; i++)
26+
{
27+
if (command[i] != texts[i])
28+
{
29+
goto next;
30+
}
31+
}
32+
list.Add(e);
33+
34+
next:;
35+
}
36+
37+
return list;
38+
}*/
39+
40+
public void FindStart(string command)
41+
{
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
3+
namespace TheOtherUs.Chat.Patches;
4+
5+
[Harmony]
6+
internal static class ChatControllerPatch
7+
{
8+
[HarmonyPatch(typeof(ChatController), nameof(ChatController.SendChat)), HarmonyPrefix]
9+
private static bool ChatControllerSendChatPatch(ChatController __instance)
10+
{
11+
var strings = __instance.freeChatField.Text.ToLower().Split(string.Empty);
12+
if (strings[0][0] != '/')
13+
return true;
14+
15+
var command = strings[0].Remove(0);
16+
var context = new List<string>();
17+
var index = 1;
18+
foreach (var str in strings)
19+
{
20+
if (index != 1)
21+
context.Add(str);
22+
index++;
23+
}
24+
25+
if (CommandManager.Instance.Clear)
26+
{
27+
__instance.freeChatField.Clear();
28+
__instance.quickChatMenu.Clear();
29+
CommandManager.Instance.Clear = false;
30+
return false;
31+
}
32+
return true;
33+
}
34+
}

TheOtherUs/CustomCosmetics/DIYColor.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@
66
using AmongUs.Data.Legacy;
77
using Csv;
88
using UnityEngine;
9+
using UnityEngine.Video;
910
using Object = UnityEngine.Object;
1011

1112
namespace TheOtherUs.CustomCosmetics;
1213

13-
public class DIYColor
14+
internal interface IColorData
15+
{
16+
public int Index { get; set; }
17+
public string Text { get; set; }
18+
public Color Color { get; set; }
19+
public Color Shadow { get; set; }
20+
}
21+
22+
public class DIYColor : IColorData
1423
{
1524
public static int StartIndex { get; private set; } = 18;
1625

26+
public static Color Impostor = Palette.ImpostorRed;
27+
public static Color Crewmate = Palette.CrewmateBlue;
28+
public static Color Light = Palette.LightBlue;
29+
public static Color Enabled = Palette.EnabledColor;
30+
public static Color Disabled = Palette.DisabledClear;
31+
public static Color Visor = Palette.VisorColor;
32+
1733
public static readonly List<DIYColor> DIYColors =
1834
[
1935
new DIYColor
@@ -288,6 +304,18 @@ public static bool Compare(Color32 color1, Color32 color2)
288304
return color1.r == color2.r && color1.g == color2.g && color1.b == color2.g && color1.a == color2.a;
289305
}
290306

307+
#nullable enable
308+
internal static IColorData? GetColor(string name)
309+
{
310+
var vanilla = vanillaColors.FirstOrDefault(n => n.Text == name);
311+
if (vanilla != null)
312+
return vanilla;
313+
314+
return DIYColors.FirstOrDefault(n => n.Text == name || n.TranslateId == name);
315+
}
316+
#nullable disable
317+
318+
291319
public static string DIYColorPath => Path.Combine(CosmeticsManager.CosmeticDir, "DIYColors.cs");
292320
public static void LoadDIYColor()
293321
{
@@ -318,7 +346,13 @@ public static void LoadDIYColor()
318346
}
319347
}
320348

321-
public record VanillaColor(Color32 Color, Color32 Shadow, int Index, StringNames StringNames);
349+
public class VanillaColor(Color32 Color, Color32 Shadow, int Index, StringNames StringName) : IColorData
350+
{
351+
public string Text { get; set; } = StringName.GetString();
352+
public Color Color { get; set; } = Color;
353+
public Color Shadow { get; set; } = Shadow;
354+
public int Index { get; set; } = Index;
355+
}
322356
}
323357

324358
[Harmony]

TheOtherUs/Helper/DownloadHelper.cs

+66-1
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,68 @@ public static string GetRepoRawURL()
5656
}
5757
}
5858

59+
public interface IFastDownloader : IDisposable
60+
{
61+
public void Download(string downloadPath, string file, string LocalPath = "");
62+
}
63+
64+
public class RepoDownloader(CodeRepo repo) : IFastDownloader
65+
{
66+
public DirectoryInfo directory;
67+
public Repos repoType = repo.repoType;
68+
public List<IGet> Gets = [];
69+
70+
71+
#nullable enable
72+
private T? Get<T>() where T : class, IGet, new()
73+
{
74+
return Gets.FirstOrDefault(n => n is T) as T;
75+
}
76+
#nullable disable
77+
78+
public RepoDownloader BuildGet()
79+
{
80+
if (repoType is Repos.Github)
81+
{
82+
Gets.Add(GithubGet.Get(repo));
83+
}
84+
85+
return this;
86+
}
87+
88+
public RepoDownloader SetBaseDirectory(string path)
89+
{
90+
directory = new DirectoryInfo(path);
91+
return this;
92+
}
93+
public void Download(string downloadPath, string file, string LocalPath = "")
94+
{
95+
96+
}
97+
98+
public void Dispose()
99+
{
100+
throw new NotImplementedException();
101+
}
102+
}
103+
104+
public enum Repos
105+
{
106+
Github,
107+
GitLab,
108+
GitCode,
109+
Gitee,
110+
Gitea,
111+
Nuget
112+
}
113+
59114
public sealed class CodeRepo
60115
{
61116
public string Url { get; set; }
62117
public string pingUrl { get; set; }
63118
public int Time { get; set; }
64119
public string Branch { get; set; }
120+
public Repos repoType { get; set; }
65121

66122
public void Download()
67123
{
@@ -89,6 +145,15 @@ public static CodeRepo GetFastRepo()
89145

90146
public interface IGet : IDisposable;
91147

148+
public interface IRepoGet : IGet;
149+
150+
public class ThunderStoreGet : IGet
151+
{
152+
public void Dispose()
153+
{
154+
}
155+
}
156+
92157
public class NugetGet : IGet
93158
{
94159
public string NugetURL { get; set; }
@@ -132,7 +197,7 @@ public void Dispose()
132197
}
133198
}
134199

135-
public class GithubGet(string RepoOwner, string RepoName) : IGet
200+
public class GithubGet(string RepoOwner, string RepoName) : IRepoGet
136201
{
137202
public const string Api = "https://api.github.com";
138203
public const string Web = "https://github.com";

TheOtherUs/Helper/FastRPC.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,10 @@ public static void Register(List<MethodInfo> methods)
431431
});
432432
}
433433

434-
[HarmonyPatch(typeof(InnerNetClient._HandleGameDataInner_d__39),
435-
nameof(InnerNetClient._HandleGameDataInner_d__39.MoveNext))]
434+
[HarmonyPatch(typeof(InnerNetClient._HandleGameDataInner_d__41),
435+
nameof(InnerNetClient._HandleGameDataInner_d__41.MoveNext))]
436436
[HarmonyPrefix]
437-
private static void InnerNet_ReaderPath(InnerNetClient._HandleGameDataInner_d__39 __instance, ref bool __result)
437+
private static void InnerNet_ReaderPath(InnerNetClient._HandleGameDataInner_d__41 __instance, ref bool __result)
438438
{
439439
if (_allListeners.Count <= 0) return;
440440
var innerNetClient = __instance.__4__this;

TheOtherUs/Helper/HandshakeHelper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static bool GetVersionHandshake(out ClientData[]? players, out string mes
101101

102102
public static void shareGameVersion()
103103
{
104-
var writer = FastRpcWriter.StartNewRpcWriter(CustomRPC.VersionHandshake, GameData.Instance)
104+
var writer = FastRpcWriter.StartNewRpcWriter(CustomRPC.VersionHandshake, LobbyBehaviour.Instance)
105105
.WritePacked(AmongUsClient.Instance.ClientId)
106106
.Write(TheOtherRolesPlugin.version.Major)
107107
.Write(TheOtherRolesPlugin.version.Minor)
@@ -179,8 +179,8 @@ public static void shareGameGUID()
179179
{
180180
var clientId = AmongUsClient.Instance.ClientId;
181181
var bytes = Assembly.GetExecutingAssembly().ManifestModule.ModuleVersionId.ToByteArray();
182-
183-
var writer = FastRpcWriter.StartNewRpcWriter(CustomRPC.VersionHandshakeEx, GameData.Instance)
182+
183+
var writer = FastRpcWriter.StartNewRpcWriter(CustomRPC.VersionHandshakeEx, LobbyBehaviour.Instance)
184184
.WritePacked(AmongUsClient.Instance.ClientId)
185185
.Write((byte)ShareMode.Guid)
186186
.Write(bytes.Length)

TheOtherUs/Helper/Helpers.cs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static bool flipBitwise(bool bit)
9595

9696
public static void enableCursor(bool initalSetCursor)
9797
{
98+
9899
if (initalSetCursor)
99100
{
100101
var sprite = loadSpriteFromResources("TheOtherUs.Resources.Cursor.png", 115f);

TheOtherUs/Languages/LanguageManager.cs

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using AmongUs.Data.Legacy;
66
using BepInEx;
7+
using Il2CppSystem;
78

89
namespace TheOtherUs.Languages;
910

@@ -172,6 +173,12 @@ internal static string Translate(this string key)
172173
{
173174
return LanguageManager.Instance.GetString(key);
174175
}
176+
177+
internal static string GetString(this StringNames name, Object[]? objects = null)
178+
{
179+
return TranslationController.Instance.GetString(name, objects);
180+
}
181+
175182
internal static string Get(params string[] strings)
176183
{
177184
TranslateNode? node = null;

TheOtherUs/MainManager.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace TheOtherUs;
5+
6+
[MonoRegisterAndDontDestroy]
7+
public class MainManager : MonoBehaviour
8+
{
9+
public MainManager Instance => MonoRegisterAndDontDestroy.GetRegister<MainManager>();
10+
private readonly ResourceSprite cursorSprite = new("Cursor.png");
11+
12+
public void OnEnable()
13+
{
14+
Cursor.SetCursor(cursorSprite.GetSprite().texture, Vector2.zero, CursorMode.Auto);
15+
}
16+
}

0 commit comments

Comments
 (0)