Skip to content

Commit

Permalink
继续优化 + 兼容v2024.10.29
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyx0412 committed Oct 23, 2024
1 parent 69e5909 commit 0165f57
Show file tree
Hide file tree
Showing 50 changed files with 328 additions and 321 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:
unzip ExtraData.zip -d ./Release/
- name: Download Reactor
run: wget https://github.com/NuclearPowered/Reactor/releases/download/2.2.0/Reactor.dll -P ./Release/BepInEx/plugins
run: wget https://github.com/NuclearPowered/Reactor/releases/download/2.3.1/Reactor.dll -P ./Release/BepInEx/plugins

- name: Build
run: dotnet build TheOtherRoles/TheOtherRoles.csproj --configuration Release --output ./Release/BepInEx/plugins
run: dotnet build TheOtherRoles/TheOtherRoles.csproj --configuration Beta --output ./Release/BepInEx/plugins

- name: Cleanup
run: |
Expand Down
Binary file modified Strings.xlsx
Binary file not shown.
3 changes: 3 additions & 0 deletions TheOtherRoles.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Other Files", "Other Files"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Beta|Any CPU = Beta|Any CPU
Debug|Any CPU = Debug|Any CPU
mxyx-club|Any CPU = mxyx-club|Any CPU
Release|Any CPU = Release|Any CPU
Sunday|Any CPU = Sunday|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Beta|Any CPU.ActiveCfg = Beta|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Beta|Any CPU.Build.0 = Beta|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.Debug|Any CPU.Build.0 = Release|Any CPU
{11FBC798-BAF5-4EE5-9511-BE6DB0592F99}.mxyx-club|Any CPU.ActiveCfg = mxyx-club|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions TheOtherRoles/Buttons/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4095,8 +4095,8 @@ public static void createButtonsPostfix(HudManager __instance)
return numberOfLeftTasks <= 0 || !CustomOptionHolder.finishTasksBeforeHauntingOrZoomingOut.getBool();
},
() => { return true; },
() => { return; },
null,
() => { return; },
null,
new Vector3(0.4f, 2.8f, 0),
__instance,
KeyCode.KeypadPlus
Expand Down
31 changes: 29 additions & 2 deletions TheOtherRoles/CustomCosmetics/CosmeticsManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json.Serialization;
using BepInEx;
using TheOtherRoles.CustomCosmetics.CustomHats;

Expand Down Expand Up @@ -36,4 +38,29 @@ public void AddConfig()
{
configs.Add(DefConfig);
}
}
}

public class CosmeticsManagerConfig
{
public string ConfigName = "None";
public string RootUrl { get; set; }
public CustomCosmeticsFlags hasCosmetics { get; set; }
public string HatDirName { get; set; } = "hats";
public string VisorDirName { get; set; } = "Visors";
public string NamePlateDirName { get; set; } = "NamePlates";
public string HatFileName { get; set; } = "CustomHats.json";
public string VisorFileName { get; set; } = "CustomVisors.json";
public string NamePlateFileName { get; set; } = "CustomNamePlates.json";
public string HatPropertyName { get; set; } = "hats";
public string VisorPropertyName { get; set; } = "Visors";
public string NamePlatePropertyName { get; set; } = "nameplates";
}

[Flags, JsonConverter(typeof(JsonStringEnumConverter))]
public enum CustomCosmeticsFlags
{
Hat = 1,
Skin,
Visor,
NamePlate,
}
29 changes: 0 additions & 29 deletions TheOtherRoles/CustomCosmetics/CosmeticsManagerConfig.cs

This file was deleted.

68 changes: 34 additions & 34 deletions TheOtherRoles/CustomCosmetics/CustomColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,42 +147,42 @@ public static bool Prefix(ref string __result, [HarmonyArgument(0)] StringNames
}
}

