2021-02-06 18:09:13 -06:00
|
|
|
|
/* This file is part of libWiiSharp
|
|
|
|
|
* Copyright (C) 2009 Leathl
|
2022-03-18 02:09:26 -05:00
|
|
|
|
* Copyright (C) 2020 - 2022 TheShadowEevee, Github Contributors
|
2021-02-06 18:09:13 -06:00
|
|
|
|
*
|
|
|
|
|
* libWiiSharp is free software: you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as published
|
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* libWiiSharp is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace libWiiSharp
|
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public class Brlyt
|
|
|
|
|
{
|
2021-02-07 12:37:46 -06:00
|
|
|
|
#region Public Functions
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all TPLs that are required by the brlyt.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pathToBrlyt"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-02-06 22:53:40 -06:00
|
|
|
|
public static string[] GetBrlytTpls(string pathToBrlyt)
|
|
|
|
|
{
|
|
|
|
|
return PrivGetBrlytTpls(File.ReadAllBytes(pathToBrlyt));
|
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-07 12:37:46 -06:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all TPLs that are required by the brlyt.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="brlytFile"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-02-06 22:53:40 -06:00
|
|
|
|
public static string[] GetBrlytTpls(byte[] brlytFile)
|
|
|
|
|
{
|
|
|
|
|
return PrivGetBrlytTpls(brlytFile);
|
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-07 12:37:46 -06:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all TPLs that are required by the brlyt.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wad"></param>
|
|
|
|
|
/// <param name="banner"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-02-06 18:09:13 -06:00
|
|
|
|
public static string[] GetBrlytTpls(WAD wad, bool banner)
|
2020-12-28 22:28:44 -06:00
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
if (!wad.HasBanner)
|
2021-02-06 22:53:40 -06:00
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
return new string[0];
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string str = nameof(banner);
|
2021-02-06 18:09:13 -06:00
|
|
|
|
if (!banner)
|
2021-02-06 22:53:40 -06:00
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
str = "icon";
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
for (int index1 = 0; index1 < wad.BannerApp.Nodes.Count; ++index1)
|
|
|
|
|
{
|
|
|
|
|
if (wad.BannerApp.StringTable[index1].ToLower() == str + ".bin")
|
|
|
|
|
{
|
|
|
|
|
U8 u8 = U8.Load(wad.BannerApp.Data[index1]);
|
|
|
|
|
string[] a = new string[0];
|
|
|
|
|
for (int index2 = 0; index2 < u8.Nodes.Count; ++index2)
|
|
|
|
|
{
|
|
|
|
|
if (u8.StringTable[index2].ToLower() == str + ".brlyt")
|
2021-02-06 22:53:40 -06:00
|
|
|
|
{
|
2021-02-07 12:37:46 -06:00
|
|
|
|
a = Shared.MergeStringArrays(a, GetBrlytTpls(u8.Data[index2]));
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new string[0];
|
2020-12-28 22:28:44 -06:00
|
|
|
|
}
|
2021-02-07 12:37:46 -06:00
|
|
|
|
#endregion
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-07 12:37:46 -06:00
|
|
|
|
#region Private Functions
|
2021-02-06 22:53:40 -06:00
|
|
|
|
private static string[] PrivGetBrlytTpls(byte[] brlytFile)
|
2021-02-06 18:09:13 -06:00
|
|
|
|
{
|
|
|
|
|
List<string> stringList = new List<string>();
|
2021-02-07 12:37:46 -06:00
|
|
|
|
int numOfTpls = GetNumOfTpls(brlytFile);
|
2021-02-06 18:09:13 -06:00
|
|
|
|
int index1 = 48 + numOfTpls * 8;
|
|
|
|
|
for (int index2 = 0; index2 < numOfTpls; ++index2)
|
|
|
|
|
{
|
|
|
|
|
string empty = string.Empty;
|
2021-02-06 22:53:40 -06:00
|
|
|
|
while (brlytFile[index1] != 0)
|
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
empty += Convert.ToChar(brlytFile[index1++]).ToString();
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 18:09:13 -06:00
|
|
|
|
stringList.Add(empty);
|
|
|
|
|
++index1;
|
|
|
|
|
}
|
|
|
|
|
for (int index2 = stringList.Count - 1; index2 >= 0; --index2)
|
|
|
|
|
{
|
|
|
|
|
if (!stringList[index2].ToLower().EndsWith(".tpl"))
|
2021-02-06 22:53:40 -06:00
|
|
|
|
{
|
2021-02-06 18:09:13 -06:00
|
|
|
|
stringList.RemoveAt(index2);
|
2021-02-06 22:53:40 -06:00
|
|
|
|
}
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
|
|
|
|
return stringList.ToArray();
|
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
|
2021-02-06 22:53:40 -06:00
|
|
|
|
private static int GetNumOfTpls(byte[] brlytFile)
|
|
|
|
|
{
|
|
|
|
|
return Shared.Swap(BitConverter.ToUInt16(brlytFile, 44));
|
|
|
|
|
}
|
2021-02-07 12:37:46 -06:00
|
|
|
|
#endregion
|
2021-02-06 18:09:13 -06:00
|
|
|
|
}
|
2020-12-28 22:28:44 -06:00
|
|
|
|
}
|