Skip to content

Commit

Permalink
Reworked LST handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed Apr 11, 2016
1 parent 7a16700 commit 76fa227
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 29 deletions.
1 change: 1 addition & 0 deletions AA2Data/AA2Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="CardReader.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="ICF.cs" />
<Compile Include="LST.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
8 changes: 4 additions & 4 deletions AA2Data/LST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual int Slot
}
}

public virtual string Name
public virtual string ID
{
get
{
Expand All @@ -74,7 +74,7 @@ public virtual string Name
}
}

public virtual string Label
public virtual string Name
{
get
{
Expand Down Expand Up @@ -227,7 +227,7 @@ public override int Slot
}
}

public override string Name
public override string ID
{
get
{
Expand All @@ -239,7 +239,7 @@ public override string Name
}
}

public override string Label
public override string Name
{
get
{
Expand Down
2 changes: 2 additions & 0 deletions AA2Snowflake/AA2Snowflake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<ItemGroup>
<Compile Include="CRC32.cs" />
<Compile Include="CustomDictionary.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="formAbout.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -108,6 +109,7 @@
<DependentUpon>formMain.cs</DependentUpon>
</Compile>
<Compile Include="Logger.cs" />
<Compile Include="LST.cs" />
<Compile Include="Paths.cs" />
<Compile Include="Personality.cs" />
<Compile Include="Program.cs" />
Expand Down
1 change: 1 addition & 0 deletions AA2Snowflake/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
+ Fixed setting pose for male personalities
+ Added personality label blanking
+ Fixed LST editing with custom/append personalities
+ Possibly fixed pose issues after restoring changing pose values

v2.0.1
+ Fixed some issues
Expand Down
51 changes: 51 additions & 0 deletions AA2Snowflake/LST.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using AA2Snowflake.Personalities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SB3Utility;
using AA2Data;
using System.IO;

namespace AA2Snowflake
{
public enum LSTMode
{
Default,
Custom
}

public static class LSTFactory
{
public static PersonalityLST LoadLST(this IPersonality p)
{
if (p.Custom)
{
return new CustomPersonalityLST(p.GetLst().ToStream().ToArray());
}
else
{
return new PersonalityLST(p.GetLst().ToStream().ToArray());
}
}

public static PersonalityLST LoadLST(this IWriteFile iw, LSTMode mode)
{
if (mode == LSTMode.Custom)
{
return new CustomPersonalityLST(iw.ToStream().ToArray());
}
else
{
return new PersonalityLST(iw.ToStream().ToArray());
}

}

public static IWriteFile ToSubfile(this BaseLST lst, string name)
{
return new MemSubfile(new MemoryStream(lst.raw), name);
}
}
}
22 changes: 12 additions & 10 deletions AA2Snowflake/Personality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,25 @@ public static class PersonalityFactory

public static CustomPersonality LoadPersonality(ppParser pp)
{
if (!pp.Subfiles.Select(iw => iw.Name).Any(n => n.EndsWith(".icf")) || //check if it's a valid personality .pp which contains everything we need
!pp.Subfiles.Select(iw => iw.Name).Any(n => n.EndsWith(".lst") && n.StartsWith("jg2p")))
if (!pp.Subfiles.Select(x => x.Name).Any(n => n.EndsWith(".icf")) || //check if it's a valid personality .pp which contains everything we need
!pp.Subfiles.Select(x => x.Name).Any(n => n.EndsWith(".lst") && n.StartsWith("jg2p")))
return null;

string filename = pp.FilePath.Remove(0, pp.FilePath.LastIndexOf('\\') + 1);
IWriteFile lst = pp.Subfiles.First(iw => iw.Name.EndsWith(".lst") && iw.Name.StartsWith("jg2p")); //you can thank a certain person for making this difficult (http://pastebin.com/3zkjpM7e)
IWriteFile iw = pp.Subfiles.First(x => x.Name.EndsWith(".lst") && x.Name.StartsWith("jg2p")); //you can thank a certain person for making this difficult (http://pastebin.com/3zkjpM7e)

byte slot = byte.Parse(Tools.GetLstValue(lst, 2));
var lst = LSTFactory.LoadLST(iw, LSTMode.Custom);

Gender gender = (Gender)byte.Parse(Tools.GetLstValue(lst, 6)); //not sure if more accurate than grabbing ID letter, this column is set to 1 for female and 0 for male
byte slot = (byte)lst.Slot;

string ID = Tools.GetLstValue(lst, 7);
Gender gender = lst.Gender; //not sure if more accurate than grabbing ID letter, this column is set to 1 for female and 0 for male

string Name = Tools.GetLstValue(lst, 8);
string ID = lst.ID;

string Name = lst.Name;
Name = AppendTranslation.GetValueOrDefault(Name, Name);

return new CustomPersonality(gender, filename, ID, filename + "/" + lst.Name, Name, slot);
return new CustomPersonality(gender, filename, ID, filename + "/" + iw.Name, Name, slot);
}

public static BasePersonality[] BasePersonalities
Expand Down Expand Up @@ -159,10 +161,10 @@ public static ppParser GetLstPP(this IPersonality personality)
return new ppParser(path, new ppFormat_AA2());
}

public static IWriteFile GetLstFromPP(this ppParser pp, IPersonality personality)
public static IWriteFile GetLst(this IPersonality personality)
{
string file = personality.LSTLocation.GetFilename('/');
return pp.Subfiles.First(iw => iw.Name == file);
return personality.GetLstPP().Subfiles.First(iw => iw.Name == file);
}

public static ppParser GetIcfPP(this IPersonality personality)
Expand Down
40 changes: 25 additions & 15 deletions AA2Snowflake/formMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,22 @@ private void btnMove31_Click(object sender, EventArgs e)
{
Application.DoEvents();
}
index = PP.jg2e00_00_00.Subfiles.IndexOf(PP.jg2e00_00_00.Subfiles.First(pp => pp.Name == "jg2e_00_01_00_00.lst"));
var sub = Tools.ManipulateLst(PP.jg2e00_00_00.Subfiles[index], 4, "51");

//This part was indicated as in snowflake guide v2 but I'm starting to question whether or not it's necessary

/*index = PP.jg2e00_00_00.Subfiles.IndexOf(PP.jg2e00_00_00.Subfiles.First(pp => pp.Name == "jg2e_00_01_00_00.lst"));
var lst = LSTFactory.LoadLST(PP.jg2e00_00_00.Subfiles[index], LSTMode.Default);
lst.AA2EditPose
var sub = Tools.ManipulateLst(, 4, "51");
sub.Name = "jg2e_00_01_00_00.lst";
PP.jg2e00_00_00.Subfiles[index] = sub;
back = PP.jg2e00_00_00.WriteArchive(PP.jg2e00_00_00.FilePath, false, "bak", true);
back.RunWorkerAsync();
while (back.IsBusy)
{
Application.DoEvents();
}
}*/
HideLoadingForm();
MessageBox.Show("Finished!");
}
Expand All @@ -634,7 +640,7 @@ public void GenerateLSTBackups()
foreach (IPersonality personality in Personalities.Values)
using (MemoryStream ms = new MemoryStream())
{
personality.GetLstPP().GetLstFromPP(personality).WriteTo(ms);
personality.GetLst().WriteTo(ms);
backup[personality.LSTLocation] = ms.ToByteArray();
}
File.WriteAllText(Paths.BACKUP + "\\lstbackup.xml", backup.SerializeObject());
Expand All @@ -648,23 +654,27 @@ private void btnSet32_Click(object sender, EventArgs e)