[HarmonyPatch(typeof(ChatNotification), nameof(ChatNotification.SetUp))]
private class ChatNotificationColorsPatch
{
public static bool Prefix(ChatNotification __instance, PlayerControl sender, string text)
{
if (ShipStatus.Instance && !ModOption.ShowChatNotifications)
{
return false;
}
__instance.timeOnScreen = 5f;
__instance.gameObject.SetActive(true);
__instance.SetCosmetics(sender.Data);
string str;
Color color;
try
{
str = ColorUtility.ToHtmlStringRGB(Palette.TextColors[__instance.player.ColorId]);
color = Palette.TextOutlineColors[__instance.player.ColorId];
}
catch
{
Color32 c = Palette.PlayerColors[__instance.player.ColorId];
str = ColorUtility.ToHtmlStringRGB(c);
[HarmonyPatch(typeof(ChatNotification), nameof(ChatNotification.SetUp))]
private class ChatNotificationColorsPatch
{
public static bool Prefix(ChatNotification __instance, PlayerControl sender, string text)
{
if (ShipStatus.Instance && !ModOption.ShowChatNotifications)
{
return false;
}
__instance.timeOnScreen = 5f;
__instance.gameObject.SetActive(true);
__instance.SetCosmetics(sender.Data);
string str;
Color color;
try
{
str = ColorUtility.ToHtmlStringRGB(Palette.TextColors[__instance.player.ColorId]);
color = Palette.TextOutlineColors[__instance.player.ColorId];
}
catch
{
Color32 c = Palette.PlayerColors[__instance.player.ColorId];
str = ColorUtility.ToHtmlStringRGB(c);

color = c.r + c.g + c.b > 180 ? Palette.Black : Palette.White;
Message($"{c.r}, {c.g}, {c.b}");
}
__instance.playerColorText.text = __instance.player.ColorBlindName;
__instance.playerNameText.text = "<color=#" + str + ">" + (string.IsNullOrEmpty(sender.Data.PlayerName) ? "..." : sender.Data.PlayerName);
__instance.playerNameText.outlineColor = color;
__instance.chatText.text = text;
return false;
}
}
color = c.r + c.g + c.b > 180 ? Palette.Black : Palette.White;
Message($"{c.r}, {c.g}, {c.b}");
}
__instance.playerColorText.text = __instance.player.ColorBlindName;
__instance.playerNameText.text = "<color=#" + str + ">" + (string.IsNullOrEmpty(sender.Data.PlayerName) ? "..." : sender.Data.PlayerName);
__instance.playerNameText.outlineColor = color;
__instance.chatText.text = text;
return false;
}
}

[HarmonyPatch(typeof(PlayerTab), nameof(PlayerTab.OnEnable))]
[HarmonyPatch(typeof(PlayerTab), nameof(PlayerTab.OnEnable))]
private static class PlayerTabEnablePatch
{
public static void Postfix(PlayerTab __instance)
Expand Down
3 changes: 1 addition & 2 deletions TheOtherRoles/CustomCosmetics/CustomHats/CustomHatData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private static bool PopulateFromHatViewDataPrefix(HatParent __instance)
__instance.BackLayer.sprite = asset.MainImage;
}

