public static void ReplaceTexture(UnityParser parser, ImportedTexture texture) { if (!Operations.ReplaceTexture(parser, texture, false)) { throw new Exception("Texture " + texture.Name + " not present"); } }
public static void ExportAsset([DefaultVar] UnityParser parser, Component asset, string path) { FileInfo file = new FileInfo(path + "." + (asset.classID() == UnityClassID.MonoBehaviour ? ((int)asset.classID1).ToString() : asset.classID().ToString())); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } using (FileStream fs = file.Create()) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed; } try { asset.WriteTo(fs); } finally { if (notLoaded != parser.Uncompressed) { notLoaded.SourceStream.Close(); notLoaded.SourceStream.Dispose(); notLoaded.SourceStream = null; } } } }
public static void ExportUnity3d([DefaultVar] UnityParser parser, string path) { if (path == String.Empty) { path = @".\"; } DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { dir.Create(); } using (Stream sourceStream = File.OpenRead(parser.FilePath)) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { var asset = parser.Cabinet.Components[i]; using (FileStream fs = File.Create(dir.FullName + @"\" + asset.pathID + "." + asset.classID1)) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = sourceStream; } asset.WriteTo(fs); if (notLoaded != null) { notLoaded.SourceStream = null; } } } } }
public static bool RemoveMod(UnityParser parser, UnityParser originalsParser, bool deleteOriginals) { Match m = Regex.Match(originalsParser.FilePath, @"-(-*\d+)\.", RegexOptions.CultureInvariant); int firstNewPathID = -1; if (!m.Success || !int.TryParse(m.Groups[1].Value, out firstNewPathID)) { Report.ReportLog("Warning! Mod filename \"" + Path.GetFileName(originalsParser.FilePath) + "\" is malformed or lies in a folder with a confusing name."); firstNewPathID = -1; } bool error = false; for (int i = originalsParser.Cabinet.Components.Count - 1; i >= 0; i--) { int pathID = originalsParser.Cabinet.Components[i].pathID; Component comp = parser.Cabinet.FindComponent(pathID); if (comp != null) { if (comp.classID2 == originalsParser.Cabinet.Components[i].classID2) { if (firstNewPathID == -1 || pathID < firstNewPathID) { parser.Cabinet.ReplaceSubfile(comp, originalsParser.Cabinet.Components[i]); } else { if (parser.Cabinet.Components.IndexOf(comp) == parser.Cabinet.Components.Count - 1) { parser.Cabinet.RemoveSubfile(comp); } else { Report.ReportLog("Asset with PathID=" + pathID + " is not located at the end. Other mods will become unremovable when this asset would be removed."); error = true; } } } else { Report.ReportLog("Unexpected asset in " + Path.GetFileName(parser.FilePath) + " with PathID=" + pathID + " was not " + (firstNewPathID == -1 || pathID < firstNewPathID ? "replaced." : "removed.")); error = true; } } else { Report.ReportLog("Asset with PathID=" + pathID + " is not present in " + Path.GetFileName(parser.FilePath)); error = true; } } if (error) { Report.ReportLog(Path.GetFileName(originalsParser.FilePath) + " was partially removed. Saving " + Path.GetFileName(parser.FilePath) + " may corrupt the file."); return(false); } if (deleteOriginals) { parser.DeleteModFiles.Add(originalsParser.Cabinet); } return(true); }
public static void ExportAsset([DefaultVar] UnityParser parser, int pathID, string path) { Component asset = parser.Cabinet.FindComponent(pathID); if (asset != null) { FileInfo file = new FileInfo(path + "." + asset.classID1); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } using (FileStream fs = file.Create()) { NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting; if (notLoaded != null) { notLoaded.SourceStream = File.OpenRead(parser.FilePath); } asset.WriteTo(fs); if (notLoaded != null) { notLoaded.SourceStream.Close(); notLoaded.SourceStream.Dispose(); notLoaded.SourceStream = null; } } } }
public static void ReplaceAudioClip(UnityParser parser, string path) { AudioClip ac = AudioClip.Import(path); if (ac.m_AudioData.Length > 0) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID() == UnityClassID.AudioClip) { AudioClip acic = parser.Cabinet.LoadComponent(asset.pathID); if (acic.m_Name == ac.m_Name) { acic.m_AudioData = ac.m_AudioData; if (parser.Cabinet.VersionNumber >= AssetCabinet.VERSION_5_0_0) { acic.m_Resource.m_Source = path; } return; } } } } }
public static void ExportTexture([DefaultVar] UnityParser parser, string name, string path) { string folder = Path.GetDirectoryName(path); if (folder.Length > 0) { folder += "\\"; } folder += Path.GetFileNameWithoutExtension(path); ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); if (name != "*") { Texture2D tex = parser.GetTexture(name); if (tex != null) { tex.Export(folder, preferredUncompressedFormat); } } else { for (int i = 0; i < parser.Textures.Count; i++) { Texture2D tex = parser.GetTexture(i); tex.Export(folder, preferredUncompressedFormat); } } }
public static void ExportTexture([DefaultVar] UnityParser parser, string name, string path) { string folder = Path.GetDirectoryName(path); if (folder.Length > 0) { folder += "\\"; } folder += Path.GetFileNameWithoutExtension(path); if (name != "*") { Texture2D tex = parser.GetTexture(name); if (tex != null) { tex.Export(folder); } } else { for (int i = 0; i < parser.Textures.Count; i++) { Texture2D tex = parser.GetTexture(i); tex.Export(folder); } } }
public static void RemoveAsset([DefaultVar] UnityParser parser, Component asset) { if (asset.classID() == UnityClassID.AssetBundle) { return; } if (asset is NotLoaded) { Component loadedAsset = parser.Cabinet.LoadComponent(((NotLoaded)asset).pathID); if (loadedAsset != null) { asset = loadedAsset; } } if (asset is LinkedByGameObject) { LinkedByGameObject linked = (LinkedByGameObject)asset; if (linked.m_GameObject != null && linked.m_GameObject.instance != null) { linked.m_GameObject.instance.RemoveLinkedComponent(linked); } } parser.Cabinet.RemoveSubfile(asset); if (asset.classID() == UnityClassID.Texture2D || asset.classID() == UnityClassID.Cubemap) { parser.Textures.Remove(asset); } if (parser.Cabinet.Bundle != null) { parser.Cabinet.Bundle.DeleteComponent(asset); } }
public FormNmlMonoBehaviour(UnityParser uParser, string nmlMonoBehaviourParserVar) { try { InitializeComponent(); NmlMonoBehaviour parser = (NmlMonoBehaviour)Gui.Scripting.Variables[nmlMonoBehaviourParserVar]; this.ShowHint = DockState.Document; this.Text = parser.m_Name; this.ToolTipText = uParser.FilePath + @"\" + this.Text; ParserVar = nmlMonoBehaviourParserVar; EditorVar = Gui.Scripting.GetNextVariable("nmlMonoBehaviourEditor"); Editor = (NmlMonoBehaviourEditor)Gui.Scripting.RunScript(EditorVar + " = NmlMonoBehaviourEditor(parser=" + ParserVar + ")"); Init(); LoadNml(); } catch (Exception ex) { Utility.ReportException(ex); } }
public FormMonoBehaviour(UnityParser uParser, string parserVar) { try { InitializeComponent(); this.ShowHint = DockState.Document; MonoBehaviour parser = (MonoBehaviour)Gui.Scripting.Variables[parserVar]; this.Text = AssetCabinet.ToString(parser); this.ToolTipText = uParser.FilePath + @"\" + this.Text; EditorVar = Gui.Scripting.GetNextVariable("monoBehaviourEditor"); Editor = (MonoBehaviourEditor)Gui.Scripting.RunScript(EditorVar + " = MonoBehaviourEditor(parser=" + parserVar + ")"); toolTip1.SetToolTip(buttonRevert, DateTime.Now.ToString()); Gui.Docking.ShowDockContent(this, Gui.Docking.DockEditors, ContentCategory.Others); float treeViewFontSize = (float)Gui.Config["TreeViewFontSize"]; if (treeViewFontSize > 0) { treeViewAdditionalMembers.Font = new Font(treeViewAdditionalMembers.Font.Name, treeViewFontSize); } LoadContents(); } catch (Exception e) { Utility.ReportException(e); } }
public static void ExportFbx([DefaultVar] UnityParser parser, object[] skinnedMeshRendererIDs, object[] animationParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, bool compatibility) { List <double> sMeshIDList = new List <double>(Utility.Convert <double>(skinnedMeshRendererIDs)); List <MeshRenderer> sMeshes = new List <MeshRenderer>(sMeshIDList.Count); for (int i = 0; i < sMeshIDList.Count; i++) { int sMeshID = (int)sMeshIDList[i]; if (i > 0 && sMeshID < 0) { for (sMeshID = (int)sMeshIDList[i - 1] + 1; sMeshID < -(int)sMeshIDList[i]; sMeshID++) { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } else { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } UnityConverter imp = new UnityConverter(parser, sMeshes, skins); FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, compatibility); }
public static Animator OpenAnimator([DefaultVar] UnityParser parser, string name) { foreach (Component subfile in parser.Cabinet.Components) { if (subfile.classID() == UnityClassID.Animator) { if (subfile is Animator) { Animator a = (Animator)subfile; if (a.m_GameObject.instance.m_Name == name) { return(a); } continue; } NotLoaded animatorComp = (NotLoaded)subfile; Stream stream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed; try { stream.Position = animatorComp.offset; PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream, parser.Cabinet.VersionNumber); for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component gameObjSubfile = parser.Cabinet.Components[i]; if (gameObjSubfile.pathID == gameObjPtr.m_PathID) { if (gameObjSubfile is GameObject) { GameObject gameObj = (GameObject)gameObjSubfile; if (gameObj.m_Name == name) { return(parser.Cabinet.LoadComponent(stream, animatorComp)); } break; } NotLoaded gameObjComp = (NotLoaded)gameObjSubfile; stream.Position = gameObjComp.offset; if (GameObject.LoadName(stream, parser.Cabinet.VersionNumber) == name) { return(parser.Cabinet.LoadComponent(stream, animatorComp)); } break; } } } finally { if (stream != parser.Uncompressed) { stream.Close(); stream.Dispose(); } } } } return(null); }
public static void RemoveAsset([DefaultVar] UnityParser parser, int pathID) { Component asset = parser.Cabinet.FindComponent(pathID); if (asset == null) { throw new Exception("Couldn't find asset PathID=" + pathID); } parser.Cabinet.RemoveSubfile(asset); }
public static void ReplaceTexture(UnityParser parser, ImportedTexture texture) { Texture2D tex = parser.GetTexture(Path.GetFileNameWithoutExtension(texture.Name)); if (tex == null) { parser.AddTexture(texture); return; } ReplaceTexture(tex, texture); }
public static void MergeTextures(UnityParser parser, string folder) { DirectoryInfo dir = new DirectoryInfo(folder); if (!dir.Exists) { throw new Exception("Directory <" + folder + "> does not exist"); } foreach (FileInfo file in dir.EnumerateFiles()) { MergeTexture(parser, file.FullName); } }
public Unity3dEditor(UnityParser parser, bool showContents) { Parser = parser; VirtualAnimators = new HashSet <Animator>(); if (Parser.Cabinet.Bundle != null) { for (int i = 0; i < Parser.Cabinet.Bundle.m_Container.Count; i++) { AssetInfo info = Parser.Cabinet.Bundle.m_Container[i].Value; if (info.asset.m_PathID == 0) { string msg = "Invalid container entry for " + Parser.Cabinet.Bundle.m_Container[i].Key; if (msgFilter.Add(msg)) { Report.ReportLog(msg); } continue; } if (info.asset.m_FileID == 0 && info.asset.asset.classID1 == UnityClassID.GameObject) { bool animatorFound = false; int nextPreloadIdx = info.preloadIndex + info.preloadSize; for (int j = info.preloadIndex; j < nextPreloadIdx; j++) { PPtr <Object> preTabEntry = Parser.Cabinet.Bundle.m_PreloadTable[j]; if (preTabEntry.m_FileID == 0 && preTabEntry.asset.classID1 == UnityClassID.Animator) { animatorFound = true; break; } } if (!animatorFound) { CreateVirtualAnimator(info.asset.asset); } } } } if (showContents) { string[] names = GetAssetNames(false); for (int i = 0; i < names.Length; i++) { Component asset = Parser.Cabinet.Components[i]; Console.WriteLine("PathID=" + asset.pathID.ToString("D") + " id1=" + (int)asset.classID1 + "/" + asset.classID1 + " id2=" + asset.classID2 + " " + names[i]); } } }
public void ComputeMinMaxNormals(object[] nmlMeshIds, AnimatorEditor dstAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates) { string path = Path.GetDirectoryName(Parser.file.Parser.FilePath); string file = Path.GetFileNameWithoutExtension(Parser.file.Parser.FilePath); string backupExt = Path.GetExtension(Parser.file.Parser.FilePath); backupExt = backupExt == String.Empty ? backupExt = "None" : backupExt.Substring(1); backupExt = (string)Properties.Settings.Default["BackupExtension" + backupExt]; UnityParser srcFileParser = new UnityParser(path + @"\" + file + ".bak0" + backupExt); Unity3dEditor srcFileEditor = new Unity3dEditor(srcFileParser); srcFileEditor.GetAssetNames(true); Animator srcAnimator = null; if (dstAnimatorEditor.Parser.classID() != UnityClassID.Animator) { Component baseAsset = srcFileParser.Cabinet.Components.Find ( delegate(Component asset) { return(asset is NotLoaded && asset.classID() == UnityClassID.GameObject && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name); } ); srcAnimator = srcFileEditor.OpenVirtualAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset)); } else { Component baseAsset = srcFileParser.Cabinet.Components.Find ( delegate(Component asset) { return(asset is NotLoaded && asset.classID() == UnityClassID.Animator && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name); } ); srcAnimator = srcFileEditor.OpenAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset)); } AnimatorEditor srcAnimatorEditor = new AnimatorEditor(srcAnimator); Component srcNmlAsset = srcFileParser.Cabinet.Components.Find ( delegate(Component asset) { return(asset is NotLoaded && asset.classID() == UnityClassID.MonoBehaviour && ((NotLoaded)asset).Name == Parser.m_Name); } ); NmlMonoBehaviour srcNml = srcFileEditor.OpenNmlMonoBehaviour(srcFileParser.Cabinet.Components.IndexOf(srcNmlAsset)); ComputeMinMaxNormals(nmlMeshIds, dstAnimatorEditor, srcNml, -1, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates); }
public static void ExportAudioClip(UnityParser parser, string name, string path) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID1 == UnityClassID.AudioClip) { AudioClip ac = parser.Cabinet.LoadComponent(asset.pathID); if (name == "*" || ac.m_Name == name) { ac.Export(path); } } } }
public static void ExportShader(UnityParser parser, string name, string path) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID() == UnityClassID.Shader) { Shader sic = parser.Cabinet.LoadComponent(asset.pathID); if (name == "*" || sic.m_Name == name) { sic.Export(path); } } } }
public static void ExportTextAsset(UnityParser parser, string name, string path) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID1 == UnityClassID.TextAsset) { TextAsset taic = parser.Cabinet.LoadComponent(asset.pathID); if (name == "*" || taic.m_Name == name) { taic.Export(path); } } } }
public static string AddFirstNewPathID(UnityParser originalParser, UnityParser modParser, string path) { int firstNewPathID = -1; for (int i = 0; i < modParser.Cabinet.Components.Count; i++) { int pathID = modParser.Cabinet.Components[i].pathID; Component comp = originalParser.Cabinet.FindComponent(pathID); if (comp == null) { firstNewPathID = pathID; break; } } return(Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(path) + "-" + firstNewPathID + Path.GetExtension(path)); }
public static string AddFirstNewPathID(UnityParser originalParser, UnityParser modParser, string path) { long firstNewPathID = -1; for (int i = 0; i < modParser.Cabinet.Components.Count; i++) { long pathID = modParser.Cabinet.Components[i].pathID; Component comp; if (!originalParser.Cabinet.findComponent.TryGetValue(pathID, out comp)) { firstNewPathID = pathID; break; } } return(Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(path) + "-" + firstNewPathID + Path.GetExtension(path)); }
public static void ReplaceMaterial(UnityParser parser, ImportedMaterial material) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component comp = parser.Cabinet.Components[i]; if (comp.classID1 == UnityClassID.Material) { Material mat = parser.Cabinet.LoadComponent(comp.pathID); if (mat.m_Name == material.Name) { ReplaceMaterial(mat, material); return; } } } throw new Exception("Replacing a material currently requires an existing material with the same name"); }
public FormAudioClip(UnityParser uParser, string audioClipParserVar) { InitializeComponent(); AudioClip parser = (AudioClip)Gui.Scripting.Variables[audioClipParserVar]; this.Text = parser.m_Name; this.ToolTipText = uParser.FilePath + @"\" + parser.m_Name; ParserVar = audioClipParserVar; EditorVar = Gui.Scripting.GetNextVariable("audioClipEditor"); Editor = (AudioClipEditor)Gui.Scripting.RunScript(EditorVar + " = AudioClipEditor(parser=" + ParserVar + ")"); Gui.Docking.ShowDockContent(this, Gui.Docking.DockEditors, ContentCategory.Others); Init(); LoadAudioClip(); }
public static UnityParser DeployCollect(UnityParser parser, object[] animatorEditors, object[] singleAssets) { HashSet <Component> collection = new HashSet <Component>(); if (animatorEditors != null) { AnimatorEditor[] editors = Utility.Convert <AnimatorEditor>(animatorEditors); foreach (AnimatorEditor animEditor in editors) { Collect(animEditor, collection); } } if (singleAssets != null) { long[] singles = Utility.Convert <long>(singleAssets); foreach (long pathID in singles) { Component asset = parser.Cabinet.LoadComponent(pathID); collection.Add(asset); } } collection.Remove(null); UnityParser p = new UnityParser(parser); p.Cabinet.Components.AddRange(collection); p.Cabinet.Components.Sort ( delegate(Component a, Component b) { return(a.pathID.CompareTo(b.pathID)); } ); p.InitTextures(); if (parser.Cabinet.Bundle != null) { parser.Cabinet.Bundle.Clone(p.Cabinet); } return(p); }
public static void ReplaceTextAsset(UnityParser parser, string path) { TextAsset ta = TextAsset.Import(path); if (ta.m_Script.Length > 0) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID1 == UnityClassID.TextAsset) { TextAsset taic = parser.Cabinet.LoadComponent(asset.pathID); if (taic.m_Name == ta.m_Name) { taic.m_Script = ta.m_Script; return; } } } } }
public static void ReplaceShader(UnityParser parser, string path) { Shader s = Shader.Import(path); if (s.m_Script.Length > 0) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID1 == UnityClassID.Shader) { Shader sic = parser.Cabinet.LoadComponent(asset.pathID); if (sic.m_Name == s.m_Name) { sic.m_Script = s.m_Script; return; } } } } }
public static void ReplaceAudioClip(UnityParser parser, string path) { AudioClip ac = AudioClip.Import(path); if (ac.m_AudioData.Length > 0) { for (int i = 0; i < parser.Cabinet.Components.Count; i++) { Component asset = parser.Cabinet.Components[i]; if (asset.classID1 == UnityClassID.AudioClip) { AudioClip acic = parser.Cabinet.LoadComponent(asset.pathID); if (acic.m_Name == ac.m_Name) { acic.m_AudioData = ac.m_AudioData; return; } } } } }
public static void UnloadModifiedTextures(UnityParser parser) { if (parser.Cabinet.VersionNumber >= AssetCabinet.VERSION_5_0_0) { Stream stream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed; try { for (int i = 0; i < parser.Textures.Count; i++) { Texture2D tex = parser.Textures[i] as Texture2D; if (tex == null || tex.m_StreamData.path.Length == 0) { continue; } if (tex.m_StreamData.path != Path.GetFileName(parser.FilePath) + ".resS") { foreach (NotLoaded notLoaded in parser.Cabinet.RemovedList) { if (notLoaded.replacement == tex) { stream.Position = notLoaded.offset; tex.LoadFrom(stream); break; } } } } } finally { if (stream != parser.Uncompressed) { stream.Close(); stream.Dispose(); } } } }