IPersonality personality = Personalities.ElementAt(cmbPersonality32.SelectedIndex).Value; //i've rewritten this to change only 1 personality since you don't want to rewrite 5gb of files everytime you change poses
ppParser pp = personality.GetLstPP();
IWriteFile sub = pp.GetLstFromPP(personality);
int index = pp.Subfiles.IndexOf(sub);
IWriteFile sub = personality.GetLst();
int index = pp.Subfiles.FindIndex(x => x.Name == sub.Name);

var lst = LSTFactory.LoadLST(personality);

if (chkPose32.Checked)
sub = Tools.ManipulateLst(sub, 6, numPose32.Value.ToString());
lst.AA2EditPose = (int)numPose32.Value;
if (chkEyebrow32.Checked)
sub = Tools.ManipulateLst(sub, 7, numEyebrow32.Value.ToString());
lst.AA2EditEyebrow = (int)numEyebrow32.Value;
if (chkEyeOS32.Checked)
sub = Tools.ManipulateLst(sub, 8, numEyeOS32.Value.ToString());
lst.AA2EditEye = (int)numEye32.Value;
if (chkEye32.Checked)
sub = Tools.ManipulateLst(sub, 9, numEye32.Value.ToString());
lst.AA2EditEyeOS = (int)numEyeOS32.Value;
if (chkMouth32.Checked)
sub = Tools.ManipulateLst(sub, 10, numMouth32.Value.ToString());
lst.AA2EditMouth = (int)numMouth32.Value;

sub = Tools.ManipulateLst(sub, 4, "51");
//lst.WriteValue(1, "1");

//sub = Tools.ManipulateLst(sub, 4, "51");
//sub.Name = "jg2e_00_01_00_00.lst";
pp.Subfiles[index] = sub;
pp.Subfiles[index] = lst.ToSubfile(sub.Name);
var back = pp.WriteArchive(pp.FilePath, false, "bak", true);
ShowLoadingForm();
back.RunWorkerAsync();
Expand Down Expand Up @@ -708,7 +718,7 @@ private void btnRestore32_Click(object sender, EventArgs e)

IPersonality personality = Personalities.ElementAt(cmbPersonality32.SelectedIndex).Value;
ppParser pp = personality.GetLstPP();
IWriteFile sub = pp.GetLstFromPP(personality);
IWriteFile sub = personality.GetLst();
var index = pp.Subfiles.IndexOf(pp.Subfiles.First(iw => iw.Name == sub.Name));
sub = new MemSubfile(new MemoryStream(backup[personality.LSTLocation]), sub.Name);
pp.Subfiles[index] = sub;
Expand Down Expand Up @@ -781,7 +791,7 @@ public void LoadICF()
Logger.WriteLine(string.Join("\r\n", pp.Subfiles.Where(p => p.Name.ToLower().EndsWith("icf"))));
IWriteFile sub = pp.Subfiles.First(iw => iw.Name.ToLower() == name.ToLower());
ICF icf;
using (MemoryStream mem = Tools.GetStreamFromSubfile(sub))
using (MemoryStream mem = sub.ToStream())
icf = new ICF(mem);

txtRotX.Text = icf.Rotation.X.RadiansToDegrees().ToString();
Expand Down

0 comments on commit 76fa227

Please sign in to comment.