if (/*!__instance.options.Initialized ||*/ !__instance.HideHat()) return false;
__instance.FrontLayer.enabled = false;
if (/*!__instance.options.Initialized ||*/ !__instance.HideHat()) return false;
__instance.FrontLayer.enabled = false;
__instance.BackLayer.enabled = false;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ internal static class HatsTabPatches
{
private static TextMeshPro textTemplate;

[HarmonyPatch(typeof(HatsTab), nameof(HatsTab.OnEnable))]
[HarmonyPrefix]
private static bool OnEnablePrefix(HatsTab __instance)
{
[HarmonyPatch(typeof(HatsTab), nameof(HatsTab.OnEnable))]
[HarmonyPrefix]
private static bool OnEnablePrefix(HatsTab __instance)
{
for (var i = 0; i < __instance.scroller.Inner.childCount; i++)
{
Object.Destroy(__instance.scroller.Inner.GetChild(i).gameObject);
Expand Down Expand Up @@ -60,8 +60,8 @@ private static bool OnEnablePrefix(HatsTab __instance)
}

__instance.scroller.ContentYBounds.max = -(yOffset + 4.1f);
return false;
}
return false;
}

private static float CreateHatPackage(List<Tuple<HatData, HatExtension>> hats, string packageName, float yStart,
HatsTab hatsTab)
Expand Down
110 changes: 53 additions & 57 deletions TheOtherRoles/CustomGameModes/GameModePatches.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Epic.OnlineServices.Presence;
using HarmonyLib;
using Hazel;
using TheOtherRoles.Utilities;
using TMPro;
using UnityEngine;
using static UnityEngine.UI.Button;
using UnityEngine.Events;
using Hazel;
using static UnityEngine.UI.Button;

namespace TheOtherRoles.CustomGameModes;

namespace TheOtherRoles.CustomGameModes
[HarmonyPatch]
class GameModePatches
{
[HarmonyPatch]
class GameModePatches
{
/*
Creates a button in the info pane in the lobby to cycle through the game modes of TOR.
*/
[HarmonyPatch(typeof(LobbyInfoPane), nameof(LobbyInfoPane.Update))]
class LobbyInfoPanePatch
{
private static GameObject gameModeButton = null;
public static void Postfix(LobbyInfoPane __instance)
{
if (gameModeButton != null || !AmongUsClient.Instance.AmHost) { return; }
var template = GameObject.Find("PRIVATE BUTTON");
var GameModeText = GameObject.Find("GameModeText");
if (template == null || GameModeText == null) { return; }
gameModeButton = GameObject.Instantiate(template, template.transform.parent); //, GameModeText.transform);
gameModeButton.transform.localPosition = template.transform.localPosition + new Vector3(0f, 0.65f, -2f);
gameModeButton.name = "TOR GameModeButton";
var pButton = gameModeButton.GetComponent<PassiveButton>();
pButton.buttonText.text = GameModeText.GetComponent<TextMeshPro>().text;
pButton.OnClick.RemoveAllListeners();
pButton.OnClick = new ButtonClickedEvent();
__instance.StartCoroutine(Effects.Lerp(0.1f, new Action<float>(p => { pButton.buttonText.text = Helpers.cs(Color.yellow, GameModeText.GetComponent<TextMeshPro>().text); })));
gameModeButton.transform.GetChild(1).GetComponent<SpriteRenderer>().color = new Color(0.1f, 0.1f, 0.1f);
gameModeButton.transform.GetChild(2).GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f);
pButton.OnClick.AddListener((Action)(() =>
{
ModOption.gameMode = (CustomGamemodes)((int)(ModOption.gameMode + 1) % Enum.GetNames(typeof(CustomGamemodes)).Length);
__instance.StartCoroutine(Effects.Lerp(0.1f, new Action<float>(p => { pButton.buttonText.text = Helpers.cs(Color.yellow, GameModeText.GetComponent<TextMeshPro>().text); })));
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.ShareGameMode, Hazel.SendOption.Reliable, -1);
writer.Write((byte)ModOption.gameMode);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.shareGameMode((byte)ModOption.gameMode);
}));
pButton.OnMouseOut = new UnityEvent();
pButton.OnMouseOver = new UnityEvent();
pButton.OnMouseOver.AddListener((Action)(() => {
gameModeButton.transform.GetChild(1).gameObject.SetActive(true);
gameModeButton.transform.GetChild(2).gameObject.SetActive(false);
}));
pButton.OnMouseOut.AddListener((Action)(() => {
gameModeButton.transform.GetChild(1).gameObject.SetActive(false);
gameModeButton.transform.GetChild(2).gameObject.SetActive(true);
}));
}
}
}
/*
Creates a button in the info pane in the lobby to cycle through the game modes of TOR.
*/
[HarmonyPatch(typeof(LobbyInfoPane), nameof(LobbyInfoPane.Update))]
private class LobbyInfoPanePatch
{
private static GameObject gameModeButton;
public static void Postfix(LobbyInfoPane __instance)
{
if (gameModeButton != null || !AmongUsClient.Instance.AmHost) { return; }
var template = GameObject.Find("PRIVATE BUTTON");
var GameModeText = GameObject.Find("GameModeText");
if (template == null || GameModeText == null) { return; }
gameModeButton = UnityEngine.Object.Instantiate(template, template.transform.parent); //, GameModeText.transform);
gameModeButton.transform.localPosition = template.transform.localPosition + new Vector3(0f, 0.65f, -2f);
gameModeButton.name = "TOR GameModeButton";
var pButton = gameModeButton.GetComponent<PassiveButton>();
pButton.buttonText.text = GameModeText.GetComponent<TextMeshPro>().text;
pButton.OnClick.RemoveAllListeners();
pButton.OnClick = new ButtonClickedEvent();
__instance.StartCoroutine(Effects.Lerp(0.1f, new Action<float>(p => { pButton.buttonText.text = cs(Color.yellow, GameModeText.GetComponent<TextMeshPro>().text); })));
gameModeButton.transform.GetChild(1).GetComponent<SpriteRenderer>().color = new Color(0.1f, 0.1f, 0.1f);
gameModeButton.transform.GetChild(2).GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f);
pButton.OnClick.AddListener((Action)(() =>
{
ModOption.gameMode = (CustomGamemodes)((int)(ModOption.gameMode + 1) % Enum.GetNames(typeof(CustomGamemodes)).Length);
__instance.StartCoroutine(Effects.Lerp(0.1f, new Action<float>(p => { pButton.buttonText.text = cs(Color.yellow, GameModeText.GetComponent<TextMeshPro>().text); })));
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
(byte)CustomRPC.ShareGameMode, SendOption.Reliable, -1);
writer.Write((byte)ModOption.gameMode);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.shareGameMode((byte)ModOption.gameMode);
}));
pButton.OnMouseOut = new UnityEvent();
pButton.OnMouseOver = new UnityEvent();
pButton.OnMouseOver.AddListener((Action)(() =>
{
gameModeButton.transform.GetChild(1).gameObject.SetActive(true);
gameModeButton.transform.GetChild(2).gameObject.SetActive(false);
}));
pButton.OnMouseOut.AddListener((Action)(() =>
{
gameModeButton.transform.GetChild(1).gameObject.SetActive(false);
gameModeButton.transform.GetChild(2).gameObject.SetActive(true);
}));
}
}
}
Loading

0 comments on commit 0165f57

Please sign in to comment.