Skip to content

Commit

Permalink
v0.5.3 Source
Browse files Browse the repository at this point in the history
  • Loading branch information
AlchlcDvl committed Oct 7, 2023
1 parent c3edf57 commit cca38f7
Show file tree
Hide file tree
Showing 106 changed files with 3,258 additions and 2,295 deletions.
613 changes: 366 additions & 247 deletions README.md

Large diffs are not rendered by default.

65 changes: 27 additions & 38 deletions TownOfUsReworked/Classes/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public static class AssetLoader
{
private const string REPO = "https://raw.githubusercontent.com/AlchlcDvl/ReworkedAssets/main";
private static bool HatsRunning;
//private static bool NameplatesRunning;
private static bool NameplatesRunning;
private static bool VisorsRunning;
private static bool LangRunning;
//public static readonly List<CustomNameplate> NameplateDetails = new();
public static readonly List<CustomNameplate> NameplateDetails = new();
public static readonly List<CustomHat> HatDetails = new();
public static readonly List<CustomVisor> VisorDetails = new();
public static readonly List<Language> AllTranslations = new();
Expand Down Expand Up @@ -54,25 +54,20 @@ public static void LoadAssets()
position2++;
}
}

Cursor.SetCursor(GetSprite("Cursor").texture, Vector2.zero, CursorMode.Auto);
}

public static void LaunchFetchers(bool update)
{
try
{
if (!Loaded)
{
LaunchHatFetcher(update);
//LaunchNameplateFetcher(update);
LaunchVisorFetcher(update);
LaunchTranslationFetcher();
Loaded = true;
}
}
catch
{
Loaded = false;
}
if (Loaded)
return;

LaunchHatFetcher(update);
LaunchVisorFetcher(update);
LaunchNameplateFetcher(update);
LaunchTranslationFetcher();
Loaded = true;
}

private static void LaunchHatFetcher(bool update)
Expand All @@ -85,15 +80,15 @@ private static void LaunchHatFetcher(bool update)
LogMessage("Fetched hats");
}

/*private static void LaunchNameplateFetcher(bool update)
private static void LaunchNameplateFetcher(bool update)
{
if (NameplatesRunning)
return;

NameplatesRunning = true;
_ = LaunchNameplateFetcherAsync(update);
LogMessage("Fetched nameplates");
}*/
}

private static void LaunchVisorFetcher(bool update)
{
Expand Down Expand Up @@ -132,7 +127,7 @@ private static async Task LaunchHatFetcherAsync(bool update)
HatsRunning = false;
}

/*private static async Task LaunchNameplateFetcherAsync(bool update)
private static async Task LaunchNameplateFetcherAsync(bool update)
{
try
{
Expand All @@ -147,7 +142,7 @@ private static async Task LaunchHatFetcherAsync(bool update)
}

NameplatesRunning = false;
}*/
}

private static async Task LaunchVisorFetcherAsync(bool update)
{
Expand Down Expand Up @@ -274,11 +269,9 @@ private static async Task<HttpStatusCode> FetchHats(bool update)
if (hatFileResponse.StatusCode != HttpStatusCode.OK)
continue;

using (var responseStream = await hatFileResponse.Content.ReadAsStreamAsync())
{
using (var fileStream = File.Create($"{TownOfUsReworked.Hats}\\{file}.png"))
responseStream.CopyTo(fileStream);
}
using var responseStream = await hatFileResponse.Content.ReadAsStreamAsync();
using var fileStream = File.Create($"{TownOfUsReworked.Hats}\\{file}.png");
responseStream.CopyTo(fileStream);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -371,11 +364,9 @@ private static async Task<HttpStatusCode> FetchVisors(bool update)
if (visorFileResponse.StatusCode != HttpStatusCode.OK)
continue;

using (var responseStream = await visorFileResponse.Content.ReadAsStreamAsync())
{
using (var fileStream = File.Create($"{TownOfUsReworked.Visors}\\{file}.png"))
responseStream.CopyTo(fileStream);
}
using var responseStream = await visorFileResponse.Content.ReadAsStreamAsync();
using var fileStream = File.Create($"{TownOfUsReworked.Visors}\\{file}.png");
responseStream.CopyTo(fileStream);
}
}
catch (Exception ex)
Expand All @@ -386,7 +377,7 @@ private static async Task<HttpStatusCode> FetchVisors(bool update)
return HttpStatusCode.OK;
}

/*private static async Task<HttpStatusCode> FetchNameplates(bool update)
private static async Task<HttpStatusCode> FetchNameplates(bool update)
{
var http = new HttpClient();
http.DefaultRequestHeaders.CacheControl = new() { NoCache = true };
Expand Down Expand Up @@ -454,11 +445,9 @@ private static async Task<HttpStatusCode> FetchVisors(bool update)
if (nameplateFileResponse.StatusCode != HttpStatusCode.OK)
continue;

using (var responseStream = await nameplateFileResponse.Content.ReadAsStreamAsync())
{
using (var fileStream = File.Create($"{TownOfUsReworked.Nameplates}\\{file}.png"))
responseStream.CopyTo(fileStream);
}
using var responseStream = await nameplateFileResponse.Content.ReadAsStreamAsync();
using var fileStream = File.Create($"{TownOfUsReworked.Nameplates}\\{file}.png");
responseStream.CopyTo(fileStream);
}
}
catch (Exception ex)
Expand All @@ -467,7 +456,7 @@ private static async Task<HttpStatusCode> FetchVisors(bool update)
}

return HttpStatusCode.OK;
}*/
}

