PedsForm support for texture variations and alternative drawables, Sorting entries by name in YtdForm and when viewing Ydd in ModelForm

This commit is contained in:
dexy 2019-11-09 18:05:41 +11:00
parent 87092996f8
commit 20545145a5
6 changed files with 303 additions and 147 deletions

View File

@ -6134,6 +6134,7 @@ namespace CodeWalker.GameFiles
public Unk_3538495220 _Data;
public Unk_3538495220 Data { get { return _Data; } }
public byte numAvailTex { get { return _Data.numAvailTex; } set { _Data.numAvailTex = value; } }
public MUnk_1535046754[] DrawblData3 { get; set; }
@ -6244,6 +6245,59 @@ namespace CodeWalker.GameFiles
return r;
}
public string GetTextureName(int texnum = 0)
{
return GetTexturePrefix() + GetTextureSuffix(texnum);
}
public string GetTexturePrefix()
{
string r = (ComponentType < 12) ? MUnk_3538495220.ComponentTypeNames[ComponentType] : "error";
r += "_diff_"; //are there variations of this?
r += DrawableIndex.ToString("000");
r += "_";
return r;
}
public string GetTextureSuffix(int texnum)
{
const string alphas = "abcdefghijklmnopqrstuvwxyz";
var tex = TexData[texnum];
var texid = tex.texId;
var distr = tex.distribution;//what does this do?
var r = string.Empty;
r += alphas[texnum % 26];
r += "_";
switch (texid)
{
case 0:
r += "uni";
break;
case 1:
r += "whi";
break;
case 2:
r += "bla";
break;
case 3:
r += "chi";
break;
case 4:
r += "lat";
break;
case 5:
r += "ara";
break;
case 8:
r += "kor";
break;
case 10:
r += "pak";
break;
default:
r += "whi";
break;
}
return r;
}
public MUnk_1535046754() { }

View File

