Skip to content

Commit

Permalink
Merge pull request #1227 from tukasa0001/develop
Browse files Browse the repository at this point in the history
developのマージ (v4.0.1)
  • Loading branch information
tukasa0001 authored Dec 22, 2022
2 parents 0d21910 + 4839fa2 commit 72ebaf1
Show file tree
Hide file tree
Showing 56 changed files with 1,314 additions and 536 deletions.
60 changes: 60 additions & 0 deletions Modules/AURoleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using AmongUs.GameOptions;

namespace TownOfHost
{
public static class AURoleOptions
{
private static IGameOptions Opt;
public static void SetOpt(IGameOptions opt) => Opt = opt;
public static float ScientistCooldown
{
get => Opt.GetFloat(FloatOptionNames.ScientistCooldown);
set => Opt.SetFloat(FloatOptionNames.ScientistCooldown, value);
}
public static float ScientistBatteryCharge
{
get => Opt.GetFloat(FloatOptionNames.ScientistBatteryCharge);
set => Opt.SetFloat(FloatOptionNames.ScientistBatteryCharge, value);
}
public static float EngineerCooldown
{
get => Opt.GetFloat(FloatOptionNames.EngineerCooldown);
set => Opt.SetFloat(FloatOptionNames.EngineerCooldown, value);
}
public static float EngineerInVentMaxTime
{
get => Opt.GetFloat(FloatOptionNames.EngineerInVentMaxTime);
set => Opt.SetFloat(FloatOptionNames.EngineerInVentMaxTime, value);
}
public static float GuardianAngelCooldown
{
get => Opt.GetFloat(FloatOptionNames.GuardianAngelCooldown);
set => Opt.SetFloat(FloatOptionNames.GuardianAngelCooldown, value);
}
public static float ProtectionDurationSeconds
{
get => Opt.GetFloat(FloatOptionNames.ProtectionDurationSeconds);
set => Opt.SetFloat(FloatOptionNames.ProtectionDurationSeconds, value);
}
public static bool ImpostorsCanSeeProtect
{
get => Opt.GetBool(BoolOptionNames.ImpostorsCanSeeProtect);
set => Opt.SetBool(BoolOptionNames.ImpostorsCanSeeProtect, value);
}
public static float ShapeshifterDuration
{
get => Opt.GetFloat(FloatOptionNames.ShapeshifterDuration);
set => Opt.SetFloat(FloatOptionNames.ShapeshifterDuration, value);
}
public static float ShapeshifterCooldown
{
get => Opt.GetFloat(FloatOptionNames.ShapeshifterCooldown);
set => Opt.SetFloat(FloatOptionNames.ShapeshifterCooldown, value);
}
public static bool ShapeshifterLeaveSkin
{
get => Opt.GetBool(BoolOptionNames.ShapeshifterLeaveSkin);
set => Opt.SetBool(BoolOptionNames.ShapeshifterLeaveSkin, value);
}
}
}
3 changes: 2 additions & 1 deletion Modules/AntiBlackout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Hazel;
using AmongUs.GameOptions;

