Categories
Uncategorized

Unity3D: replace Uma.dll with source code

If you want to replace the UMA.dll with the source code from https://github.com/huika/UMA, Unity3d will loose references to essential scripts such as SlotData.cs, OverlayData.cs …

The following script will replace the corrupted references.
1. remove UMA.dll from your project
2. add source code of the dll to the project (https://github.com/huika/UMA)
3. press the menu “UMA/Replace UMA DLL”

Some reasons to replace the dll with source code:
– remove UMA.dll and LitJson.dll from your build project
– debug UMA to find bugs or learn how it works (I have a bug in my case, but I’m not sure if its UMA or something else)

[code language=”csharp”]
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;

/// <summary>
/// If you want to replace the UMA.dll with the source code from https://github.com/huika/UMA, Unity3d will loose references to essential scripts such as SlotData.cs, OverlayData.cs …
/// 1. remove UMA.dll from your project
/// 2. add source code of the dll to the project (https://github.com/huika/UMA)
/// 3. press the menu "UMA/Replace UMA DLL"
///
/// Good read how fileID and guid work with DLLs:
/// http://forum.unity3d.com/threads/reducing-script-compile-time-or-a-better-workflow-to-reduce-excessive-recompiling.148078/#post-1026639
///
/// Hint: This is script is not optimized for performance, because you only run it onces 😉
/// </summary>
public class ReplaceUmaDll
{
[MenuItem("UMA/Replace UMA DLL")]
static void Replace()
{
List<UnityReference> r = new List<UnityReference>();
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "1772484567", "e20699a64490c4e4284b27a8aeb05666", "11500000")); // OverlayData.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-1278852528", "73c8549c3cf080440a73c4e2ccd18008", "11500000")); // SlotData.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-335686737", "0255b874991cce440bf9d7aeb881d411", "11500000")); // RaceData.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-1571472132", "e7c16015bfeffbf46a4f40de1f687493", "11500000")); // UMADefaultMeshCombiner.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-946187639", "fd3c35f1684963b4c8693ace7a4e9751", "11500000")); // UMALegacyMeshCombiner.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-1550055707", "8c8e9aa6f57f2fb4ab4808b7dd814787", "11500000")); // UMAData.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-1708169498", "ca64bee1dd859ab498a3045e0e682a1a", "11500000")); // UmaTPose.cs
r.Add(new UnityReference("e20699a64490c4e4284b27a8aeb05666", "-1175167296", "a4beb7632b1d45f44b433df8b2d28f9a", "11500000")); // TextureMerge.cs

ReplaceReferences(Application.dataPath, r);
}

static void ReplaceReferences(string assetFolder, List<UnityReference> r)
{
string[] files = Directory.GetFiles(assetFolder, "*", SearchOption.AllDirectories);
for (int i = 0; i < files.Length; i++)
{
string file = files[i];

if (EditorUtility.DisplayCancelableProgressBar("Replace UMA DLL", file, i/(float)files.Length))
{
EditorUtility.ClearProgressBar();
return;
}

if (file.EndsWith(".asset") || file.EndsWith(".prefab") || file.EndsWith(".unity"))
{
ReplaceFile(file, r);
FindNotReplacedFiles(file, "e20699a64490c4e4284b27a8aeb05666");
}
}

EditorUtility.ClearProgressBar();
}

static void ReplaceFile(string filePath, List<UnityReference> references)
{
var fileContents = System.IO.File.ReadAllText(filePath);

bool match = false;

foreach(UnityReference r in references)
{
Regex regex = new Regex(@"fileID: " + r.srcFileId + ", guid: " + r.srcGuid);
if (regex.IsMatch(fileContents))
{
fileContents = regex.Replace(fileContents, "fileID: " + r.dstFileId + ", guid: " + r.dstGuid);
match = true;
Debug.Log("Replaced: " + filePath);
}
}

if (match)
{
System.IO.File.WriteAllText(filePath, fileContents);
}
}

/// <summary>
/// Just to make sure that all references are replaced.
/// </summary>
static void FindNotReplacedFiles(string filePath, string guid)
{
var fileContents = System.IO.File.ReadAllText(filePath);

// -? number can be negative
// [0-9]+ 1-n numbers
Regex.Replace(fileContents, @"fileID: -?[0-9]+, guid: " + guid,
(match) =>
{
if (match.Value != "fileID: 11500000, guid: " + guid)
{
Debug.LogWarning("NotReplaced: " + match.Value + " " + filePath);
}
return match.Value;
});
}

class UnityReference
{
public UnityReference(string srcGuid, string srcFileId, string dstGuid, string dstFileId)
{
this.srcGuid = srcGuid;
this.srcFileId = srcFileId;
this.dstGuid = dstGuid;
this.dstFileId = dstFileId;
}

public string srcGuid;
public string srcFileId;
public string dstGuid;
public string dstFileId;
}
}
[/code]