private static async Task<HttpStatusCode> FetchTranslations()
{
Expand Down
7 changes: 6 additions & 1 deletion TownOfUsReworked/Classes/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ namespace TownOfUsReworked.Classes;
public static class Logging
{
private static ManualLogSource Log;
public static string SavedLogs;

public static void Init()
{
Log = BepInEx.Logging.Logger.CreateLogSource("Reworked");
//Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
}

private static void LogSomething(object message, LogLevel type) => Log?.Log(type, message);
private static void LogSomething(object message, LogLevel type)
{
Log?.Log(type, message);
SavedLogs += $"[{type}] {message}\n";
}

public static void LogError(object message) => LogSomething(message, LogLevel.Error);

Expand Down
2 changes: 1 addition & 1 deletion TownOfUsReworked/Classes/ModCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public static void Init()
}
catch (Exception e)
{
LogError("Couldn't load compatibilies:\n" + e);
LogError($"Couldn't load compatibilies:\n{e}");
}
}

Expand Down
9 changes: 7 additions & 2 deletions TownOfUsReworked/Classes/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ public static void ReceiveOptionRPC(MessageReader reader)
if (customOption == null)
continue;

//Works but may need to change to gameObject.name check
object value = null;
object val = null;

if (customOption.Type == CustomOptionType.Toggle)
value = reader.ReadBoolean();
else if (customOption.Type == CustomOptionType.Number)
value = reader.ReadSingle();
else if (customOption.Type is CustomOptionType.String or CustomOptionType.Entry)
else if (customOption.Type == CustomOptionType.String)
value = reader.ReadInt32();
else if (customOption.Type == CustomOptionType.Entry)
value = (LayerEnum)reader.ReadInt32();
else if (customOption.Type == CustomOptionType.Layers)
{
value = reader.ReadInt32();
Expand Down Expand Up @@ -173,6 +174,8 @@ public static void CallRpc(params object[] data)
writer.Write(Long);
else if (item is byte[] array)
writer.WriteBytesAndSize(array);
else if (item is List<byte> list)
writer.WriteBytesAndSize(list.ToArray());
else if (item is TargetRPC target)
writer.Write((byte)target);
else if (item is ActionsRPC action)
Expand Down Expand Up @@ -205,6 +208,8 @@ public static void CallRpc(params object[] data)
writer.Write((byte)glitchAction);
else if (item is ThiefActionsRPC thiefAction)
writer.Write((byte)thiefAction);
else if (item is PoliticianActionsRPC polAction)
writer.Write((byte)polAction);
else if (item is MiscRPC misc)
writer.Write((byte)misc);
else if (item is PlayerControl player)
Expand Down
16 changes: 8 additions & 8 deletions TownOfUsReworked/Classes/Regions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public static class ExtraRegions

public static void UpdateRegions()
{
var mna = new StaticHttpRegionInfo("Modded NA", StringNames.NoTranslation, "www.aumods.us", new(new[] { new ServerInfo("Http-1", "https://www.aumods.us", 443, false)
var mna = new StaticHttpRegionInfo("Modded NA (MNA)", StringNames.NoTranslation, "www.aumods.us", new(new[] { new ServerInfo("Http-1", "https://www.aumods.us", 443, false)
})).Cast<IRegionInfo>();

var meu = new StaticHttpRegionInfo("Modded EU", StringNames.NoTranslation, "au-eu.duikbo.at", new(new[] { new ServerInfo("Http-1", "https://au-eu.duikbo.at", 443, false)
var meu = new StaticHttpRegionInfo("Modded EU (MEU)", StringNames.NoTranslation, "au-eu.duikbo.at", new(new[] { new ServerInfo("Http-1", "https://au-eu.duikbo.at", 443, false)
})).Cast<IRegionInfo>();

var mas = new StaticHttpRegionInfo("Modded Asia", StringNames.NoTranslation, "au-as.duikbo.at", new(new[] { new ServerInfo("Http-1", "https://au-as.duikbo.at", 443, false)
var mas = new StaticHttpRegionInfo("Modded Asia (MAS)", StringNames.NoTranslation, "au-as.duikbo.at", new(new[] { new ServerInfo("Http-1", "https://au-as.duikbo.at", 443, false)
})).Cast<IRegionInfo>();

var custom = new StaticHttpRegionInfo("Custom", StringNames.NoTranslation, TownOfUsReworked.Ip.Value, new(new[] { new ServerInfo("Custom", TownOfUsReworked.Ip.Value,
Expand Down Expand Up @@ -132,19 +132,19 @@ private static IRegionInfo[] ParseRegions(string regions)
}
}

public static void CorrectCurrentRegion(ServerManager instance)
public static void CorrectCurrentRegion(ServerManager __instance)
{
var region = instance.CurrentRegion;
var region = __instance.CurrentRegion;
LogInfo($"Current region: {region.Name} ({region.Servers.Length} servers)");
LogInfo($"Region \"{region.Servers[0].Name}\" @ {region.Servers[0].Ip}:{region.Servers[0].Port}");

if (ParsedRegions != null && ParsedRegions.ContainsKey(region.Name))
{
instance.CurrentRegion = ParsedRegions[region.Name];
__instance.CurrentRegion = ParsedRegions[region.Name];
LogInfo("Loading region from cache instead of from file");

if (region.Servers[0].Port != instance.CurrentRegion.Servers[0].Port)
LogInfo($"Port corrected from {region.Servers[0].Port} to {instance.CurrentRegion.Servers[0].Port}");
if (region.Servers[0].Port != __instance.CurrentRegion.Servers[0].Port)
LogInfo($"Port corrected from {region.Servers[0].Port} to {__instance.CurrentRegion.Servers[0].Port}");
}
}
}
Loading

0 comments on commit cca38f7

Please sign in to comment.