fork from TMWC2024 plugin

This commit is contained in:
Beu
2024-12-13 11:09:07 +01:00
commit 383b386604
2 changed files with 157 additions and 0 deletions

151
main.as Executable file
View File

@@ -0,0 +1,151 @@
const array<string> 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<CTrackManiaNetwork>(GetApp().Network);
/**
* Unload already loaded custom UI
*/
if (Network.ClientManiaAppPlayground !is null) {
CGameManiaAppPlayground @ManiaApp = Network.ClientManiaAppPlayground;
array<string> Manialinks = GetManialinkFiles();
array<string> CustomInterfacesIds;
for (uint i = 0; i < Manialinks.Length; i++) {
CustomInterfacesIds.InsertLast(Path::GetFileNameWithoutExtension(Manialinks[i]));
}
MwFastBuffer<CGameUILayer@> UILayers = ManiaApp.UILayers;
for (uint i = 0; i < UILayers.Length; i++) {
CGameUILayer @UILayer = UILayers[i];
string ManialinkPage = UILayer.ManialinkPage;
array<string> FirstLines = ManialinkPage.Split("\n", 5);
if (FirstLines.Length > 0) {
for (uint j = 0; j < FirstLines.Length - 1; j++) {
if (FirstLines[j].Contains('<manialink ')) {
string[] match = Regex::Search(FirstLines[j], 'name="(\\w*)"');
if (match.Length == 2) {
string LayerId = match[1];
if (LayerId.StartsWith('Custom_TMWC2024_')) {
if (CustomInterfacesIds.Find(LayerId) > -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<CGameUILayer@> UILayers = ManiaApp.UILayers;
if (count != UILayers.Length) {
print('Walking through UILayers');
array<string> CustomUIModulesLoaded = {};
for (uint i = 0; i < UILayers.Length; i++) {
CGameUILayer @UILayer = UILayers[i];
string ManialinkPage = UILayer.ManialinkPage;
array<string> FirstLines = ManialinkPage.Split("\n", 5);
if (FirstLines.Length > 0) {
for (uint j = 0; j < FirstLines.Length - 1; j++) {
if (FirstLines[j].Contains('<manialink ')) {
string[] match = Regex::Search(FirstLines[j], 'name="(\\w*)"');
if (match.Length == 2) {
string id = match[1];
/**
* Delete UI
*/
if (C_ModuleToDisable.Find(id) > -1) {
print('Deleting ' + id);
ManiaApp.UILayerDestroy(UILayers[i]);
}
if (id.StartsWith('Custom_TMWC2024_')) {
CustomUIModulesLoaded.InsertLast(id);
}
}
}
}
}
}
array<string> 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<string> GetManialinkFiles() {
return IO::IndexFolder(Meta::ExecutingPlugin().SourcePath + '/Manialinks/', false);
}
string GetManialinkPage(string _Id) {
IO::FileSource Xml('Manialinks/' + _Id + '.xml');
return Xml.ReadToEnd();
}