Skip to content

Commit

Permalink
Create base class for multiplayer clothes resource builders
Browse files Browse the repository at this point in the history
  • Loading branch information
DurtyFree committed Feb 7, 2021
1 parent 1cf99e6 commit 1d9620c
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 222 deletions.
202 changes: 83 additions & 119 deletions altClothTool.App/Builders/AltvResourceBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,136 +1,100 @@
using System.Collections.Generic;
using System.IO;
using RageLib.GTA5.ResourceWrappers.PC.Meta.Structures;
using RageLib.Resources.GTA5.PC.GameFiles;
using RageLib.Resources.GTA5.PC.Meta;
using altClothTool.App.Builders.Base;

namespace altClothTool.App.Builders
{
internal class AltvResourceBuilder
: ResourceBuilderBase
: MultiplayerResourceBuilderBase
{
public override void BuildResource(string outputFolder, string collectionName)
private readonly List<string> _streamCfgMetas = new List<string>();
private readonly List<string> _streamCfgIncludes = new List<string>();

#region Resource Props

protected override void OnFirstPropAddedToResource(string outputFolder, int sexNr, string collectionName)
{
Directory.CreateDirectory($"{outputFolder}\\stream");
Directory.CreateDirectory($"{outputFolder}\\stream\\{FolderNames[sexNr]}_p.rpf");
Directory.CreateDirectory($"{outputFolder}\\stream\\{FolderNames[sexNr]}_p.rpf\\{Prefixes[sexNr]}freemode_01_p_{Prefixes[sexNr]}{collectionName}");
}

protected override void CopyPropTextureToResource(string propTextureFilePath, int sexNr, string outputFolder, string collectionName,
string componentNumerics, string prefix, char offsetLetter)
{
string targetFilePath = $"{outputFolder}\\stream\\{FolderNames[sexNr]}_p.rpf\\{Prefixes[sexNr]}freemode_01_p_{Prefixes[sexNr]}{collectionName}\\{prefix}_diff_{componentNumerics}_{offsetLetter}.ytd";
File.Copy(propTextureFilePath, targetFilePath, true);
}

protected override void CopyPropModelToResource(ClothData propClothData, int sexNr, string outputFolder, string collectionName,
string componentNumerics, string prefix)
{
string targetFilePath = $"{outputFolder}\\stream\\{FolderNames[sexNr]}_p.rpf\\{Prefixes[sexNr]}freemode_01_p_{Prefixes[sexNr]}{collectionName}\\{prefix}_{componentNumerics}.ydd";
File.Copy(propClothData.MainPath, targetFilePath, true);
}

#endregion

#region Resource Clothes

protected override string GetClothYmtFilePath(string outputFolder, int sexNr, string collectionName)
{
return $"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}.ymt";
}

protected override void OnFirstClothAddedToResource(string outputFolder, int sexNr, string collectionName)
{
Directory.CreateDirectory($"{outputFolder}\\stream");
Directory.CreateDirectory($"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf");
Directory.CreateDirectory($"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}");
}

protected override void CopyClothFirstPersonModelToResource(string clothDataFirstPersonModelPath, int sexNr, string outputFolder,
string collectionName, string componentNumerics, string prefix, string yddPostfix)
{
string targetFilePath = $"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}\\{prefix}_{componentNumerics}_{yddPostfix}_1.ydd";
File.Copy(clothDataFirstPersonModelPath, targetFilePath);
}

protected override void CopyClothTextureToResource(string clothTextureFilePath, int sexNr, string outputFolder, string collectionName,
string componentNumerics, string prefix, string ytdPostfix, char offsetLetter)
{
string targetFilePath = $"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}\\{prefix}_diff_{componentNumerics}_{offsetLetter}_{ytdPostfix}.ytd";
File.Copy(clothTextureFilePath, targetFilePath);
}

protected override void CopyClothModelToResource(ClothData clothData, int sexNr, string outputFolder, string collectionName,
string componentNumerics, string prefix, string yddPostfix)
{
string targetFilePath = $"{outputFolder}\\stream\\{FolderNames[sexNr]}.rpf\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}\\{prefix}_{componentNumerics}_{yddPostfix}.ydd";
File.Copy(clothData.MainPath, targetFilePath);
}

#endregion

protected override void OnResourceClothDataFinished(string outputFolder, int sexNr, string collectionName, bool isAnyClothAdded, bool isAnyPropAdded)
{
List<string> streamCfgMetas = new List<string>();
List<string> streamCfgIncludes = new List<string>();
if (isAnyPropAdded)
{
_streamCfgIncludes.Add($"stream/{FolderNames[sexNr]}_p.rpf/*");
}

for(int sexNr = 0; sexNr < 2; ++sexNr)
if (isAnyClothAdded || isAnyPropAdded)
{
//Male YMT generating
YmtPedDefinitionFile ymt = new YmtPedDefinitionFile
{
metaYmtName = Prefixes[sexNr] + collectionName,
Unk_376833625 = {DlcName = RageLib.Hash.Jenkins.Hash(Prefixes[sexNr] + collectionName)}
};

MUnk_3538495220[] componentTextureBindings = { null, null, null, null, null, null, null, null, null, null, null, null };
int[] componentIndexes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int[] propIndexes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

//ymt.Unk_376833625.Unk_1235281004 = 0;
//ymt.Unk_376833625.Unk_4086467184 = 0;
//ymt.Unk_376833625.Unk_911147899 = 0;
//ymt.Unk_376833625.Unk_315291935 = 0;
//ymt.Unk_376833625.Unk_2996560424 = ;

bool isAnyClothAdded = false;
bool isAnyPropAdded = false;

foreach (ClothData clothData in MainWindow.Clothes)
{
if (clothData.IsComponent())
{
if (clothData.Textures.Count <= 0 || (int) clothData.TargetSex != sexNr)
continue;

var componentItemInfo = GenerateYmtPedComponentItem(clothData, ref componentTextureBindings);
ymt.Unk_376833625.CompInfos.Add(componentItemInfo);

var componentTypeId = componentItemInfo.Unk_3509540765;
GetClothPostfixes(clothData, out var ytdPostfix, out var yddPostfix);

if (!isAnyClothAdded)
{
isAnyClothAdded = true;
Directory.CreateDirectory(outputFolder + "\\stream");
Directory.CreateDirectory(outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf");
Directory.CreateDirectory(outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName);
}

int currentComponentIndex = componentIndexes[componentTypeId]++;
string componentNumerics = currentComponentIndex.ToString().PadLeft(3, '0');
string prefix = clothData.GetPrefix();

clothData.SetComponentNumerics(componentNumerics, currentComponentIndex);

File.Copy(clothData.MainPath, outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + "\\" + prefix + "_" + componentNumerics + "_" + yddPostfix + ".ydd");

char offsetLetter = 'a';
for (int i = 0; i < clothData.Textures.Count; ++i)
File.Copy(clothData.Textures[i], outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + "\\" + prefix + "_diff_" + componentNumerics + "_" + (char)(offsetLetter + i) + "_" + ytdPostfix + ".ytd");

if (clothData.FirstPersonModelPath != "")
File.Copy(clothData.FirstPersonModelPath, outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + "\\" + prefix + "_" + componentNumerics + "_" + yddPostfix + "_1.ydd");
}
else
{
if (clothData.Textures.Count <= 0 || (int) clothData.TargetSex != sexNr)
continue;

Unk_2834549053 anchor = (Unk_2834549053)clothData.GetPedPropTypeId();
var defs = ymt.Unk_376833625.PropInfo.Props[anchor] ?? new List<MUnk_94549140>();
var item = GenerateYmtPedPropItem(ymt, anchor, clothData);
defs.Add(item);

if (!isAnyPropAdded)
{
isAnyPropAdded = true;
Directory.CreateDirectory(outputFolder + "\\stream");
Directory.CreateDirectory(outputFolder + "\\stream\\" + FolderNames[sexNr] + "_p.rpf");
Directory.CreateDirectory(outputFolder + "\\stream\\" + FolderNames[sexNr] + "_p.rpf\\" + Prefixes[sexNr] + "freemode_01_p_" + Prefixes[sexNr] + collectionName);
}

int currentPropIndex = propIndexes[(byte)anchor]++;

string componentNumerics = currentPropIndex.ToString().PadLeft(3, '0');
string prefix = clothData.GetPrefix();

clothData.SetComponentNumerics(componentNumerics, currentPropIndex);

File.Copy(clothData.MainPath, outputFolder + "\\stream\\" + FolderNames[sexNr] + "_p.rpf\\" + Prefixes[sexNr] + "freemode_01_p_" + Prefixes[sexNr] + collectionName + "\\" + prefix + "_" + componentNumerics + ".ydd", true);

char offsetLetter = 'a';
for (int i = 0; i < clothData.Textures.Count; ++i)
{
File.Copy(clothData.Textures[i], outputFolder + "\\stream\\" + FolderNames[sexNr] + "_p.rpf\\" + Prefixes[sexNr] + "freemode_01_p_" + Prefixes[sexNr] + collectionName + "\\" + prefix + "_diff_" + componentNumerics + "_" + (char)(offsetLetter + i) + ".ytd", true);
}
}
}
string shopMetaFilePath = $"{outputFolder}\\stream\\{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}.meta";
File.WriteAllText(shopMetaFilePath, GenerateShopMetaContent((ClothData.Sex)sexNr, collectionName));

if (isAnyClothAdded)
{
UpdateYmtComponentTextureBindings(componentTextureBindings, ymt);
ymt.Save(outputFolder + "\\stream\\" + FolderNames[sexNr] + ".rpf\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + ".ymt");
}

if(isAnyPropAdded)
{
streamCfgIncludes.Add("stream/" + FolderNames[sexNr] + "_p.rpf/*");
}

if (isAnyClothAdded || isAnyPropAdded)
{
File.WriteAllText(outputFolder + "\\stream\\" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + ".meta", GenerateShopMetaContent((ClothData.Sex)sexNr, collectionName));
streamCfgMetas.Add("stream/" + Prefixes[sexNr] + "freemode_01_" + Prefixes[sexNr] + collectionName + ".meta: SHOP_PED_APPAREL_META_FILE");

streamCfgIncludes.Add("stream/" + FolderNames[sexNr] + ".rpf/*");
}
_streamCfgMetas.Add($"stream/{Prefixes[sexNr]}freemode_01_{Prefixes[sexNr]}{collectionName}.meta: SHOP_PED_APPAREL_META_FILE");
_streamCfgIncludes.Add($"stream/{FolderNames[sexNr]}.rpf/*");
}
}

File.WriteAllText(outputFolder + "\\stream.cfg", GenerateAltvStreamCfgContent(streamCfgIncludes, streamCfgMetas));
File.WriteAllText(outputFolder + "\\resource.cfg", GenerateAltvResourceCfgContent());
protected override void OnResourceBuildingFinished(string outputFolder)
{
File.WriteAllText($"{outputFolder}\\stream.cfg", GenerateAltvStreamCfgContent(_streamCfgIncludes, _streamCfgMetas));
File.WriteAllText($"{outputFolder}\\resource.cfg", GenerateAltvResourceCfgContent());
}

private string GenerateAltvStreamCfgContent(List<string> files, List<string> metas)
{
string filesText = "";
Expand Down
Loading

0 comments on commit 1d9620c

Please sign in to comment.