namespace TownOfHost
{
Expand All @@ -14,7 +15,7 @@ public static class AntiBlackout
///<summary>
///インポスターが一人しか存在しない設定かどうか
///</summary>
public static bool IsSingleImpostor => Main.RealOptionsData != null ? Main.RealOptionsData.NumImpostors == 1 : PlayerControl.GameOptions.NumImpostors == 1;
public static bool IsSingleImpostor => Main.RealOptionsData != null ? Main.RealOptionsData.GetInt(Int32OptionNames.NumImpostors) == 1 : Main.NormalOptions.NumImpostors == 1;
///<summary>
///AntiBlackout内の処理が必要であるかどうか
///</summary>
Expand Down
120 changes: 82 additions & 38 deletions Modules/Camouflague.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,116 @@
using System.Collections.Generic;
using HarmonyLib;

namespace TownOfHost
{
static class PlayerOutfitExtension
{
public static GameData.PlayerOutfit Set(this GameData.PlayerOutfit instance, string playerName, int colorId, string hatId, string skinId, string visorId, string petId)
{
instance.PlayerName = playerName;
instance.ColorId = colorId;
instance.HatId = hatId;
instance.SkinId = skinId;
instance.VisorId = visorId;
instance.PetId = petId;
return instance;
}
public static bool Compare(this GameData.PlayerOutfit instance, GameData.PlayerOutfit targetOutfit)
{
return instance.ColorId == targetOutfit.ColorId &&
instance.HatId == targetOutfit.HatId &&
instance.SkinId == targetOutfit.SkinId &&
instance.VisorId == targetOutfit.VisorId &&
instance.PetId == targetOutfit.PetId;

}
public static string GetString(this GameData.PlayerOutfit instance)
{
return $"{instance.PlayerName} Color:{instance.ColorId} {instance.HatId} {instance.SkinId} {instance.VisorId} {instance.PetId}";
}
}
public static class Camouflage
{
public static Dictionary<byte, (int, string, string, string, string)> PlayerSkins = new();
public static void RpcSetSkin(PlayerControl target, bool ForceRevert = false)
static GameData.PlayerOutfit CamouflageOutfit = new GameData.PlayerOutfit().Set("", 15, "", "", "", "");

public static bool IsCamouflage;
public static Dictionary<byte, GameData.PlayerOutfit> PlayerSkins = new();

public static void CheckCamouflage()
{
if (!(AmongUsClient.Instance.AmHost && Options.CommsCamouflage.GetBool())) return;

var oldIsCamouflage = IsCamouflage;

IsCamouflage = Utils.IsActive(SystemTypes.Comms);

if (oldIsCamouflage != IsCamouflage)
{
new LateTask(
() =>
{
PlayerControl.AllPlayerControls.ToArray().Do(pc => Camouflage.RpcSetSkin(pc));
if (!GameStates.IsMeeting)
Utils.NotifyRoles(ForceLoop: true);
}, 0.1f, "Camouflage");
}
}
public static void RpcSetSkin(PlayerControl target, bool ForceRevert = false, bool RevertToDefault = false)
{
if (!(AmongUsClient.Instance.AmHost && Options.CommsCamouflage.GetBool())) return;
if (target == null) return;

var id = target.PlayerId;

int colorId = 15; //グレー
string hatId = "";
string skinId = "";
string visorId = "";
string petId = "";
if (Utils.IsActive(SystemTypes.Comms))
if (IsCamouflage)
{
//コミュサボ中

//死んでいたら処理しない
if (Main.PlayerStates[id].IsDead) return;
}
if (!Utils.IsActive(SystemTypes.Comms) || ForceRevert)

var newOutfit = CamouflageOutfit;

if (!IsCamouflage || ForceRevert)
{
var GetValue = Main.CheckShapeshift.TryGetValue(id, out var shapeshifting);
if (!GetValue && Main.CheckShapeshift.ContainsKey(id)) return;

var outfit = target.CurrentOutfit;
var value = PlayerSkins[id];

if (
outfit.ColorId == value.Item1 &&
outfit.HatId == value.Item2 &&
outfit.SkinId == value.Item3 &&
outfit.VisorId == value.Item4 &&
outfit.PetId == value.Item5
) return; //姿が変わっていないなら処理しない

colorId = shapeshifting ? outfit.ColorId : value.Item1;
hatId = shapeshifting ? outfit.HatId : value.Item2;
skinId = shapeshifting ? outfit.SkinId : value.Item3;
visorId = shapeshifting ? outfit.VisorId : value.Item4;
petId = shapeshifting ? outfit.PetId : value.Item5;
//コミュサボ解除または強制解除

if (Main.CheckShapeshift.TryGetValue(id, out var shapeshifting) && !RevertToDefault)
{
//シェイプシフターなら今の姿のidに変更
id = Main.ShapeshiftTarget[id];
}

newOutfit = PlayerSkins[id];
}
Logger.Info($"newOutfit={newOutfit.GetString()}", "RpcSetSkin");

var sender = CustomRpcSender.Create(name: $"Camouflage.RpcSetSkin({target.Data.PlayerName})");

target.SetColor(colorId);
target.SetColor(newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetColor)
.Write(colorId)
.Write(newOutfit.ColorId)
.EndRpc();

target.SetHat(hatId, colorId);
target.SetHat(newOutfit.HatId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetHatStr)
.Write(hatId)
.Write(newOutfit.HatId)
.EndRpc();

target.SetSkin(skinId, colorId);
target.SetSkin(newOutfit.SkinId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetSkinStr)
.Write(skinId)
.Write(newOutfit.SkinId)
.EndRpc();

target.SetVisor(visorId, colorId);
target.SetVisor(newOutfit.VisorId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetVisorStr)
.Write(visorId)
.Write(newOutfit.VisorId)
.EndRpc();

target.SetPet(petId);
target.SetPet(newOutfit.PetId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetPetStr)
.Write(petId)
.Write(newOutfit.PetId)
.EndRpc();

sender.SendMessage();
Expand Down
6 changes: 4 additions & 2 deletions Modules/CustomRolesHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AmongUs.GameOptions;

namespace TownOfHost
{
static class CustomRolesHelper
Expand Down Expand Up @@ -81,7 +83,7 @@ public static int GetCount(this CustomRoles role)
{
if (role.IsVanilla())
{
RoleOptionsData roleOpt = PlayerControl.GameOptions.RoleOptions;
var roleOpt = Main.NormalOptions.RoleOptions;
return role switch
{
CustomRoles.Engineer => roleOpt.GetNumPerGame(RoleTypes.Engineer),
Expand All @@ -101,7 +103,7 @@ public static float GetChance(this CustomRoles role)
{
if (role.IsVanilla())
{
RoleOptionsData roleOpt = PlayerControl.GameOptions.RoleOptions;
var roleOpt = Main.NormalOptions.RoleOptions;
return role switch
{
CustomRoles.Engineer => roleOpt.GetChancePerGame(RoleTypes.Engineer),
Expand Down
1 change: 1 addition & 0 deletions Modules/CustomRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hazel;
using InnerNet;
using UnhollowerBaseLib;
using AmongUs.GameOptions;

namespace TownOfHost
{
Expand Down
8 changes: 4 additions & 4 deletions Modules/DisableDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DisableDevice
};
public static float UsableDistance()
{
var Map = (MapNames)PlayerControl.GameOptions.MapId;
var Map = (MapNames)Main.NormalOptions.MapId;
return Map switch
{
MapNames.Skeld => 1.8f,
Expand Down Expand Up @@ -63,7 +63,7 @@ public static void FixedUpdate()

if (pc.IsAlive() && !Utils.IsActive(SystemTypes.Comms))
{
switch (PlayerControl.GameOptions.MapId)
switch (Main.NormalOptions.MapId)
{
case 0:
if (Options.DisableSkeldAdmin.GetBool())
Expand Down Expand Up @@ -113,7 +113,7 @@ public static void FixedUpdate()
DesyncComms.Remove(pc.PlayerId);
pc.RpcDesyncRepairSystem(SystemTypes.Comms, 16);

if (PlayerControl.GameOptions.MapId == 1)
if (Main.NormalOptions.MapId == 1)
pc.RpcDesyncRepairSystem(SystemTypes.Comms, 17);
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public static void UpdateDisableDevices()
var admins = GameObject.FindObjectsOfType<MapConsole>(true);
var consoles = GameObject.FindObjectsOfType<SystemConsole>(true);
if (admins == null || consoles == null) return;
switch (PlayerControl.GameOptions.MapId)
switch (Main.NormalOptions.MapId)
{
case 0:
if (Options.DisableSkeldAdmin.GetBool())
Expand Down
8 changes: 7 additions & 1 deletion Modules/ErrorText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public void Update()
{
AllErrors.RemoveAll(err => ToRemove.Contains(err));
UpdateText();
if (HnSFlag)
Destroy(this.gameObject);
}
}
public void LateUpdate()
Expand Down Expand Up @@ -97,7 +99,8 @@ public void UpdateText()
}
else
{
text += $"{GetString($"ErrorLevel{maxLevel}")}";
if (!HnSFlag)
text += $"{GetString($"ErrorLevel{maxLevel}")}";
Text.enabled = true;
}
if (GameStates.IsInGame && maxLevel != 3)
Expand Down Expand Up @@ -133,6 +136,8 @@ public override string ToString()
}
public void IncreaseTimer() => Timer += Time.deltaTime;
}

public bool HnSFlag;
}
public enum ErrorCode
{
Expand All @@ -154,5 +159,6 @@ public enum ErrorCode
TestError1 = 0009101, // 000-910-1 Test Error 1
TestError2 = 0009202, // 000-920-2 Test Error 2
TestError3 = 0009303, // 000-930-3 Test Error 3
HnsUnload = 000_804_1, // 000-804-1 Unloaded By HnS
}
}
Loading

0 comments on commit 72ebaf1

Please sign in to comment.