From 383b386604c0f6e13febef828bbdf2916ebf9449 Mon Sep 17 00:00:00 2001 From: beu Date: Fri, 13 Dec 2024 11:09:07 +0100 Subject: [PATCH] fork from TMWC2024 plugin --- info.toml | 6 +++ main.as | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100755 info.toml create mode 100755 main.as diff --git a/info.toml b/info.toml new file mode 100755 index 0000000..3cf05ac --- /dev/null +++ b/info.toml @@ -0,0 +1,6 @@ +[meta] +name = "Custom Interfaces Loader" +#siteid = 484 +author = "Beu" +category = "Interfaces" +version = "0.1" \ No newline at end of file diff --git a/main.as b/main.as new file mode 100755 index 0000000..507dd27 --- /dev/null +++ b/main.as @@ -0,0 +1,151 @@ +const array C_ModuleToDisable = { + "UIModule_ChampionSpring2022_MatchInfo", + "UIModule_ChampionSpring2022_ScoresHeader", + "UIModule_ChampionSpring2022_Sponsors", + "UIModule_ChampionCup_LiveRanking", + "UIModule_ChampionCup_SpectatorInfo", + "UIModule_ChampionCup_Chat", + "UIModule_ChampionCup_MapInfo", + "UIModule_ChampionCup_Countdown", + "UIModule_Race_ScoresTable", + "UIModule_ChampionCup_Sign16x9_1", + "UIModule_ChampionCup_Sign16x9_2", + "UIModule_ChampionCup_Sign16x9_3", + "UIModule_ChampionCup_Sign16x9_4", + "UIModule_ChampionCup_Sign16x9_5", + "UIModule_ChampionCup_Sign64x10_64x10_Start", + "UIModule_ChampionCup_Sign64x10_64x10_Finish", + "UIModule_ChampionCup_Sign64x10_64x10_Checkpoint", + "UIModule_ChampionCup_Sign2x3_1" +}; + +void Main() { + auto Network = cast(GetApp().Network); + + /** + * Unload already loaded custom UI + */ + if (Network.ClientManiaAppPlayground !is null) { + CGameManiaAppPlayground @ManiaApp = Network.ClientManiaAppPlayground; + array Manialinks = GetManialinkFiles(); + + array CustomInterfacesIds; + + for (uint i = 0; i < Manialinks.Length; i++) { + CustomInterfacesIds.InsertLast(Path::GetFileNameWithoutExtension(Manialinks[i])); + } + + MwFastBuffer UILayers = ManiaApp.UILayers; + + for (uint i = 0; i < UILayers.Length; i++) { + CGameUILayer @UILayer = UILayers[i]; + string ManialinkPage = UILayer.ManialinkPage; + array FirstLines = ManialinkPage.Split("\n", 5); + if (FirstLines.Length > 0) { + for (uint j = 0; j < FirstLines.Length - 1; j++) { + if (FirstLines[j].Contains(' -1) { + print("Updating existing layer " + LayerId); + UILayer.ManialinkPage = GetManialinkPage(LayerId); + } else { + print("Destroying not existing layer " + LayerId); + ManiaApp.UILayerDestroy(UILayer); + } + } + } + } + } + } + } + } + + uint count = 0; + + while(true) { + yield(); + if (Network.ClientManiaAppPlayground !is null) { + CGameManiaAppPlayground @ManiaApp = Network.ClientManiaAppPlayground; + MwFastBuffer UILayers = ManiaApp.UILayers; + + if (count != UILayers.Length) { + print('Walking through UILayers'); + + array CustomUIModulesLoaded = {}; + + for (uint i = 0; i < UILayers.Length; i++) { + CGameUILayer @UILayer = UILayers[i]; + string ManialinkPage = UILayer.ManialinkPage; + array FirstLines = ManialinkPage.Split("\n", 5); + if (FirstLines.Length > 0) { + for (uint j = 0; j < FirstLines.Length - 1; j++) { + if (FirstLines[j].Contains(' -1) { + print('Deleting ' + id); + ManiaApp.UILayerDestroy(UILayers[i]); + } + + if (id.StartsWith('Custom_TMWC2024_')) { + CustomUIModulesLoaded.InsertLast(id); + } + } + } + } + } + } + + array Manialinks = GetManialinkFiles(); + + for (uint i = 0; i < Manialinks.Length; i++) { + string FilePath = Manialinks[i]; + string FileName = Path::GetFileName(FilePath); + if (FileName.EndsWith('.xml')) { + string LayerId = Path::GetFileNameWithoutExtension(FileName); + if (CustomUIModulesLoaded.Find(LayerId) == -1) { + print("Loading layer " + LayerId); + CGameUILayer @UILayer = ManiaApp.UILayerCreate(); + UILayer.ManialinkPage = GetManialinkPage(LayerId); + + if (LayerId.Contains("_Sign16x9Small") || LayerId.Contains("_Sign155Small")) { + UILayer.Type = CGameUILayer::EUILayerType::ScreenIn3d; + UILayer.AttachId = "155_StadiumSmall"; + } else if (LayerId.Contains("_Sign16x9") || LayerId.Contains("_Sign155")) { + UILayer.Type = CGameUILayer::EUILayerType::ScreenIn3d; + UILayer.AttachId = "155_Stadium"; + } else if (LayerId.Contains("_Sign2x3")) { + UILayer.Type = CGameUILayer::EUILayerType::ScreenIn3d; + UILayer.AttachId = "2x3_Stadium"; + } else if (LayerId.Contains("_Markers")) { + UILayer.Type = CGameUILayer::EUILayerType::Markers; + } + } + } + } + + count = ManiaApp.UILayers.Length; + } + } else { + count = 0; + } + } +} + +array GetManialinkFiles() { + return IO::IndexFolder(Meta::ExecutingPlugin().SourcePath + '/Manialinks/', false); +} + +string GetManialinkPage(string _Id) { + IO::FileSource Xml('Manialinks/' + _Id + '.xml'); + return Xml.ReadToEnd(); +} \ No newline at end of file