Skip to content

Commit

Permalink
Merge pull request #182 from JieGeLovesDengDuaLang/main
Browse files Browse the repository at this point in the history
修改
  • Loading branch information
JieGeLovesDengDuaLang authored Aug 20, 2024
2 parents 5043cb1 + 636757e commit 51aa382
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 62 deletions.
30 changes: 10 additions & 20 deletions COG/Listener/Impl/HelpInnerslothFixVanillaBugsListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace COG.Listener.Impl;

public class VanillaBugFixListener : IListener
{
public static bool OccuredBlackoutOnAirship { get; set; }

[EventHandler(EventHandlerType.Postfix)]
public void OnSelectRole(RoleManagerSelectRolesEvent _)
{
Expand All @@ -22,24 +20,24 @@ public void OnSelectRole(RoleManagerSelectRolesEvent _)
}
}

public void OnEjectionEnd()
public void OnEjectionEnd(ExileController controller)
{
HudManager.Instance.StartCoroutine(CoFixBlackout().WrapToIl2Cpp());
controller.StartCoroutine(CoFixBlackout(controller).WrapToIl2Cpp());
}

[EventHandler(EventHandlerType.Postfix)]
public void OnAirshipEjectionEnd(PlayerExileEndOnAirshipEvent @event)
{
OnEjectionEnd();
OnEjectionEnd(@event.Controller);
}

[EventHandler(EventHandlerType.Postfix)]
public void OnOtherMapEjectionEnd(PlayerExileEndEvent @event)
{
OnEjectionEnd();
OnEjectionEnd(@event.ExileController);
}

public IEnumerator CoFixBlackout()
public IEnumerator CoFixBlackout(ExileController controller)
{
Main.Logger.LogInfo("Checking if blackout occured...");

Expand All @@ -51,23 +49,15 @@ public IEnumerator CoFixBlackout()
if (!fullScr.active) yield break;

Main.Logger.LogWarning("After-meeting blackout bug has occured. Trying to fix...");
var auClient = AmongUsClient.Instance;
var mapId = (MapNames)(auClient.NetworkMode == NetworkModes.FreePlay
? auClient.TutorialMapId
: GameUtils.GetGameOptions().MapId);
var mapId = (MapNames)GameUtils.GetGameOptions().MapId;

if (mapId is MapNames.Airship)
{
var ship = ShipStatus.Instance;
ship.StartCoroutine(ship.PrespawnStep());
Main.Logger.LogInfo("Fixed successfully! Now fix SpawnInMiniGame and FollowerCamera...");
OccuredBlackoutOnAirship = true;
}
else
{
hud.StartCoroutine(hud.CoFadeFullScreen(new Color(0, 0, 0, 1), new Color(0, 0, 0, 0)));
hud.PlayerCam.Locked = false;
Main.Logger.LogInfo("Fixed successfully!");
yield return ship.PrespawnStep();
}

controller.ReEnableGameplay();
Main.Logger.LogInfo("Fixed successfully!");
}
}
3 changes: 2 additions & 1 deletion COG/Patch/GameSettingMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace COG.Patch;
internal static class GameSettingMenuPatch
{
[HarmonyPatch(nameof(GameSettingMenu.Close))]
[HarmonyPatch(nameof(GameSettingMenu.Start))]
[HarmonyPostfix]
public static void OnClose()
public static void ResetOptionData()
{
RoleOptionPatch.CampTabs.Clear();
RoleOptionPatch.CurrentTab = null;
Expand Down
2 changes: 0 additions & 2 deletions COG/Patch/OptionBehaviourPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private static void OptionNamePatch(OptionBehaviour __instance)
if (__instance is ToggleOption toggle)
{
toggle.CheckMark.enabled = customOption.GetBool();
toggle.GetComponentInChildren<PassiveButton>().SelectButton(customOption.GetBool());
}
else if (__instance is NumberOption number)
{
Expand Down Expand Up @@ -114,7 +113,6 @@ private static bool SetAsPlayerPatch(OptionBehaviour __instance)
return false;
}


return true;
}
}
32 changes: 27 additions & 5 deletions COG/Patch/RoleSettingMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

namespace COG.Patch;

// FIXME
// 有时候勾选框的背景会消失

