Skip to content

Commit

Permalink
Lobby QoL
Browse files Browse the repository at this point in the history
  • Loading branch information
tma02 committed Dec 12, 2024
1 parent 51a416f commit 64b3a77
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 49 deletions.
13 changes: 9 additions & 4 deletions Teemaw.Calico/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ public class Config
{
[JsonInclude] public bool DynamicZonesEnabled = true;
[JsonInclude] public bool LoadingWaitTimeoutEnabled = true;
[JsonInclude] public bool LobbyIdsEnabled = false;
[JsonInclude] public bool LobbyQolEnabled = true;
[JsonInclude] public bool MapSoundOptimizationsEnabled = true;
[JsonInclude] public bool MeshGpuInstancingEnabled = true;
[JsonInclude] public bool MultiThreadNetworkingEnabled = true;
[JsonInclude] public bool PlayerOptimizationsEnabled = true;
[JsonInclude] public bool ReducePhysicsUpdatesEnabled = true;
[JsonInclude] public bool SmoothCameraEnabled = true;

public override string ToString()
{
return $"DynamicZonesEnabled={DynamicZonesEnabled}, " +
return $"DynamicZonesEnabled={DynamicZonesEnabled}, " +
$"LoadingWaitTimeoutEnabled={LoadingWaitTimeoutEnabled}, " +
$"LobbyIdsEnabled={LobbyIdsEnabled}, " +
$"LobbyQolEnabled={LobbyQolEnabled}, " +
$"MapSoundOptimizationsEnabled={MapSoundOptimizationsEnabled}, " +
$"MeshGpuInstancingEnabled={MeshGpuInstancingEnabled}, " +
$"MultiThreadNetworkingEnabled={MultiThreadNetworkingEnabled}, " +
$"PlayerOptimizationsEnabled={PlayerOptimizationsEnabled}, " +
$"ReducePhysicsUpdatesEnabled={ReducePhysicsUpdatesEnabled}, " +
$"SmoothCameraEnabled={SmoothCameraEnabled}";
}

public bool AnyEnabled() =>
DynamicZonesEnabled || LoadingWaitTimeoutEnabled || LobbyQolEnabled || MapSoundOptimizationsEnabled
|| MeshGpuInstancingEnabled || MultiThreadNetworkingEnabled || PlayerOptimizationsEnabled
|| ReducePhysicsUpdatesEnabled || SmoothCameraEnabled;
}
10 changes: 5 additions & 5 deletions Teemaw.Calico/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using GDWeave;
using Teemaw.Calico.ScriptMod;
using Teemaw.Calico.ScriptMod.LobbyId;
using Teemaw.Calico.ScriptMod.LobbyQol;

namespace Teemaw.Calico;

Expand Down Expand Up @@ -71,11 +71,11 @@ public Mod(IModInterface modInterface)
modInterface.RegisterScriptMod(LoadingMenuScriptModFactory.Create(modInterface));
}

if (config.LobbyIdsEnabled)
if (config.LobbyQolEnabled)
{
modInterface.RegisterScriptMod(LobbyIdSteamNetworkScriptModFactory.Create(modInterface));
modInterface.RegisterScriptMod(LobbyIdMainMenuScriptModFactory.Create(modInterface));
modInterface.RegisterScriptMod(LobbyIdEscMenuScriptModFactory.Create(modInterface));
modInterface.RegisterScriptMod(LobbyQolSteamNetworkScriptModFactory.Create(modInterface, config));
modInterface.RegisterScriptMod(LobbyQolMainMenuScriptModFactory.Create(modInterface));
modInterface.RegisterScriptMod(LobbyQolEscMenuScriptModFactory.Create(modInterface));
}
}

Expand Down
31 changes: 0 additions & 31 deletions Teemaw.Calico/ScriptMod/LobbyId/LobbyIdMainMenuScriptModFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using static Teemaw.Calico.LexicalTransformer.Operation;
using static Teemaw.Calico.LexicalTransformer.TransformationPatternFactory;

namespace Teemaw.Calico.ScriptMod.LobbyId;
namespace Teemaw.Calico.ScriptMod.LobbyQol;

