Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Translate System #6

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,8 @@ After that, it's gaming time.
[CrowdedMod](https://github.com/CrowdedMods/CrowdedMod) - For allowing to bypass the 15 player limit and is embedded into the mod\
[Town Of Salem](https://www.blankmediagames.com/TownOfSalem/), [Traitors In Salem](https://www.traitorsinsalem.com) & [Town Of Salem 2](https://store.steampowered.com/app/2140510/Town_of_Salem_2/) - For multiple role ideas

[TheIdealShip](https://github.com/TheIdealShipAU/TheIdealShip) - For Code for translation system

-----------------------

# License
Expand Down
40 changes: 22 additions & 18 deletions TownOfUsReworked.sln
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TownOfUsReworked", "TownOfUsReworked\TownOfUsReworked.csproj", "{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F2C2A857-F42E-4331-B220-4439B2FCA645}
EndGlobalSection
EndGlobal
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B91EF68-B9BB-4138-9DEF-79C91FA554D6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F2C2A857-F42E-4331-B220-4439B2FCA645}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion TownOfUsReworked/BetterMaps/Airship/SpawnInMinigame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool Prefix(SpawnInMinigame __instance)
if (!player.Data.PlayerName.Contains("Robot"))
continue;

var rand = new SRandom().Next(0, __instance.Locations.Count);
var rand = URandom.Range(0, __instance.Locations.Count);
player.gameObject.SetActive(true);
player.NetTransform.RpcSnapTo(__instance.Locations[rand].Location);
}
Expand Down
53 changes: 43 additions & 10 deletions TownOfUsReworked/Classes/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class AssetManager
private static readonly Dictionary<string, float> Sizes = new();
//private static readonly string[] TranslationKeys = Utils.CreateText("Keys", "Languages").Split("\n");
public readonly static Sprite[] PortalAnimation = new Sprite[205];
//public readonly static Dictionary<string, Material> Materials = new();
public readonly static Dictionary<string, string> Presets = new()
{
{ "Casual", Utils.CreateText("Casual", "Presets") },
Expand All @@ -30,6 +31,7 @@ public static class AssetManager
{ 9, TryLoadingSlotSettings(9) },
{ 10, TryLoadingSlotSettings(10) }
};
//public readonly static Dictionary<string, string> MaterialNames = new() { {"Vision", "GlitchedPlayer"} };

public static string TryLoadingDataPreset(string itemName)
{
Expand Down Expand Up @@ -68,10 +70,18 @@ public static AudioClip GetAudio(string path)
return SoundEffects[path];
}

public static Sprite GetSprite(string path)
/*public static Material GetMaterial(string path)
{
return !Sprites.ContainsKey(path) ? MeetingHud.Instance ? Sprites["MeetingPlaceholder"] : Sprites["Placeholder"] : Sprites[path];
}
if (!Materials.ContainsKey(path))
{
Utils.LogSomething($"{path} does not exist");
return null;
}
else
return Materials[path];
}*/

public static Sprite GetSprite(string path) => !Sprites.ContainsKey(path) ? Utils.Meeting ? Sprites["MeetingPlaceholder"] : Sprites["Placeholder"] : Sprites[path];

/*public static string Translate(string id)
{
Expand Down Expand Up @@ -151,7 +161,7 @@ public static unsafe Texture2D LoadResourceTexture(string path)
}
}

public static AudioClip CreateAudio(string path)
/*public static AudioClip CreateAudio(string path)
{
try
{
Expand All @@ -173,14 +183,14 @@ public static AudioClip CreateAudio(string path)
Utils.LogSomething($"Error loading {path}");
return null;
}
}
}*/

public static Sprite CreateSprite(string name)
{
try
{
var sname = name.Replace(".png", "").Replace(TownOfUsReworked.Buttons, "").Replace(TownOfUsReworked.Misc, "").Replace(TownOfUsReworked.Portal, "")
.Replace(TownOfUsReworked.Icons, "");
/*.Replace(TownOfUsReworked.Icons, "")*/;
var tex = LoadResourceTexture(name);
var sprite = Sprite.Create(tex, new(0, 0, tex.width, tex.height), new(0.5f, 0.5f), Sizes[sname]);
sprite.name = sname;
Expand All @@ -195,6 +205,24 @@ public static Sprite CreateSprite(string name)
}
}

/*public static Material CreateMaterial(string path, string materialName)
{
try
{
var stream = TownOfUsReworked.Executing.GetManifestResourceStream(path);
var assets = stream.ReadFully();
var bundle = AssetBundle.LoadFromMemory(assets);
var mat = bundle.LoadAsset<Material>(materialName).DontUnload();
mat.name = materialName;
return mat;
}
catch
{
Utils.LogSomething("Unable to load material: " + path);
return null;
}
}*/

public static void Load()
{
SoundEffects.Clear();
Expand All @@ -207,7 +235,7 @@ public static void Load()
if (resourceName.EndsWith(".png"))
{
var name = resourceName.Replace(".png", "").Replace(TownOfUsReworked.Buttons, "").Replace(TownOfUsReworked.Misc, "").Replace(TownOfUsReworked.Portal, "")
.Replace(TownOfUsReworked.Icons, "");
/*.Replace(TownOfUsReworked.Icons, "")*/;

if (name is "CurrentSettings" or "Help" or "Plus" or "Minus")
Sizes.Add(name, 180);
Expand All @@ -222,10 +250,10 @@ public static void Load()

foreach (var resourceName in TownOfUsReworked.Assembly.GetManifestResourceNames())
{
if ((resourceName.StartsWith(TownOfUsReworked.Buttons) || resourceName.StartsWith(TownOfUsReworked.Misc) || resourceName.StartsWith(TownOfUsReworked.Icons)) &&
if ((resourceName.StartsWith(TownOfUsReworked.Buttons) || resourceName.StartsWith(TownOfUsReworked.Misc)/* || resourceName.StartsWith(TownOfUsReworked.Icons)*/) &&
resourceName.EndsWith(".png"))
{
var name = resourceName.Replace(".png", "").Replace(TownOfUsReworked.Buttons, "").Replace(TownOfUsReworked.Misc, "").Replace(TownOfUsReworked.Icons, "");
var name = resourceName.Replace(".png", "").Replace(TownOfUsReworked.Buttons, "").Replace(TownOfUsReworked.Misc, "")/*.Replace(TownOfUsReworked.Icons, "")*/;
Sprites.Add(name, CreateSprite(resourceName));
}
else if (resourceName.StartsWith(TownOfUsReworked.Portal) && resourceName.EndsWith(".png"))
Expand All @@ -235,11 +263,16 @@ public static void Load()

position2++;
}
/*else if (resourceName.StartsWith(TownOfUsReworked.Materials))
{
var name = resourceName.Replace(TownOfUsReworked.Materials, "");
Materials.Add(name, CreateMaterial(resourceName, MaterialNames[name]));
}
else if (resourceName.StartsWith(TownOfUsReworked.Sounds) && resourceName.EndsWith(".raw"))
{
var name = resourceName.Replace(TownOfUsReworked.Sounds, "").Replace(".raw", "");
SoundEffects.Add(name, CreateAudio(resourceName));
}
}*/
}

/*var translation = Utils.CreateText(GetLanguage(), "Languages").Split("\n");
Expand Down
57 changes: 52 additions & 5 deletions TownOfUsReworked/Classes/ModCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[HarmonyPatch]
public static class ModCompatibility
{
public const string SUBMERGED_GUID = "Submerged";
public const string SM_GUID = "Submerged";
public const string ElevatorMover = "ElevatorMover";
public const ShipStatus.MapType SUBMERGED_MAP_TYPE = (ShipStatus.MapType)5;

Expand Down Expand Up @@ -85,11 +85,17 @@ public static bool DisableO2MaskCheckForEmergency
private static FieldInfo SubmergedInstance;
private static FieldInfo SubmergedElevators;

public static Type CustomPlayerData;
public static FieldInfo hasMap;

public static Type SpawnInState;
public static FieldInfo CurrentState;

private static readonly Harmony SubHarmony = new("tourew.subcompat.patch");

public static void InitializeSubmerged()
{
SubLoaded = IL2CPPChainloader.Instance.Plugins.TryGetValue(SUBMERGED_GUID, out var subPlugin);
SubLoaded = IL2CPPChainloader.Instance.Plugins.TryGetValue(SM_GUID, out var subPlugin);

if (!SubLoaded)
return;
Expand Down Expand Up @@ -140,8 +146,18 @@ public static void InitializeSubmerged()
SubmarineElevatorSystem = SubTypes.First(t => t.Name == "SubmarineElevatorSystem");
UpperDeckIsTargetFloor = AccessTools.Field(SubmarineElevatorSystem, "UpperDeckIsTargetFloor");

CustomPlayerData = SubInjectedTypes.Where(t => t.Key == "CustomPlayerData").Select(x => x.Value).First();
hasMap = AccessTools.Field(CustomPlayerData, "hasMap");

SpawnInState = SubTypes.First(t => t.Name == "SpawnInState");

var subSpawnSystem = SubTypes.First(t => t.Name == "SubmarineSpawnInSystem");
var GetReadyPlayerAmount = AccessTools.Method(subSpawnSystem, "GetReadyPlayerAmount");
CurrentState = AccessTools.Field(subSpawnSystem, "currentState");

//I tried patching normally but it would never work
SubHarmony.Patch(SubmergedExileWrapUpMethod, null, new(SymbolExtensions.GetMethodInfo(() => ExileRoleChangePostfix())));
SubHarmony.Patch(GetReadyPlayerAmount, new(AccessTools.Method(typeof(ModCompatibility), nameof(ReadyPlayerAmount))));
}

public static void CheckOutOfBoundsElevator(PlayerControl player)
Expand Down Expand Up @@ -207,12 +223,12 @@ public static void ExileRoleChangePostfix()

public static IEnumerator WaitStart(Action next)
{
while (HudManager.Instance.UICamera.transform.Find("SpawnInMinigame(Clone)") == null)
while (Utils.HUD.UICamera.transform.Find("SpawnInMinigame(Clone)") == null)
yield return null;

yield return new WaitForSeconds(0.5f);

while (HudManager.Instance.UICamera.transform.Find("SpawnInMinigame(Clone)") != null)
while (Utils.HUD.UICamera.transform.Find("SpawnInMinigame(Clone)") != null)
yield return null;

next();
Expand All @@ -225,7 +241,7 @@ public static IEnumerator WaitMeeting(Action next)

yield return new WaitForSeconds(0.5f);

while (HudManager.Instance.PlayerCam.transform.Find("SpawnInMinigame(Clone)") != null)
while (Utils.HUD.PlayerCam.transform.Find("SpawnInMinigame(Clone)") != null)
yield return null;

next();
Expand Down Expand Up @@ -322,6 +338,31 @@ public static void RepairOxygen()
} catch (NullReferenceException) {}
}

public static bool ReadyPlayerAmount(dynamic __instance, ref int __result)
{
if (!SubLoaded)
return true;

if (TownOfUsReworked.MCIActive)
{
__result = __instance.GetTotalPlayerAmount();
Enum.TryParse(SpawnInState, "Done", true, out var e);
CurrentState.SetValue(__instance, e);
return false;
}

return true;
}

public static void ImpartSub(PlayerControl bot)
{
var comp = TryCast(bot.gameObject.AddComponent(Il2CppType.From(CustomPlayerData)), CustomPlayerData);
hasMap.SetValue(comp, true);
}

public static object TryCast(Il2CppObjectBase self, Type type) => AccessTools.Method(self.GetType(), nameof(Il2CppObjectBase.TryCast)).MakeGenericMethod(type).Invoke(self,
Array.Empty<object>());

public const string LI_GUID = "com.DigiWorm.LevelImposter";
public const ShipStatus.MapType LI_MAP_TYPE = (ShipStatus.MapType)6;

Expand Down Expand Up @@ -404,5 +445,11 @@ public static void InitializeLevelImpostor()
public const string RD_GUID = "gg.reactor.debugger";

//public const string TM_GUID = "me.toppatcrew.toppatmod";

public static void Init()
{
InitializeLevelImpostor();
InitializeSubmerged();
}
}
}
Loading