@ -946,7 +946,13 @@ namespace CodeWalker.Forms
bool check = true;
if (dict != null)
{
List<KeyValuePair<uint, Drawable>> items = new List<KeyValuePair<uint, Drawable>>();
foreach (var kvp in dict)
{
items.Add(kvp);
}
items.Sort((a, b) => { return a.Value?.Name?.CompareTo(b.Value?.Name ?? "") ?? 0; });
foreach (var kvp in items)
{
AddDrawableTreeNode(kvp.Value, kvp.Key, check);
check = false;

View File

@ -63,10 +63,11 @@ namespace CodeWalker.Forms
if ((TexDict.Textures == null) || (TexDict.Textures.data_items == null)) return;
var texs = TexDict.Textures.data_items;
List<Texture> texlist = new List<Texture>(texs);
texlist.Sort((a, b) => { return a.Name?.CompareTo(b.Name) ?? 0; });
for (int i = 0; i < texs.Length; i++)
foreach (var tex in texlist)
{
var tex = texs[i];
ListViewItem lvi = TexturesListView.Items.Add(tex.Name);
lvi.ToolTipText = tex.Name;
lvi.Tag = tex;

View File

@ -76,6 +76,11 @@
this.PedNameComboBox = new System.Windows.Forms.ComboBox();
this.StatsUpdateTimer = new System.Windows.Forms.Timer(this.components);
this.ToolsPedTabPage = new System.Windows.Forms.TabPage();
this.label23 = new System.Windows.Forms.Label();
this.label22 = new System.Windows.Forms.Label();
this.ClipComboBox = new System.Windows.Forms.ComboBox();
this.label21 = new System.Windows.Forms.Label();
this.ClipDictComboBox = new System.Windows.Forms.ComboBox();
this.label20 = new System.Windows.Forms.Label();
this.CompJbibComboBox = new System.Windows.Forms.ComboBox();
this.label18 = new System.Windows.Forms.Label();
@ -103,11 +108,6 @@
this.label4 = new System.Windows.Forms.Label();
this.ToolsTabControl = new System.Windows.Forms.TabControl();
this.ToolsPanel = new System.Windows.Forms.Panel();
this.label21 = new System.Windows.Forms.Label();
this.ClipDictComboBox = new System.Windows.Forms.ComboBox();
this.label22 = new System.Windows.Forms.Label();
this.ClipComboBox = new System.Windows.Forms.ComboBox();
this.label23 = new System.Windows.Forms.Label();
this.ConsolePanel.SuspendLayout();
this.ToolsOptionsTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.TimeOfDayTrackBar)).BeginInit();
@ -695,6 +695,60 @@
this.ToolsPedTabPage.Text = "Ped";
this.ToolsPedTabPage.UseVisualStyleBackColor = true;
//
// label23
//
this.label23.AutoSize = true;
this.label23.Location = new System.Drawing.Point(3, 422);
this.label23.Name = "label23";
this.label23.Size = new System.Drawing.Size(56, 13);
this.label23.TabIndex = 31;
this.label23.Text = "Animation:";
//
// label22
//
this.label22.AutoSize = true;
this.label22.Location = new System.Drawing.Point(24, 472);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(27, 13);
this.label22.TabIndex = 30;
this.label22.Text = "Clip:";
//
// ClipComboBox
//
this.ClipComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ClipComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.ClipComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.ClipComboBox.FormattingEnabled = true;
this.ClipComboBox.Location = new System.Drawing.Point(54, 469);
this.ClipComboBox.Name = "ClipComboBox";
this.ClipComboBox.Size = new System.Drawing.Size(182, 21);
this.ClipComboBox.TabIndex = 29;
this.ClipComboBox.SelectedIndexChanged += new System.EventHandler(this.ClipComboBox_SelectedIndexChanged);
this.ClipComboBox.TextChanged += new System.EventHandler(this.ClipComboBox_TextChanged);
//
// label21
//
this.label21.AutoSize = true;
this.label21.Location = new System.Drawing.Point(2, 445);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(49, 13);
this.label21.TabIndex = 28;
this.label21.Text = "Clip Dict:";
//
// ClipDictComboBox
//
this.ClipDictComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ClipDictComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.ClipDictComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
this.ClipDictComboBox.FormattingEnabled = true;
this.ClipDictComboBox.Location = new System.Drawing.Point(54, 442);
this.ClipDictComboBox.Name = "ClipDictComboBox";
this.ClipDictComboBox.Size = new System.Drawing.Size(182, 21);
this.ClipDictComboBox.TabIndex = 27;
this.ClipDictComboBox.TextChanged += new System.EventHandler(this.ClipDictComboBox_TextChanged);
//
// label20
//
this.label20.AutoSize = true;
@ -710,6 +764,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompJbibComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompJbibComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompJbibComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompJbibComboBox.FormattingEnabled = true;
this.CompJbibComboBox.Location = new System.Drawing.Point(54, 370);
this.CompJbibComboBox.Name = "CompJbibComboBox";
@ -732,6 +787,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompDeclComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompDeclComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompDeclComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompDeclComboBox.FormattingEnabled = true;
this.CompDeclComboBox.Location = new System.Drawing.Point(54, 343);
this.CompDeclComboBox.Name = "CompDeclComboBox";
@ -754,6 +810,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompTaskComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompTaskComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompTaskComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompTaskComboBox.FormattingEnabled = true;
this.CompTaskComboBox.Location = new System.Drawing.Point(54, 316);
this.CompTaskComboBox.Name = "CompTaskComboBox";
@ -776,6 +833,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompAccsComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompAccsComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompAccsComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompAccsComboBox.FormattingEnabled = true;
this.CompAccsComboBox.Location = new System.Drawing.Point(54, 289);
this.CompAccsComboBox.Name = "CompAccsComboBox";
@ -798,6 +856,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompTeefComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompTeefComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompTeefComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompTeefComboBox.FormattingEnabled = true;
this.CompTeefComboBox.Location = new System.Drawing.Point(54, 262);
this.CompTeefComboBox.Name = "CompTeefComboBox";
@ -820,6 +879,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompFeetComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompFeetComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompFeetComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompFeetComboBox.FormattingEnabled = true;
this.CompFeetComboBox.Location = new System.Drawing.Point(54, 235);
this.CompFeetComboBox.Name = "CompFeetComboBox";
@ -842,6 +902,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompHandComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompHandComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompHandComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompHandComboBox.FormattingEnabled = true;
this.CompHandComboBox.Location = new System.Drawing.Point(54, 208);
this.CompHandComboBox.Name = "CompHandComboBox";
@ -864,6 +925,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompLowrComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompLowrComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompLowrComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompLowrComboBox.FormattingEnabled = true;
this.CompLowrComboBox.Location = new System.Drawing.Point(54, 181);
this.CompLowrComboBox.Name = "CompLowrComboBox";
@ -886,6 +948,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompUpprComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompUpprComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompUpprComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompUpprComboBox.FormattingEnabled = true;
this.CompUpprComboBox.Location = new System.Drawing.Point(54, 154);
this.CompUpprComboBox.Name = "CompUpprComboBox";
@ -908,6 +971,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompHairComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompHairComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompHairComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompHairComboBox.FormattingEnabled = true;
this.CompHairComboBox.Location = new System.Drawing.Point(54, 127);
this.CompHairComboBox.Name = "CompHairComboBox";
@ -930,6 +994,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompBerdComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompBerdComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompBerdComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompBerdComboBox.FormattingEnabled = true;
this.CompBerdComboBox.Location = new System.Drawing.Point(54, 100);
this.CompBerdComboBox.Name = "CompBerdComboBox";
@ -952,6 +1017,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.CompHeadComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CompHeadComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CompHeadComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CompHeadComboBox.FormattingEnabled = true;
this.CompHeadComboBox.Location = new System.Drawing.Point(54, 73);
this.CompHeadComboBox.Name = "CompHeadComboBox";
@ -998,60 +1064,6 @@
this.ToolsPanel.TabIndex = 7;
this.ToolsPanel.Visible = false;
//
// label21
//
this.label21.AutoSize = true;
this.label21.Location = new System.Drawing.Point(2, 445);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(49, 13);
this.label21.TabIndex = 28;
this.label21.Text = "Clip Dict:";
//
// ClipDictComboBox
//
this.ClipDictComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ClipDictComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.ClipDictComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
this.ClipDictComboBox.FormattingEnabled = true;
this.ClipDictComboBox.Location = new System.Drawing.Point(54, 442);
this.ClipDictComboBox.Name = "ClipDictComboBox";
this.ClipDictComboBox.Size = new System.Drawing.Size(182, 21);
this.ClipDictComboBox.TabIndex = 27;
this.ClipDictComboBox.TextChanged += new System.EventHandler(this.ClipDictComboBox_TextChanged);
//
// label22
//
this.label22.AutoSize = true;
this.label22.Location = new System.Drawing.Point(24, 472);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(27, 13);
this.label22.TabIndex = 30;
this.label22.Text = "Clip:";
//
// ClipComboBox
//
this.ClipComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ClipComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.ClipComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.ClipComboBox.FormattingEnabled = true;
this.ClipComboBox.Location = new System.Drawing.Point(54, 469);
this.ClipComboBox.Name = "ClipComboBox";
this.ClipComboBox.Size = new System.Drawing.Size(182, 21);
this.ClipComboBox.TabIndex = 29;
this.ClipComboBox.SelectedIndexChanged += new System.EventHandler(this.ClipComboBox_SelectedIndexChanged);
this.ClipComboBox.TextChanged += new System.EventHandler(this.ClipComboBox_TextChanged);
//
// label23
//
this.label23.AutoSize = true;
this.label23.Location = new System.Drawing.Point(3, 422);
this.label23.Name = "label23";
this.label23.Size = new System.Drawing.Size(56, 13);
this.label23.TabIndex = 31;
this.label23.Text = "Animation:";
//
// PedsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -75,19 +75,6 @@ namespace CodeWalker.Peds
Drawable SelectedHead = null;
Drawable SelectedBerd = null;
Drawable SelectedHair = null;
Drawable SelectedUppr = null;
Drawable SelectedLowr = null;
Drawable SelectedHand = null;
Drawable SelectedFeet = null;
Drawable SelectedTeef = null;
Drawable SelectedAccs = null;
Drawable SelectedTask = null;
Drawable SelectedDecl = null;
Drawable SelectedJbib = null;
[TypeConverter(typeof(ExpandableObjectConverter))] public class PedSelection
{
public string Name { get; set; } = string.Empty;
@ -103,17 +90,71 @@ namespace CodeWalker.Peds
public RpfFileEntry[] DrawableFiles { get; set; } = null;
public RpfFileEntry[] TextureFiles { get; set; } = null;
public ClipMapEntry AnimClip { get; set; } = null;
public Drawable[] Drawables { get; set; } = new Drawable[12];
public Texture[] Textures { get; set; } = new Texture[12];
}
PedSelection SelectedPed = new PedSelection();
ComboBox[] ComponentComboBoxes = null;
public class ComponentComboItem
{
public MUnk_1535046754 DrawableData { get; set; }
public int AlternativeIndex { get; set; }
public int TextureIndex { get; set; }
public ComponentComboItem(MUnk_1535046754 drawableData, int altIndex = 0, int textureIndex = -1)
{
DrawableData = drawableData;
AlternativeIndex = altIndex;
TextureIndex = textureIndex;
}
public override string ToString()
{
if (DrawableData == null) return TextureIndex.ToString();
var itemname = DrawableData.GetDrawableName(AlternativeIndex);
if (DrawableData.TexData?.Length > 0) return itemname + " + " + DrawableData.GetTextureSuffix(TextureIndex);
return itemname;
}
public string DrawableName
{
get
{
return DrawableData?.GetDrawableName(AlternativeIndex) ?? "error";
}
}
public string TextureName
{
get
{
return DrawableData?.GetTextureName(TextureIndex);
}
}
}
public PedsForm()
{
InitializeComponent();
ComponentComboBoxes = new[]
{
CompHeadComboBox,
CompBerdComboBox,
CompHairComboBox,
CompUpprComboBox,
CompLowrComboBox,
CompHandComboBox,
CompFeetComboBox,
CompTeefComboBox,
CompAccsComboBox,
CompTaskComboBox,
CompDeclComboBox,
CompJbibComboBox
};
Renderer = new Renderer(this, GameFileCache);
camera = Renderer.camera;
timecycle = Renderer.timecycle;
@ -724,18 +765,12 @@ namespace CodeWalker.Peds
SelectedPed.Yft = null;
SelectedPed.Ymt = null;
SelectedPed.AnimClip = null;
ClearCombo(CompHeadComboBox); SelectedHead = null;
ClearCombo(CompBerdComboBox); SelectedBerd = null;
ClearCombo(CompHairComboBox); SelectedHair = null;
ClearCombo(CompUpprComboBox); SelectedUppr = null;
ClearCombo(CompLowrComboBox); SelectedLowr = null;
ClearCombo(CompHandComboBox); SelectedHand = null;
ClearCombo(CompFeetComboBox); SelectedFeet = null;
ClearCombo(CompTeefComboBox); SelectedTeef = null;
ClearCombo(CompAccsComboBox); SelectedAccs = null;
ClearCombo(CompTaskComboBox); SelectedTask = null;
ClearCombo(CompDeclComboBox); SelectedDecl = null;
ClearCombo(CompJbibComboBox); SelectedJbib = null;
for (int i = 0; i < 12; i++)
{
ClearCombo(ComponentComboBoxes[i]);
SelectedPed.Drawables[i] = null;
SelectedPed.Textures[i] = null;
}
DetailsPropertyGrid.SelectedObject = null;
@ -794,18 +829,10 @@ namespace CodeWalker.Peds
var vi = SelectedPed.Ymt?.VariationInfo;
if (vi != null)
{
PopulateCompCombo(CompHeadComboBox, vi.GetComponentData(0));
PopulateCompCombo(CompBerdComboBox, vi.GetComponentData(1));
PopulateCompCombo(CompHairComboBox, vi.GetComponentData(2));
PopulateCompCombo(CompUpprComboBox, vi.GetComponentData(3));
PopulateCompCombo(CompLowrComboBox, vi.GetComponentData(4));
PopulateCompCombo(CompHandComboBox, vi.GetComponentData(5));
PopulateCompCombo(CompFeetComboBox, vi.GetComponentData(6));
PopulateCompCombo(CompTeefComboBox, vi.GetComponentData(7));
PopulateCompCombo(CompAccsComboBox, vi.GetComponentData(8));
PopulateCompCombo(CompTaskComboBox, vi.GetComponentData(9));
PopulateCompCombo(CompDeclComboBox, vi.GetComponentData(10));
PopulateCompCombo(CompJbibComboBox, vi.GetComponentData(11));
for (int i = 0; i < 12; i++)
{
PopulateCompCombo(ComponentComboBoxes[i], vi.GetComponentData(i));
}
}
@ -851,7 +878,20 @@ namespace CodeWalker.Peds
if (compData?.DrawblData3 == null) return;
foreach (var item in compData.DrawblData3)
{
c.Items.Add(item.GetDrawableName());
for (int alt = 0; alt <= item.NumAlternatives; alt++)
{
if (item.TexData?.Length > 0)
{
for (int tex = 0; tex < item.TexData.Length; tex++)
{
c.Items.Add(new ComponentComboItem(item, alt, tex));
}
}
else
{
c.Items.Add(new ComponentComboItem(item));
}
}
}
if (compData.DrawblData3.Length > 0)
{
@ -859,25 +899,28 @@ namespace CodeWalker.Peds
}
}
private Drawable GetComponentDrawable(string name)
private void SetComponentDrawable(int index, object comboObj)
{
if (string.IsNullOrEmpty(name)) return null;
var namel = name.ToLowerInvariant();
MetaHash hash = JenkHash.GenHash(namel);
Drawable d;
if (SelectedPed.Ydd?.Dict != null)
var comboItem = comboObj as ComponentComboItem;
var name = comboItem?.DrawableName;
if (string.IsNullOrEmpty(name))
{
if (SelectedPed.Ydd.Dict.TryGetValue(hash, out d)) return d;
SelectedPed.Drawables[index] = null;
SelectedPed.Textures[index] = null;
return;
}
if (SelectedPed.DrawableFilesDict != null)
MetaHash namehash = JenkHash.GenHash(name.ToLowerInvariant());
Drawable d = null;
if (SelectedPed.Ydd?.Dict != null)
{
SelectedPed.Ydd.Dict.TryGetValue(namehash, out d);
}
if ((d == null) && (SelectedPed.DrawableFilesDict != null))
{
RpfFileEntry file = null;
if (SelectedPed.DrawableFilesDict.TryGetValue(hash, out file))
if (SelectedPed.DrawableFilesDict.TryGetValue(namehash, out file))
{
var ydd = GameFileCache.GetFileUncached<YddFile>(file);
while ((ydd != null) && (!ydd.Loaded))
@ -887,12 +930,40 @@ namespace CodeWalker.Peds
}
if (ydd?.Drawables?.Length > 0)
{
return ydd.Drawables[0];//should only be one in this dict
d = ydd.Drawables[0];//should only be one in this dict
}
}
}
return null;
var tex = comboItem.TextureName;
MetaHash texhash = JenkHash.GenHash(tex.ToLowerInvariant());
Texture t = null;
if (SelectedPed.Ytd?.TextureDict?.Dict != null)
{
SelectedPed.Ytd.TextureDict.Dict.TryGetValue(texhash, out t);
}
if ((t == null) && (SelectedPed.TextureFilesDict != null))
{
RpfFileEntry file = null;
if (SelectedPed.TextureFilesDict.TryGetValue(texhash, out file))
{
var ytd = GameFileCache.GetFileUncached<YtdFile>(file);
while ((ytd != null) && (!ytd.Loaded))
{
Thread.Sleep(20);//kinda hacky
GameFileCache.TryLoadEnqueue(ytd);
}
if (ytd?.TextureDict?.Textures?.data_items.Length > 0)
{
t = ytd.TextureDict.Textures.data_items[0];//should only be one in this dict
}
}
}
if (d != null) SelectedPed.Drawables[index] = d;
if (t != null) SelectedPed.Textures[index] = t;
}
@ -1101,29 +1172,24 @@ namespace CodeWalker.Peds
var vi = SelectedPed.Ymt?.VariationInfo;
if (vi != null)
{
RenderPedComponent(SelectedHead, vi.GetComponentData(0));
RenderPedComponent(SelectedBerd, vi.GetComponentData(1));
RenderPedComponent(SelectedHair, vi.GetComponentData(2));
RenderPedComponent(SelectedUppr, vi.GetComponentData(3));
RenderPedComponent(SelectedLowr, vi.GetComponentData(4));
RenderPedComponent(SelectedHand, vi.GetComponentData(5));
RenderPedComponent(SelectedFeet, vi.GetComponentData(6));
RenderPedComponent(SelectedTeef, vi.GetComponentData(7));
RenderPedComponent(SelectedAccs, vi.GetComponentData(8));
RenderPedComponent(SelectedTask, vi.GetComponentData(9));
RenderPedComponent(SelectedDecl, vi.GetComponentData(10));
RenderPedComponent(SelectedJbib, vi.GetComponentData(11));
}
}
}
private void RenderPedComponent(Drawable drawable, MUnk_3538495220 compData)
for (int i = 0; i < 12; i++)
{
if (drawable == null) return;
if (compData == null) return;
RenderPedComponent(i);
}
}
}
}
private void RenderPedComponent(int i)
{
//var compData = SelectedPed.Ymt?.VariationInfo?.GetComponentData(i);
var drawable = SelectedPed.Drawables[i];
var texture = SelectedPed.Textures[i];
//if (compData == null) return;
if (drawable == null) return;
var td = SelectedPed.Ytd?.TextureDict;
var ac = SelectedPed.AnimClip;
@ -1131,11 +1197,11 @@ namespace CodeWalker.Peds
var skel = SelectedPed.Yft?.Fragment?.Drawable?.Skeleton;
if (skel != null)
{
drawable.Skeleton = skel;
drawable.Skeleton = skel;//force the drawable to use this skeleton.
}
Renderer.RenderDrawable(drawable, null, null, 0, td, ac);
Renderer.RenderDrawable(drawable, null, null, 0, td, texture, ac);
}
@ -1644,62 +1710,62 @@ namespace CodeWalker.Peds
private void CompHeadComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedHead = GetComponentDrawable(CompHeadComboBox.Text);
SetComponentDrawable(0, CompHeadComboBox.SelectedItem);
}
private void CompBerdComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedBerd = GetComponentDrawable(CompBerdComboBox.Text);
SetComponentDrawable(1, CompBerdComboBox.SelectedItem);
}
private void CompHairComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedHair = GetComponentDrawable(CompHairComboBox.Text);
SetComponentDrawable(2, CompHairComboBox.SelectedItem);
}
private void CompUpprComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedUppr = GetComponentDrawable(CompUpprComboBox.Text);
SetComponentDrawable(3, CompUpprComboBox.SelectedItem);
}
private void CompLowrComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedLowr = GetComponentDrawable(CompLowrComboBox.Text);
SetComponentDrawable(4, CompLowrComboBox.SelectedItem);
}
private void CompHandComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedHand = GetComponentDrawable(CompHandComboBox.Text);
SetComponentDrawable(5, CompHandComboBox.SelectedItem);
}
private void CompFeetComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedFeet = GetComponentDrawable(CompFeetComboBox.Text);
SetComponentDrawable(6, CompFeetComboBox.SelectedItem);
}
private void CompTeefComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedTeef = GetComponentDrawable(CompTeefComboBox.Text);
SetComponentDrawable(7, CompTeefComboBox.SelectedItem);
}
private void CompAccsComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedAccs = GetComponentDrawable(CompAccsComboBox.Text);
SetComponentDrawable(8, CompAccsComboBox.SelectedItem);
}
private void CompTaskComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedTask = GetComponentDrawable(CompTaskComboBox.Text);
SetComponentDrawable(9, CompTaskComboBox.SelectedItem);
}
private void CompDeclComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedDecl = GetComponentDrawable(CompDeclComboBox.Text);
SetComponentDrawable(10, CompDeclComboBox.SelectedItem);
}
private void CompJbibComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedJbib = GetComponentDrawable(CompJbibComboBox.Text);
SetComponentDrawable(11, CompJbibComboBox.SelectedItem);
}
private void ClipDictComboBox_TextChanged(object sender, EventArgs e)
@ -1725,23 +1791,31 @@ namespace CodeWalker.Peds
return;
}
List<string> items = new List<string>();
foreach (var cme in ycd.ClipMapEntries)
{
var animclip = cme.Clip as ClipAnimation;
if (animclip != null)
{
ClipComboBox.Items.Add(animclip.ShortName);
items.Add(animclip.ShortName);
continue;
}
var animcliplist = cme.Clip as ClipAnimationList;
if (animcliplist?.Animations?.Data != null)
{
ClipComboBox.Items.Add(animcliplist.ShortName);
items.Add(animcliplist.ShortName);
continue;
}
}
items.Sort();
foreach (var item in items)
{
ClipComboBox.Items.Add(item);
}
}