public static class LobbyIdEscMenuScriptModFactory
public static class LobbyQolEscMenuScriptModFactory
{
public static IScriptMod Create(IModInterface mod)
{
return new TransformationRuleScriptModBuilder()
.ForMod(mod)
.Named("LobbyIdEscMenuScriptMod")
.Named("LobbyQolEscMenuScriptMod")
.Patching("res://Scenes/HUD/Esc Menu/esc_menu.gdc")
.AddRule(new TransformationRuleBuilder()
.Named("globals")
Expand Down Expand Up @@ -44,10 +44,14 @@ func calico_on_copy_paste_pressed():
calico_code_show = $VBoxContainer/code_show.duplicate()
calico_code_show.text = "Calico: Show Lobby ID"
calico_code_show.get_node("TooltipNode").header = "Show Lobby ID"
calico_code_show.get_node("TooltipNode").body = "Shows the current game's lobby ID. Other lobbies can never have the same ID. Players with Calico can join with this ID!"
calico_code_show.disconnect("pressed", self, "_on_code_pressed")
calico_code_show.connect("pressed", self, "calico_on_show_code_pressed")
calico_code_display = $VBoxContainer/code_display.duplicate()
calico_code_display.get_node("copy_paste").disconnect("pressed", self, "_on_copy_paste_pressed")
calico_code_display.get_node("copy_paste").get_node("TooltipNode").header = "Copy Lobby ID"
calico_code_display.get_node("copy_paste").get_node("TooltipNode").body = "Copies the lobby ID to your clipboard."
calico_code_display.get_node("copy_paste").connect("pressed", self, "calico_on_copy_paste_pressed")
calico_code_label = calico_code_display.get_node("Panel").get_node("code")
$VBoxContainer.add_child(calico_code_show)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using GDWeave;
using GDWeave.Godot;
using GDWeave.Modding;
using Teemaw.Calico.LexicalTransformer;
using static GDWeave.Godot.TokenType;
using static Teemaw.Calico.LexicalTransformer.Operation;
using static Teemaw.Calico.LexicalTransformer.TransformationPatternFactory;

namespace Teemaw.Calico.ScriptMod.LobbyQol;

public static class LobbyQolMainMenuScriptModFactory
{
public static IScriptMod Create(IModInterface mod)
{
return new TransformationRuleScriptModBuilder()
.ForMod(mod)
.Named("LobbyQolMainMenuScriptMod")
.Patching("res://Scenes/Menus/Main Menu/main_menu.gdc")
.AddRule(new TransformationRuleBuilder()
.Named("globals")
.Matching(CreateGlobalsPattern())
.Do(Append)
.With(
"""
var calico_most_players
func calico_sort_lobbies_desc(a, b):
return Steam.getNumLobbyMembers(a) > Steam.getNumLobbyMembers(b)
"""
)
)
.AddRule(new TransformationRuleBuilder()
.Named("ready")
.Matching(CreateFunctionDefinitionPattern("_ready"))
.Do(Append)
.With(
"""
code.max_length = 14
calico_most_players = $"%hidenames".duplicate()
calico_most_players.text = "MOST USERS"
var calico_tt = $"%hidenames".get_parent().get_node("Label").get_node("TooltipNode").duplicate()
calico_tt.header = "Calico: Most Users"
calico_tt.body = "Sorts the lobby list by user count."
calico_most_players.add_child(calico_tt)
$"%hidenames".get_parent().add_child(calico_most_players)
""", 1
)
)
.AddRule(new TransformationRuleBuilder()
.Named("lobby_list")
.Matching(CreateFunctionDefinitionPattern("_lobby_list_returned", ["lobbies"]))
.Do(Append)
.With(
"""
if calico_most_players.pressed:
lobbies.sort_custom(self, "calico_sort_lobbies_desc")
""", 1
)
)
.AddRule(new TransformationRuleBuilder()
.Named("lobby_list_cap")
.Matching(CreateGdSnippetPattern("if created_lobbies.has(lobby): return"))
.Do(ReplaceLast)
.With(new Token(CfContinue))
)
.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using static Teemaw.Calico.LexicalTransformer.Operation;
using static Teemaw.Calico.LexicalTransformer.TransformationPatternFactory;

namespace Teemaw.Calico.ScriptMod.LobbyId;
namespace Teemaw.Calico.ScriptMod.LobbyQol;

public static class LobbyIdSteamNetworkScriptModFactory
public static class LobbyQolSteamNetworkScriptModFactory
{
public static IScriptMod Create(IModInterface mod)
public static IScriptMod Create(IModInterface mod, Config config)
{
return new TransformationRuleScriptModBuilder()
.ForMod(mod)
.Named("LobbyIdSteamNetworkScriptMod")
.Named("LobbyQolSteamNetworkScriptMod")
.Patching("res://Scenes/Singletons/SteamNetwork.gdc")
.AddRule(new TransformationRuleBuilder()
.Named("globals")
Expand Down Expand Up @@ -74,7 +74,8 @@ func calico_base36_to_decimal(base36_str):
.With(
"""
CALICO_LOBBY_ID = calico_decimal_to_base36(lobby_id)
CALICO_LOBBY_ID = calico_decimal_to_base36(int(lobby_id))
print(CALICO_LOBBY_ID)
""", 1
)
Expand All @@ -87,6 +88,7 @@ func calico_base36_to_decimal(base36_str):
"""
CALICO_LOBBY_ID = calico_decimal_to_base36(lobby_id)
print(CALICO_LOBBY_ID)
""", 2
)
Expand All @@ -100,13 +102,22 @@ func calico_base36_to_decimal(base36_str):
"""
var calicode = code
if code.find("-") != -1:
var use_calicode = false
if code.count("-") == 3:
calicode = calico_base36_to_decimal(code)
use_calicode = true
print("[calico] Calicode decoded as ", calicode)
""", 1
)
)
.AddRule(new TransformationRuleBuilder()
.Named("search_for_lobby_skip_code")
.ScopedTo(CreateFunctionDefinitionPattern("_search_for_lobby", ["code"]))
.Matching(CreateGdSnippetPattern("if lobbies.size() > 0:"))
.Do(ReplaceAll)
.With("if lobbies.size() > 0 && !use_calicode:")
)
.AddRule(new TransformationRuleBuilder()
.Named("search_for_lobby_calicode")
.ScopedTo(CreateFunctionDefinitionPattern("_search_for_lobby", ["code"]))
Expand Down Expand Up @@ -135,6 +146,71 @@ func calico_base36_to_decimal(base36_str):
""", 1
)
)
.AddRule(new TransformationRuleBuilder()
.Named("send_p2p_packet_ignore_banned")
.ScopedTo(CreateGdSnippetPattern(
config.MultiThreadNetworkingEnabled
? "func _calico_send_P2P_packet_on_thread(packet):"
: "func _send_P2P_Packet(packet_data, target = \"all\", type = 0, channel = 0):"))
.Matching(CreateGdSnippetPattern(
"""
for MEMBER in LOBBY_MEMBERS:
Steam.sendP2PPacket(MEMBER["steam_id"], PACKET_DATA, SEND_TYPE, CHANNEL)
""", 2
))
.Do(ReplaceAll)
.With(
"""
for MEMBER in LOBBY_MEMBERS:
if !FORCE_DISCONNECT_PLAYERS.has(MEMBER["steam_id"]):
Steam.sendP2PPacket(MEMBER["steam_id"], PACKET_DATA, SEND_TYPE, CHANNEL)
""", 2
)
)
.AddRule(new TransformationRuleBuilder()
.Named("lobby_chat_update_join")
.ScopedTo(CreateFunctionDefinitionPattern("_on_Lobby_Chat_Update",
["lobby_id", "changed_id", "making_change_id", "chat_state"]))
.Matching(CreateGdSnippetPattern(
"""
_delayed_chat_update_message(making_change_id, "%u joined the game.", 1.5)
emit_signal("_user_connected", making_change_id)
""", 2
))
.Do(ReplaceAll)
.With(
"""
if !FORCE_DISCONNECT_PLAYERS.has(int(making_change_id)):
_delayed_chat_update_message(making_change_id, "%u joined the game.", 1.5)
emit_signal("_user_connected", making_change_id)
""", 2
)
)
.AddRule(new TransformationRuleBuilder()
.Named("lobby_chat_update_leave")
.ScopedTo(CreateFunctionDefinitionPattern("_on_Lobby_Chat_Update",
["lobby_id", "changed_id", "making_change_id", "chat_state"]))
.Matching(CreateGdSnippetPattern(
"""
_recieve_safe_message(making_change_id, "ffeed5", "%u left the game.", false)
emit_signal("_user_disconnected", making_change_id)
Steam.closeP2PSessionWithUser(making_change_id)
""", 2
))
.Do(ReplaceAll)
.With(
"""
if Steam.closeP2PSessionWithUser(making_change_id):
_recieve_safe_message(making_change_id, "ffeed5", "%u left the game.", false)
emit_signal("_user_disconnected", making_change_id)
""", 2
)
)
.Build();
}
}
9 changes: 9 additions & 0 deletions Teemaw.Calico/Util/WeaveUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using GDWeave;

namespace Teemaw.Calico.Util;

public static class WeaveUtil
{
public static bool IsModLoaded(IModInterface modInterface, string modName) =>
modInterface.LoadedMods.Contains(modName);
}

0 comments on commit 64b3a77

Please sign in to comment.