[HarmonyPatch(typeof(RolesSettingsMenu))]
public static class RoleOptionPatch
{
Expand Down Expand Up @@ -309,7 +306,6 @@ public static void ChangeCustomTab(RolesSettingsMenu menu, GameObject newTab, Pa
{
menu.AdvancedRolesSettings.SetActive(false);
CurrentAdvancedTabFor = null;
//menu.selectedRoleTab = CampTabs.Values.Select(pair => pair.gameObject).ToList().IndexOf(newTab);

CloseAllTab(menu);
OpenTab(newTab, toSelect);
Expand Down Expand Up @@ -348,9 +344,35 @@ private static void OpenTab(GameObject tabToOpen, PassiveButton button)

[HarmonyPatch(nameof(RolesSettingsMenu.CloseMenu))]
[HarmonyPrefix]
public static void OnMenuClose()
public static void OnMenuClosing()
{
SetButtonActive(CurrentButton!, false);
if (CurrentTab) CurrentTab!.SetActive(false);
}

[HarmonyPatch(nameof(RolesSettingsMenu.RefreshChildren))]
[HarmonyPostfix]
public static void OnMenuRefreshing()
{
if (AmongUsClient.Instance.AmHost) return; // This patch is for clients who are previewing the settings to update options when the host has changed settings

foreach (var option in CustomRoleManager.GetManager().GetRoles()
.Where(r => r is { IsBaseRole: false, ShowInOptions: true }))
{
option.RoleNumberOption!.OptionBehaviour!.Cast<RoleOptionSetting>().UpdateValuesAndText(null);
option.RoleOptions.Where(o => o.OptionBehaviour).ForEach(o =>
{
var behaviour = o.OptionBehaviour!;
NumberOption numberOption = null!;
StringOption stringOption = null!;
ToggleOption toggleOption = null!;
if (numberOption = behaviour.GetComponent<NumberOption>())
numberOption.Value = o.GetFloat();
else if (stringOption = behaviour.GetComponent<StringOption>())
stringOption.Value = o.Selection;
else if (toggleOption = behaviour.GetComponent<ToggleOption>())
toggleOption.CheckMark.enabled = o.GetBool();
});
}
}
}
20 changes: 0 additions & 20 deletions COG/Patch/SpawnInMinigamePatch.cs

This file was deleted.

2 changes: 1 addition & 1 deletion COG/Role/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override bool Equals(object? obj)

protected string GetContextFromLanguage(string context)
{
var campName = IsSubRole ? "sub-roles" : Enum.GetName(typeof(CampType), CampType)!.ToLower();
var campName = IsSubRole ? "sub-roles" : CampType.ToString().ToLower();
var location = $"role.{campName}.{GetNameInConfig()}.{context}";
var toReturn = LanguageConfig.Instance.YamlReader!
.GetString(location);
Expand Down
44 changes: 39 additions & 5 deletions COG/Role/Impl/Crewmate/Technician.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using COG.Listener;
using COG.Listener.Event.Impl.Player;
using COG.Listener.Event.Impl.VentImpl;
using COG.Rpc;
using COG.UI.CustomButton;
using COG.Utils;
using COG.Utils.Coding;
using UnityEngine;
using static Il2CppSystem.TimeZoneInfo;

namespace COG.Role.Impl.Crewmate;

Expand All @@ -13,6 +15,8 @@ public class Technician : CustomRole
{
public Technician() : base(Palette.Orange, CampType.Crewmate)
{
CanVent = true;

RepairButton = CustomButton.Create(() =>
{
RpcUtils.StartRpcImmediately(PlayerControl.LocalPlayer, KnownRpc.ClearSabotages).Finish();
Expand All @@ -23,24 +27,54 @@ public Technician() : base(Palette.Orange, CampType.Crewmate)
() => true,
ResourceUtils.LoadSprite("COG.Resources.InDLL.Images.Buttons.Repair.png")!,
2,
KeyCode.F,
KeyCode.R,
"REPAIR",
() => 0f,
2
);

AddButton(RepairButton);
}

private CustomButton RepairButton { get; }

[EventHandler(EventHandlerType.Postfix)]
public void OnPlayerFixedUpdate(PlayerFixedUpdateEvent _)
public void OnVentCheck(VentCheckEvent @event)
{
var ventButton = HudManager.Instance.ImpostorVentButton;
var data = @event.PlayerInfo;
var player = data.Object;
var vent = @event.Vent;
if (!IsLocalPlayerRole(player)) return;
if (PlayerControl.LocalPlayer.AllTasksCompleted())
{

var dist = float.MaxValue;
var couldUse = (!player.MustCleanVent(vent.Id) || (player.inVent && Vent.currentVent == vent))
&& !data.IsDead && (player.CanMove || player.inVent);
if (ShipStatus.Instance.Systems.TryGetValueSafeIl2Cpp(SystemTypes.Ventilation, out var systemType))
{
var ventilationSystem = systemType.Cast<VentilationSystem>();
if (ventilationSystem != null && ventilationSystem.IsVentCurrentlyBeingCleaned(vent.Id))
couldUse = false;
}
var canUse = couldUse;
if (canUse)
{
var center = player.Collider.bounds.center;
var position = vent.transform.position;
dist = Vector2.Distance(center, position);
canUse &= dist <= vent.UsableDistance
&& !PhysicsHelpers.AnythingBetween(player.Collider, center, position, Constants.ShipOnlyMask, false);
}

@event.SetCanUse(canUse);
@event.SetCouldUse(couldUse);
@event.SetResult(dist);
}
else
{
@event.SetCanUse(false);
@event.SetCouldUse(false);
@event.SetResult(float.MaxValue);
}
}

Expand Down
7 changes: 7 additions & 0 deletions COG/UI/CustomOption/CustomOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using COG.Patch;
using COG.Role;
using COG.Rpc;
using COG.UI.CustomOption.ValueRules;
Expand Down Expand Up @@ -60,6 +61,12 @@ public int Selection
set
{
_selection = value;
var menu = Object.FindObjectOfType<RolesSettingsMenu>();
if (menu)
{
RoleOptionPatch.OnMenuUpdate(menu); // Try update vanilla options
menu?.RefreshChildren();
}
NotifySettingChange();
}
}
Expand Down
16 changes: 8 additions & 8 deletions COG/Utils/PlayerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static void SetCustomRole(this PlayerControl pc, CustomRole role, CustomR
var playerRole = GameUtils.PlayerData.FirstOrDefault(pr => pr.Player.IsSamePlayer(pc));
if (playerRole is not null) GameUtils.PlayerData.Remove(playerRole);

GameUtils.PlayerData.Add(new PlayerData(pc, role, subRoles));
GameUtils.PlayerData.Add(new PlayerData(pc.Data, role, subRoles));
RoleManager.Instance.SetRole(pc, role.BaseRoleType);

Main.Logger.LogInfo($"The role of player {pc.Data.PlayerName} has set to {role.GetNormalName()}");
Expand Down Expand Up @@ -549,7 +549,7 @@ private SerializablePlayerData(byte playerId, int mainRoleId, int[] subRoleIds)

public PlayerData AsPlayerData()
{
return new PlayerData(PlayerUtils.GetPlayerById(PlayerId)!,
return new PlayerData(GameData.Instance.GetPlayerById(PlayerId),
CustomRoleManager.GetManager().GetRoleById(MainRoleId)!,
SubRoleIds.Select(id => CustomRoleManager.GetManager().GetRoleById(id)).ToArray()!);
}
Expand All @@ -563,14 +563,14 @@ public static SerializablePlayerData Of(PlayerData playerData)

public class PlayerData
{
public PlayerData(PlayerControl player, CustomRole role, CustomRole[]? subRoles = null)
public PlayerData(NetworkedPlayerInfo data, CustomRole role, CustomRole[]? subRoles = null)
{
Player = player;
Data = player.Data;
Player = data.Object;
Data = data;
Role = role;
PlayerName = player.name;
PlayerId = player.PlayerId;
ColorId = player.cosmetics.ColorId;
PlayerName = data.PlayerName;
PlayerId = data.PlayerId;
ColorId = data.DefaultOutfit.ColorId;
Tags = new List<string>();
SubRoles = subRoles != null
? subRoles.Where(subRole => subRole.IsSubRole).ToArray()
Expand Down
7 changes: 7 additions & 0 deletions COG/Utils/RpcUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ internal RpcWriter(MessageWriter[] writers)
_writers = writers;
}

public RpcWriter WriteAll(params dynamic[] values)
{
foreach (var messageWriter in _writers)
values.ForEach(v => messageWriter.Write(v));
return this;
}

public RpcWriter Write(bool value)
{
foreach (var messageWriter in _writers) messageWriter.Write(value);
Expand Down

0 comments on commit 51aa382

Please sign in to comment.