View File

@ -2495,14 +2495,14 @@ namespace CodeWalker.Rendering
return res;
}
public bool RenderDrawable(DrawableBase drawable, Archetype arche, YmapEntityDef entity, uint txdHash = 0, TextureDictionary txdExtra = null, ClipMapEntry animClip = null)
public bool RenderDrawable(DrawableBase drawable, Archetype arche, YmapEntityDef entity, uint txdHash = 0, TextureDictionary txdExtra = null, Texture diffOverride = null, ClipMapEntry animClip = null)
{
//enqueue a single drawable for rendering.
if (drawable == null)
return false;
Renderable rndbl = TryGetRenderable(arche, drawable, txdHash, txdExtra);
Renderable rndbl = TryGetRenderable(arche, drawable, txdHash, txdExtra, diffOverride);
if (rndbl == null)
return false;
@ -2810,7 +2810,7 @@ namespace CodeWalker.Rendering
private Renderable TryGetRenderable(Archetype arche, DrawableBase drawable, uint txdHash = 0, TextureDictionary txdExtra = null)
private Renderable TryGetRenderable(Archetype arche, DrawableBase drawable, uint txdHash = 0, TextureDictionary txdExtra = null, Texture diffOverride = null)
{
if (drawable == null) return null;
//BUG: only last texdict used!! needs to cache textures per archetype........
@ -2959,6 +2959,15 @@ namespace CodeWalker.Rendering
{
for (int i = 0; i < geom.Textures.Length; i++)
{
if (diffOverride != null)
{
var texParamHash = (i < geom.TextureParamHashes?.Length) ? geom.TextureParamHashes[i] : 0;
if (texParamHash == ShaderParamNames.DiffuseSampler)
{
geom.Textures[i] = diffOverride;
}
}
var tex = geom.Textures[i];
var ttex = tex as Texture;
Texture dtex = null;