Skip to content

Commit

Permalink
Fix pathID and texture2D generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nifyr committed Mar 2, 2024
1 parent b369af6 commit 6bd7552
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions PokemonInserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ private void UpdateContestData(int srcMonsNo, int dstMonsNo, int dstFormNo)
gameData.contestResultMotion.Add(dstRM);
}

private long GeneratePathID(List<long> pathIDs)
{
long newPathID = 0;
do
{
newPathID = NextInt64();
} while (pathIDs.Contains(newPathID));
pathIDs.Add(newPathID);
return newPathID;
}

private void DuplicateIcons(Dictionary<string, string> menuSprites, Dictionary<string, string> largeSprites, Dictionary<string, string> dpSprites)
{
foreach (KeyValuePair<string, string> pair in largeSprites)
Expand All @@ -391,12 +402,13 @@ private void DuplicateIcons(Dictionary<string, string> menuSprites, Dictionary<s
AssetTypeTemplateField renderDataPairATTF = spriteAtlas["m_RenderDataMap"]["Array"][0].GetTemplateField();
List<AssetTypeValueField> renderDataPairATVFs = spriteAtlas["m_RenderDataMap"]["Array"].GetChildrenList().ToList();
List<AssetsReplacer> ars = new();
List<long> pathIDs = afi.table.assetFileInfo.Select(afie => afie.index).ToList();
foreach (KeyValuePair<string, string> pair in menuSprites)
{
AssetTypeValueField texture2DATVF = ValueBuilder.DefaultValueFieldFromTemplate(attf);
FillTexture2D(texture2DATVF);
texture2DATVF["m_Name"].GetValue().Set(pair.Value + "_Texture2D");
long texture2DPathID = afi.table.assetFileInfo.Max(afie => afie.index) + 1;
long texture2DPathID = GeneratePathID(pathIDs);
ars.Add(new AssetsReplacerFromMemory(0, texture2DPathID, 28, 0xFFFF, texture2DATVF.WriteToByteArray()));

AssetTypeValueField spriteATVF = afi.table.GetAssetsOfType(213)
Expand All @@ -422,7 +434,7 @@ private void DuplicateIcons(Dictionary<string, string> menuSprites, Dictionary<s
spriteATVF["m_RD"]["textureRect"]["height"].GetValue().Set(128);
spriteATVF["m_RD"]["textureRectOffset"]["x"].GetValue().Set(0);
spriteATVF["m_RD"]["textureRectOffset"]["y"].GetValue().Set(0);
long spritePathID = afi.table.assetFileInfo.Max(afie => afie.index) + 2;
long spritePathID = GeneratePathID(pathIDs);
ars.Add(new AssetsReplacerFromMemory(0, spritePathID, 213, 0xFFFF, spriteATVF.WriteToByteArray()));

AssetTypeValueField atlasSprite = ValueBuilder.DefaultValueFieldFromTemplate(spriteATTF);
Expand Down Expand Up @@ -475,6 +487,7 @@ private void FillTexture2D(AssetTypeValueField atvf)
atvf["m_CompleteImageSize"].GetValue().Set(7744);
atvf["m_TextureFormat"].GetValue().Set(50);
atvf["m_MipCount"].GetValue().Set(1);
atvf["m_IsReadable"].GetValue().Set(true);
atvf["m_ImageCount"].GetValue().Set(1);
atvf["m_TextureDimension"].GetValue().Set(2);
atvf["m_TextureSettings"]["m_FilterMode"].GetValue().Set(1);
Expand Down

0 comments on commit 6bd7552

Please sign in to comment.