public void MoveLayerDown(int index) { if (index < DICT.LTOC.LHDRList.Count - 1) { Section_LHDR post = DICT.LTOC.LHDRList[index + 1]; DICT.LTOC.LHDRList[index + 1] = DICT.LTOC.LHDRList[index]; DICT.LTOC.LHDRList[index] = post; UnsavedChanges = true; } }
public void MoveLayerUp(int index) { if (index > 0) { Section_LHDR previous = DICT.LTOC.LHDRList[index - 1]; DICT.LTOC.LHDRList[index - 1] = DICT.LTOC.LHDRList[index]; DICT.LTOC.LHDRList[index] = previous; UnsavedChanges = true; } }
public static int AssetGetLayerIndex(Section_AHDR AHDR, HipSection[] hip) { foreach (HipSection section in hip) { if (section is Section_DICT DICT) { List <Section_LHDR> LHDRList = DICT.LTOC.LHDRList; for (int i = 0; i < LHDRList.Count; i++) { Section_LHDR LHDR = LHDRList[i]; if (LHDR.assetIDlist.Contains(AHDR.assetID)) { return(i); } } } } return(-1); }
public Patch Commit(string root) { Patch uninstall = new Patch(); uninstall.isUninstall = true; Console.WriteLine(); Console.WriteLine("Patching..."); Console.WriteLine(); foreach (AddedFile file in addedFiles) { string path = root + file.path; DeletedFile backup = new DeletedFile(file.path); uninstall.deletedFiles.Add(backup); File.WriteAllBytes(path, file.data); PrintFile(PatchType.ADD, file.path); } foreach (ModifiedFile file in modifiedFiles) { string path = root + file.path; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ModifiedFile backup = new ModifiedFile(file.path, data); uninstall.modifiedFiles.Add(backup); } File.WriteAllBytes(path, file.data); PrintFile(PatchType.MODIFY, file.path); } foreach (DeletedFile file in deletedFiles) { string path = root + file.path; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); AddedFile backup = new AddedFile(file.path, data); uninstall.addedFiles.Add(backup); } File.Delete(path); PrintFile(PatchType.DELETE, file.path); } foreach (HipFile file in hipFiles) { string path = root + file.path; HipFile backup = new HipFile(file.path); HipSection[] hip = HipFileToHipArray(path); Section_HIPA hipa = (Section_HIPA)hip[0]; Section_PACK pack = (Section_PACK)hip[1]; Section_DICT dict = (Section_DICT)hip[2]; Section_STRM strm = (Section_STRM)hip[3]; List <Section_AHDR> ahdrList = dict.ATOC.AHDRList; List <Section_LHDR> lhdrList = dict.LTOC.LHDRList; Dictionary <uint, Section_AHDR> ahdrDict = ahdrList.ToDictionary(s => s.assetID); PrintFile(PatchType.MODIFY, file.path); foreach (AddedAsset asset in file.addedAssets) { Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum); Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg); ahdr.data = asset.data; DeletedAsset backupAsset = new DeletedAsset(asset); backup.deletedAssets.Add(backupAsset); ahdrList.Add(ahdr); Section_LHDR lhdr = lhdrList[asset.layer]; lhdr.assetIDlist.Add(asset.id); PrintAsset(PatchType.ADD, asset.name); } foreach (ModifiedAsset asset in file.modifiedAssets) { if (!ahdrDict.ContainsKey(asset.id)) { break; } Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum); Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg); ahdr.data = asset.data; Section_AHDR oldAHDR = ahdrDict[asset.id]; ahdrList.Remove(oldAHDR); ahdrList.Add(ahdr); ModifiedAsset backupAsset = new ModifiedAsset(oldAHDR, hip); backup.modifiedAssets.Add(backupAsset); PrintAsset(PatchType.MODIFY, asset.name); } foreach (DeletedAsset asset in file.deletedAssets) { if (!ahdrDict.ContainsKey(asset.id)) { break; } Section_AHDR ahdr = ahdrDict[asset.id]; ahdrList.Remove(ahdr); AddedAsset backupAsset = new AddedAsset(ahdr, hip); backup.addedAssets.Add(backupAsset); Section_LHDR lhdr = lhdrList[asset.layer]; lhdr.assetIDlist.Remove(asset.id); PrintAsset(PatchType.DELETE, asset.name); } pack.PCNT.AHDRCount = ahdrList.Count; hip = SetupStream(ref hipa, ref pack, ref dict, ref strm); File.WriteAllBytes(path, HipArrayToFile(hip)); uninstall.hipFiles.Add(backup); } Console.WriteLine("Done patching."); Console.WriteLine(); return(uninstall); }