

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using AssetsTools.NET;
using AssetsTools.NET.Extra;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using R2API.Animations.Models.Interfaces;
using R2API.AutoVersionGen;
using R2API.Models;
using R2API.NativeStructs;
using RoR2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.Animations")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+4c3fa0aa1bf06bccbf6fd22f858a2b3d0c968b1c")]
[assembly: AssemblyProduct("R2API.Animations")]
[assembly: AssemblyTitle("R2API.Animations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: TypeForwardedTo(typeof(Condition))]
[assembly: TypeForwardedTo(typeof(ConditionMode))]
[assembly: TypeForwardedTo(typeof(Parameter))]
[assembly: TypeForwardedTo(typeof(ParameterType))]
[assembly: TypeForwardedTo(typeof(ParameterValue))]
[assembly: TypeForwardedTo(typeof(State))]
[assembly: TypeForwardedTo(typeof(Transition))]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NativeIntegerAttribute : Attribute
{
public readonly bool[] TransformFlags;
public NativeIntegerAttribute()
{
TransformFlags = new bool[1] { true };
}
public NativeIntegerAttribute(bool[] P_0)
{
TransformFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API
{
[AutoVersion]
public static class AnimationsAPI
{
public const string PluginGUID = "com.bepis.r2api.animations";
public const string PluginName = "R2API.Animations";
private const string bundleExtension = ".bundle";
private const string hashExtension = ".hash";
private const string dummyBundleName = "dummy_controller_bundle";
private const long dummyAnimatorControllerPathID = -27250459394986890L;
private const string dummyAnimatorControllerPath = "assets/dummycontroller.controller";
private static readonly Dictionary<(string, RuntimeAnimatorController), List<AnimatorModifications>> controllerModifications = new Dictionary<(string, RuntimeAnimatorController), List<AnimatorModifications>>();
private static readonly Dictionary<RuntimeAnimatorController, List<Animator>> controllerToAnimators = new Dictionary<RuntimeAnimatorController, List<Animator>>();
private static bool _hooksEnabled = false;
public const string PluginVersion = "1.2.0";
internal static void SetHooks()
{
if (!_hooksEnabled)
{
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
_hooksEnabled = true;
}
}
internal static void UnsetHooks()
{
RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(OnLoad));
_hooksEnabled = false;
}
private static void OnLoad()
{
NativeHelpers.Init();
ApplyModifications();
}
public static void AddModifications(string sourceBundlePath, RuntimeAnimatorController sourceAnimatorController, AnimatorModifications modifications)
{
SetHooks();
controllerModifications.GetOrAddDefault((sourceBundlePath, sourceAnimatorController), () => new List<AnimatorModifications>()).Add(modifications);
}
public static void AddAnimatorController(Animator animator, RuntimeAnimatorController controller)
{
SetHooks();
controllerToAnimators.GetOrAddDefault(controller, () => new List<Animator>()).Add(animator);
}
internal static void ApplyModifications()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
AssetsManager val = new AssetsManager();
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)AnimationsPlugin.Instance).Info.Location), "dummy_controller_bundle");
foreach (KeyValuePair<(string, RuntimeAnimatorController), List<AnimatorModifications>> controllerModification in controllerModifications)
{
controllerModification.Deconstruct(out var key, out var value);
(string, RuntimeAnimatorController) tuple = key;
string item = tuple.Item1;
RuntimeAnimatorController item2 = tuple.Item2;
List<AnimatorModifications> modifications = value;
long assetPathID = NativeHelpers.GetAssetPathID((Object)(object)item2);
string text2 = Path.Combine(Paths.CachePath, "R2API.Animations", string.Format("{0}_{1}{2}", Path.GetFileName(item), assetPathID, ".bundle"));
string text3 = Path.Combine(Paths.CachePath, "R2API.Animations", string.Format("{0}_{1}{2}", Path.GetFileName(item), assetPathID, ".hash"));
bool value2 = AnimationsPlugin.IgnoreCache.Value;
string hash = null;
if (value2 || !CachedBundleExists(text2, text3, assetPathID, modifications, out hash))
{
BundleFileInstance val2 = val.LoadBundleFile(item, true);
AssetsFileInstance assetFile = val.LoadAssetsFileFromBundle(val2, 0, false);
BundleFileInstance val3 = val.LoadBundleFile(text, true);
AssetsFileInstance val4 = val.LoadAssetsFileFromBundle(val3, 0, false);
new ModificationsBundleCreator(val, assetFile, assetPathID, val4, val3, -27250459394986890L, modifications, text2).Run();
if (!value2)
{
File.WriteAllText(text3, hash);
}
val.UnloadAssetsFile(val4);
val.UnloadBundleFile(val3);
}
RuntimeAnimatorController runtimeAnimatorController = AssetBundle.LoadFromFile(text2).LoadAsset<RuntimeAnimatorController>("assets/dummycontroller.controller");
if (!controllerToAnimators.TryGetValue(item2, out List<Animator> value3))
{
continue;
}
foreach (Animator item3 in value3)
{
item3.runtimeAnimatorController = runtimeAnimatorController;
}
}
val.UnloadAll(true);
controllerModifications.Clear();
controllerToAnimators.Clear();
}
private static bool CachedBundleExists(string modifiedBundlePath, string hashPath, long sourceAnimatorControllerPathID, List<AnimatorModifications> modifications, out string hash)
{
using (MD5 mD = MD5.Create())
{
using MemoryStream memoryStream = new MemoryStream();
using BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(RoR2Application.buildId);
binaryWriter.Write(sourceAnimatorControllerPathID);
foreach (AnimatorModifications item in modifications.OrderBy((AnimatorModifications m) => m.Key))
{
binaryWriter.Write(item.Key);
}
byte[] array = mD.ComputeHash(memoryStream);
hash = BitConverter.ToString(array);
}
if (!File.Exists(modifiedBundlePath))
{
return false;
}
if (!File.Exists(hashPath))
{
return false;
}
string text = File.ReadAllText(hashPath);
return hash == text;
}
}
[BepInPlugin("com.bepis.r2api.animations", "R2API.Animations", "1.2.0")]
public sealed class AnimationsPlugin : BaseUnityPlugin
{
internal static AnimationsPlugin Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static ConfigEntry<bool> IgnoreCache { get; private set; }
private void Awake()
{
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
IgnoreCache = ((BaseUnityPlugin)this).Config.Bind<bool>("Dev", "IgnoreCache", false, "Always generate new bundles with modifications");
}
private void OnDestroy()
{
AnimationsAPI.UnsetHooks();
}
}
public class AnimatorModifications : IExistingAnimatorController
{
public string Key { get; }
public Dictionary<string, List<State>> NewStates { get; } = new Dictionary<string, List<State>>();
public Dictionary<(string, string), List<Transition>> NewTransitions { get; } = new Dictionary<(string, string), List<Transition>>();
public List<Parameter> NewParameters { get; } = new List<Parameter>();
IReadOnlyList<IParameter> IExistingAnimatorController.NewParameters => (IReadOnlyList<IParameter>)NewParameters;
public List<ExistingLayer> Layers { get; } = new List<ExistingLayer>();
IReadOnlyList<IExistingLayer> IExistingAnimatorController.Layers => (IReadOnlyList<IExistingLayer>)Layers;
public List<Layer> NewLayers { get; } = new List<Layer>();
IReadOnlyList<ILayer> IExistingAnimatorController.NewLayers => (IReadOnlyList<ILayer>)NewLayers;
public AnimatorModifications(BepInPlugin plugin)
{
Key = $"{plugin.GUID};{plugin.Version}";
}
[Obsolete]
public static AnimatorModifications CreateFromDiff(AnimatorDiff diff, BepInPlugin plugin, string clipBundlePath)
{
return CreateFromDiff(diff, plugin);
}
public static AnimatorModifications CreateFromDiff(AnimatorDiff diff, BepInPlugin plugin)
{
AnimatorModifications animatorModifications = new AnimatorModifications(plugin);
animatorModifications.Layers.AddRange(diff.Layers);
animatorModifications.NewLayers.AddRange(diff.NewLayers);
animatorModifications.NewParameters.AddRange(diff.NewParameters);
foreach (ExistingLayer layer in diff.Layers)
{
animatorModifications.NewStates[layer.Name] = layer.NewStates;
foreach (ExistingState existingState in layer.ExistingStates)
{
animatorModifications.NewTransitions[(layer.Name, existingState.Name)] = existingState.NewTransitions;
}
}
return animatorModifications;
}
}
internal static class Extensions
{
public static TValue GetOrAddDefault<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, Func<TValue> defaultValueFunc)
{
if (dict.TryGetValue(key, out TValue value))
{
return value;
}
return dict[key] = defaultValueFunc();
}
public static int IndexOf<T>(this IEnumerable<T> values, Func<T, bool> predicate)
{
int result = 0;
foreach (T value in values)
{
if (predicate(value))
{
return result;
}
}
return -1;
}
}
internal class ModificationsBundleCreator
{
private class BehavioursNode
{
public uint FullPathID;
public string FullPath;
public bool IsState;
public BehavioursNode Parent;
public List<uint> Behaviours = new List<uint>();
}
private readonly AssetsManager manager;
private readonly AssetsFileInstance assetFile;
private readonly long sourceAnimatorControllerPathID;
private readonly AssetsFileInstance dummyAssetFile;
private readonly BundleFileInstance dummyBundleFile;
private readonly long dummyAnimatorControllerPathID;
private readonly List<AnimatorModifications> modifications;
private readonly string modifiedBundlePath;
private readonly List<string> dependencies = new List<string>();
private readonly List<string> newNames = new List<string>();
private readonly Dictionary<uint, string> hashToName = new Dictionary<uint, string>();
private readonly Dictionary<string, uint> nameToHash = new Dictionary<string, uint>();
private readonly List<Action> delayedActions = new List<Action>();
private AssetTypeValueField baseField;
private AnimatorModifications currentModification;
private void AddBehaviours()
{
AssetTypeValueField obj = baseField["m_Controller"];
AssetTypeValueField val = obj["m_LayerArray"]["Array"];
AssetTypeValueField stateMachineArray = obj["m_StateMachineArray"]["Array"];
GatherLayerBehaviourNodes(val, stateMachineArray, out List<Dictionary<uint, BehavioursNode>> layerBehaviourNodes);
AssetTypeValueField val2 = baseField["m_StateMachineBehaviours"]["Array"];
AssetTypeValueField obj2 = baseField["m_StateMachineBehaviourVectorDescription"];
AssetTypeValueField val3 = obj2["m_StateMachineBehaviourRanges"]["Array"];
AssetTypeValueField val4 = obj2["m_StateMachineBehaviourIndices"]["Array"];
List<(int, long)> list = new List<(int, long)>();
Dictionary<StateMachineBehaviour, uint> addedBehaviours = new Dictionary<StateMachineBehaviour, uint>();
foreach (AssetTypeValueField item3 in val2)
{
list.Add((item3["m_FileID"].AsInt, item3["m_PathID"].AsLong));
}
List<(uint, int, List<uint>)> list2 = new List<(uint, int, List<uint>)>();
foreach (AssetTypeValueField item4 in val3)
{
AssetTypeValueField obj3 = item4["first"];
uint asUInt = obj3["m_LayerIndex"].AsUInt;
uint asUInt2 = obj3["m_StateID"].AsUInt;
AssetTypeValueField obj4 = item4["second"];
int asUInt3 = (int)obj4["m_StartIndex"].AsUInt;
uint asUInt4 = obj4["m_Count"].AsUInt;
if (layerBehaviourNodes[(int)asUInt].TryGetValue(asUInt2, out var value))
{
for (int i = 0; i < asUInt4; i++)
{
value.Behaviours.Add(val4[i + asUInt3].AsUInt);
}
continue;
}
List<uint> list3 = new List<uint>();
for (int j = 0; j < asUInt4; j++)
{
list3.Add(val4[j + asUInt3].AsUInt);
}
list2.Add((asUInt2, (int)asUInt, list3));
}
foreach (Dictionary<uint, BehavioursNode> item5 in layerBehaviourNodes)
{
foreach (BehavioursNode item6 in item5.Values.Where((BehavioursNode v) => v.IsState))
{
for (BehavioursNode parent = item6.Parent; parent != null; parent = parent.Parent)
{
foreach (uint behaviour in parent.Behaviours)
{
item6.Behaviours.Remove(behaviour);
}
}
}
}
foreach (AnimatorModifications modification in modifications)
{
AnimatorModifications animatorModifications = (currentModification = modification);
foreach (ExistingLayer layer in animatorModifications.Layers)
{
uint layerID2 = GetOrAddName(layer.Name);
int num = ((IEnumerable<AssetTypeValueField>)val).IndexOf((AssetTypeValueField l) => l["data"]["m_Binding"].AsUInt == layerID2);
Dictionary<uint, BehavioursNode> behavioursNodes = layerBehaviourNodes[num];
if (Object.op_Implicit((Object)(object)layer.StateMachine))
{
FillExistingStateMachineBehaviours("", layer.StateMachine, list, behavioursNodes, addedBehaviours);
continue;
}
AssetTypeValueField layerField = val[num];
FillSyncedStateMachineBehaviours(layer.NewSyncedBehaviours, stateMachineArray, behavioursNodes, layerField, list, addedBehaviours);
}
foreach (Layer newLayer in animatorModifications.NewLayers)
{
uint layerID = GetOrAddName(newLayer.Name);
int num2 = ((IEnumerable<AssetTypeValueField>)val).IndexOf((AssetTypeValueField l) => l["data"]["m_Binding"].AsUInt == layerID);
Dictionary<uint, BehavioursNode> behavioursNodes2 = layerBehaviourNodes[num2];
if (Object.op_Implicit((Object)(object)newLayer.StateMachine))
{
FillStateMachineBehaviours("", newLayer.StateMachine, list, behavioursNodes2, addedBehaviours);
continue;
}
AssetTypeValueField layerField2 = val[num2];
FillSyncedStateMachineBehaviours(newLayer.SyncedBehaviours, stateMachineArray, behavioursNodes2, layerField2, list, addedBehaviours);
}
}
currentModification = null;
val2.Children.Clear();
foreach (var item7 in list)
{
int item = item7.Item1;
long item2 = item7.Item2;
AssetTypeValueField val5 = ValueBuilder.DefaultValueFieldFromTemplate(val2.TemplateField.Children[1]);
val2.Children.Add(val5);
val5["m_FileID"].AsInt = item;
val5["m_PathID"].AsLong = item2;
}
val4.Children.Clear();
val3.Children.Clear();
for (int k = 0; k < layerBehaviourNodes.Count; k++)
{
foreach (BehavioursNode value2 in layerBehaviourNodes[k].Values)
{
int count = val4.Children.Count;
int num3 = 0;
foreach (uint behaviour2 in value2.Behaviours)
{
num3++;
AssetTypeValueField val6 = ValueBuilder.DefaultValueFieldFromTemplate(val4.TemplateField.Children[1]);
val4.Children.Add(val6);
val6.AsUInt = behaviour2;
}
if (value2.IsState)
{
for (BehavioursNode parent2 = value2.Parent; parent2 != null; parent2 = parent2.Parent)
{
for (int m = 0; m < parent2.Behaviours.Count; m++)
{
uint asUInt5 = parent2.Behaviours[m];
num3++;
AssetTypeValueField val7 = ValueBuilder.DefaultValueFieldFromTemplate(val4.TemplateField.Children[1]);
val4.Children.Insert(count + m, val7);
val7.AsUInt = asUInt5;
}
}
}
if (num3 > 0)
{
AssetTypeValueField val8 = ValueBuilder.DefaultValueFieldFromTemplate(val3.TemplateField.Children[1]);
val3.Children.Add(val8);
AssetTypeValueField obj5 = val8["first"];
obj5["m_StateID"].AsUInt = value2.FullPathID;
obj5["m_LayerIndex"].AsInt = k;
AssetTypeValueField obj6 = val8["second"];
obj6["m_StartIndex"].AsUInt = (uint)count;
obj6["m_Count"].AsUInt = (uint)num3;
}
}
}
foreach (var item8 in list2)
{
int count2 = val4.Children.Count;
int num4 = 0;
foreach (uint item9 in item8.Item3)
{
num4++;
AssetTypeValueField val9 = ValueBuilder.DefaultValueFieldFromTemplate(val4.TemplateField.Children[1]);
val4.Children.Add(val9);
val9.AsUInt = item9;
}
if (num4 > 0)
{
AssetTypeValueField val10 = ValueBuilder.DefaultValueFieldFromTemplate(val3.TemplateField.Children[1]);
val3.Children.Add(val10);
AssetTypeValueField obj7 = val10["first"];
obj7["m_StateID"].AsUInt = item8.Item1;
obj7["m_LayerIndex"].AsInt = item8.Item2;
AssetTypeValueField obj8 = val10["second"];
obj8["m_StartIndex"].AsUInt = (uint)count2;
obj8["m_Count"].AsUInt = (uint)num4;
}
}
val3.Children = (from f in val3.Children
orderby f["first"]["m_StateID"].AsUInt, f["first"]["m_LayerIndex"].AsInt
select f).ToList();
}
private void GatherLayerBehaviourNodes(AssetTypeValueField layerArray, AssetTypeValueField stateMachineArray, out List<Dictionary<uint, BehavioursNode>> layerBehaviourNodes)
{
layerBehaviourNodes = new List<Dictionary<uint, BehavioursNode>>();
List<Dictionary<uint, BehavioursNode>> list = new List<Dictionary<uint, BehavioursNode>>();
foreach (AssetTypeValueField item in stateMachineArray)
{
Dictionary<uint, BehavioursNode> dictionary = new Dictionary<uint, BehavioursNode>();
list.Add(dictionary);
foreach (AssetTypeValueField item2 in item["data"]["m_StateConstantArray"]["Array"])
{
uint asUInt = item2["data"]["m_FullPathID"].AsUInt;
string fullPath2 = hashToName[asUInt];
BehavioursNode value = new BehavioursNode
{
FullPathID = asUInt,
FullPath = fullPath2,
IsState = true,
Parent = GetOrCreateParent(fullPath2, dictionary)
};
dictionary[asUInt] = value;
}
}
foreach (AnimatorModifications modification in modifications)
{
AnimatorModifications animatorModifications = (currentModification = modification);
foreach (ExistingLayer layer in animatorModifications.Layers)
{
if (Object.op_Implicit((Object)(object)layer.StateMachine))
{
uint layerID2 = GetOrAddName(layer.Name);
uint asUInt2 = ((IEnumerable<AssetTypeValueField>)layerArray).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField l) => l["data"]["m_Binding"].AsUInt == layerID2))["data"]["m_StateMachineIndex"].AsUInt;
Dictionary<uint, BehavioursNode> behavioursNodes2 = list[(int)asUInt2];
FillBehaviourNodesFromExistingStateMachine(layer.StateMachine, behavioursNodes2, "");
}
}
foreach (Layer newLayer in animatorModifications.NewLayers)
{
if (Object.op_Implicit((Object)(object)newLayer.StateMachine))
{
uint layerID = GetOrAddName(newLayer.Name);
uint asUInt3 = ((IEnumerable<AssetTypeValueField>)layerArray).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField l) => l["data"]["m_Binding"].AsUInt == layerID))["data"]["m_StateMachineIndex"].AsUInt;
Dictionary<uint, BehavioursNode> behavioursNodes3 = list[(int)asUInt3];
FillBehaviourNodesFromStateMachine(newLayer.StateMachine, behavioursNodes3, "");
}
}
}
currentModification = null;
foreach (AssetTypeValueField item3 in layerArray)
{
new Dictionary<uint, List<uint>>();
uint asUInt4 = item3["data"]["m_StateMachineIndex"].AsUInt;
uint asUInt5 = item3["data"]["m_StateMachineSynchronizedLayerIndex"].AsUInt;
Dictionary<uint, BehavioursNode> dictionary2 = list[(int)asUInt4];
if (asUInt5 != 0)
{
dictionary2 = dictionary2.ToDictionary((KeyValuePair<uint, BehavioursNode> n) => n.Key, (KeyValuePair<uint, BehavioursNode> n) => n.Value.IsState ? new BehavioursNode
{
FullPath = n.Value.FullPath,
FullPathID = n.Value.FullPathID,
Parent = n.Value.Parent,
IsState = true
} : n.Value);
}
layerBehaviourNodes.Add(dictionary2);
}
BehavioursNode GetOrCreateParent(string fullPath, Dictionary<uint, BehavioursNode> behavioursNodes)
{
int num = fullPath.LastIndexOf('.');
if (num == -1)
{
return null;
}
string text = fullPath.Substring(0, num);
uint orAddName = GetOrAddName(text);
if (!behavioursNodes.TryGetValue(orAddName, out BehavioursNode value2))
{
value2 = (behavioursNodes[orAddName] = new BehavioursNode
{
FullPathID = orAddName,
FullPath = text,
IsState = false,
Parent = GetOrCreateParent(text, behavioursNodes)
});
}
return value2;
}
}
private void FillBehaviourNodesFromExistingStateMachine(ExistingStateMachine stateMachine, Dictionary<uint, BehavioursNode> behavioursNodes, string stateMachinePath, BehavioursNode parent = null)
{
string text = (string.IsNullOrEmpty(stateMachinePath) ? stateMachine.Name : (stateMachinePath + "." + stateMachine.Name));
uint orAddName = GetOrAddName(text);
if (!behavioursNodes.TryGetValue(orAddName, out BehavioursNode value))
{
BehavioursNode obj = new BehavioursNode
{
FullPath = text,
FullPathID = orAddName,
Parent = parent,
IsState = false
};
value = obj;
behavioursNodes[orAddName] = obj;
}
foreach (ExistingStateMachine subStateMachine in stateMachine.SubStateMachines)
{
FillBehaviourNodesFromExistingStateMachine(subStateMachine, behavioursNodes, text, value);
}
foreach (StateMachine newSubStateMachine in stateMachine.NewSubStateMachines)
{
FillBehaviourNodesFromStateMachine(newSubStateMachine, behavioursNodes, text, value);
}
}
private void FillBehaviourNodesFromStateMachine(StateMachine stateMachine, Dictionary<uint, BehavioursNode> behavioursNodes, string stateMachinePath, BehavioursNode parent = null)
{
string text = (string.IsNullOrEmpty(stateMachinePath) ? stateMachine.Name : (stateMachinePath + "." + stateMachine.Name));
uint orAddName = GetOrAddName(text);
if (!behavioursNodes.TryGetValue(orAddName, out BehavioursNode value))
{
BehavioursNode obj = new BehavioursNode
{
FullPath = text,
FullPathID = orAddName,
Parent = parent,
IsState = false
};
value = obj;
behavioursNodes[orAddName] = obj;
}
foreach (StateMachine subStateMachine in stateMachine.SubStateMachines)
{
FillBehaviourNodesFromStateMachine(subStateMachine, behavioursNodes, text, value);
}
}
private void FillSyncedStateMachineBehaviours(List<SyncedBehaviour> syncedBehaviours, AssetTypeValueField stateMachineArray, Dictionary<uint, BehavioursNode> behavioursNodes, AssetTypeValueField layerField, List<(int, long)> behaviours, Dictionary<StateMachineBehaviour, uint> addedBehaviours)
{
uint asUInt = layerField["data"]["m_StateMachineIndex"].AsUInt;
AssetTypeValueField obj = stateMachineArray[(int)asUInt];
int asUInt2 = (int)obj["data"]["m_DefaultState"].AsUInt;
uint asUInt3 = obj["data"]["m_StateConstantArray"]["Array"][asUInt2]["data"]["m_FullPathID"].AsUInt;
BehavioursNode behavioursNode = behavioursNodes[asUInt3];
while (behavioursNode.Parent != null)
{
behavioursNode = behavioursNode.Parent;
}
foreach (SyncedBehaviour syncedBehaviour in syncedBehaviours)
{
string text = (string.IsNullOrEmpty(syncedBehaviour.StateMachinePath) ? behavioursNode.FullPath : syncedBehaviour.StateMachinePath);
uint orAddName = GetOrAddName(text + "." + syncedBehaviour.StateName);
BehavioursNode behavioursNode2 = behavioursNodes[orAddName];
foreach (StateMachineBehaviour behaviour in syncedBehaviour.Behaviours)
{
if (!addedBehaviours.TryGetValue(behaviour, out var value))
{
value = (uint)behaviours.Count;
TryAddDependency((Object)(object)behaviour, out var fileID, out var pathID);
behaviours.Add((fileID, pathID));
}
behavioursNode2.Behaviours.Add(value);
}
}
}
private void FillStateMachineBehaviours(string stateMachinePath, StateMachine stateMachine, List<(int, long)> behaviours, Dictionary<uint, BehavioursNode> behavioursNodes, Dictionary<StateMachineBehaviour, uint> addedBehaviours)
{
string text = (string.IsNullOrEmpty(stateMachinePath) ? stateMachine.Name : (stateMachinePath + "." + stateMachine.Name));
uint orAddName = GetOrAddName(text);
BehavioursNode behavioursNode = behavioursNodes[orAddName];
foreach (StateMachineBehaviour behaviour in stateMachine.Behaviours)
{
if (!addedBehaviours.TryGetValue(behaviour, out var value))
{
value = (uint)behaviours.Count;
if (!TryAddDependency((Object)(object)behaviour, out var fileID, out var pathID))
{
LogError("Behaviour for a StateMachine \"" + behavioursNode.FullPath + "\". Make sure it was loaded from an AssetBundle.");
continue;
}
behaviours.Add((fileID, pathID));
}
behavioursNode.Behaviours.Add(value);
}
foreach (State state in stateMachine.States)
{
uint orAddName2 = GetOrAddName(text + "." + state.Name);
BehavioursNode behavioursNode2 = behavioursNodes[orAddName2];
foreach (StateMachineBehaviour behaviour2 in state.Behaviours)
{
if (!addedBehaviours.TryGetValue(behaviour2, out var value2))
{
value2 = (uint)behaviours.Count;
if (!TryAddDependency((Object)(object)behaviour2, out var fileID2, out var pathID2))
{
LogError("Behaviour for a State \"" + behavioursNode2.FullPath + "\". Make sure it was loaded from an AssetBundle.");
continue;
}
behaviours.Add((fileID2, pathID2));
}
behavioursNode2.Behaviours.Add(value2);
}
}
foreach (StateMachine subStateMachine in stateMachine.SubStateMachines)
{
FillStateMachineBehaviours(text, subStateMachine, behaviours, behavioursNodes, addedBehaviours);
}
}
private void FillExistingStateMachineBehaviours(string stateMachinePath, ExistingStateMachine stateMachine, List<(int, long)> behaviours, Dictionary<uint, BehavioursNode> behavioursNodes, Dictionary<StateMachineBehaviour, uint> addedBehaviours)
{
string text = (string.IsNullOrEmpty(stateMachinePath) ? stateMachine.Name : (stateMachinePath + "." + stateMachine.Name));
uint orAddName = GetOrAddName(text);
BehavioursNode behavioursNode = behavioursNodes[orAddName];
foreach (StateMachineBehaviour newBehaviour in stateMachine.NewBehaviours)
{
if (!addedBehaviours.TryGetValue(newBehaviour, out var value))
{
value = (uint)behaviours.Count;
if (!TryAddDependency((Object)(object)newBehaviour, out var fileID, out var pathID))
{
LogError("Behaviour for a StateMachine \"" + behavioursNode.FullPath + "\". Make sure it was loaded from an AssetBundle.");
continue;
}
behaviours.Add((fileID, pathID));
}
behavioursNode.Behaviours.Add(value);
}
foreach (ExistingState state in stateMachine.States)
{
uint orAddName2 = GetOrAddName(text + "." + state.Name);
BehavioursNode behavioursNode2 = behavioursNodes[orAddName2];
foreach (StateMachineBehaviour newBehaviour2 in state.NewBehaviours)
{
if (!addedBehaviours.TryGetValue(newBehaviour2, out var value2))
{
value2 = (uint)behaviours.Count;
if (!TryAddDependency((Object)(object)newBehaviour2, out var fileID2, out var pathID2))
{
LogError("Behaviour for a State \"" + behavioursNode2.FullPath + "\". Make sure it was loaded from an AssetBundle.");
continue;
}
behaviours.Add((fileID2, pathID2));
}
behavioursNode2.Behaviours.Add(value2);
}
}
foreach (State newState in stateMachine.NewStates)
{
uint orAddName3 = GetOrAddName(text + "." + newState.Name);
BehavioursNode behavioursNode3 = behavioursNodes[orAddName3];
foreach (StateMachineBehaviour behaviour in newState.Behaviours)
{
if (!addedBehaviours.TryGetValue(behaviour, out var value3))
{
value3 = (uint)behaviours.Count;
if (!TryAddDependency((Object)(object)behaviour, out var fileID3, out var pathID3))
{
LogError("Behaviour for a State \"" + behavioursNode3.FullPath + "\". Make sure it was loaded from an AssetBundle.");
continue;
}
behaviours.Add((fileID3, pathID3));
}
behavioursNode3.Behaviours.Add(value3);
}
}
foreach (ExistingStateMachine subStateMachine in stateMachine.SubStateMachines)
{
FillExistingStateMachineBehaviours(text, subStateMachine, behaviours, behavioursNodes, addedBehaviours);
}
foreach (StateMachine newSubStateMachine in stateMachine.NewSubStateMachines)
{
FillStateMachineBehaviours(text, newSubStateMachine, behaviours, behavioursNodes, addedBehaviours);
}
}
private void CreateBlendTreeFromMotion(AssetTypeValueField animationClips, IMotion motion, AssetTypeValueField blendTreeIndexArray, AssetTypeValueField blendTreeConstantArray)
{
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(blendTreeIndexArray.TemplateField.Children[1]);
blendTreeIndexArray.Children.Add(val);
if (motion != null && (Object.op_Implicit((Object)(object)motion.Clip) || motion.BlendTree != null))
{
val.AsInt = blendTreeConstantArray.Children.Count;
AssetTypeValueField val2 = ValueBuilder.DefaultValueFieldFromTemplate(blendTreeConstantArray.TemplateField.Children[1]);
blendTreeConstantArray.Children.Add(val2);
AssetTypeValueField nodeArray = val2["data"]["m_NodeArray"]["Array"];
if (Object.op_Implicit((Object)(object)motion.Clip))
{
CreateBlendTreeNodeFromClip(animationClips, nodeArray, motion.Clip);
}
else
{
CreateBlendTreeNodeFromBlendTree(animationClips, nodeArray, motion.BlendTree);
}
}
else
{
val.AsInt = -1;
}
}
private int CreateBlendTreeNodeFromClip(AssetTypeValueField animationClips, AssetTypeValueField nodeArray, AnimationClip clip, float cycleOffset = 0f, bool mirror = false, float timeScale = 1f)
{
TryAddDependency((Object)(object)clip, out var fileID, out var pathID);
int count = animationClips.Children.Count;
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(animationClips.TemplateField.Children[1]);
val["m_FileID"].AsInt = fileID;
val["m_PathID"].AsLong = pathID;
animationClips.Children.Add(val);
AssetTypeValueField val2 = ValueBuilder.DefaultValueFieldFromTemplate(nodeArray.TemplateField.Children[1]);
AssetTypeValueField obj = val2["data"];
obj["m_BlendEventID"].AsUInt = uint.MaxValue;
obj["m_BlendEventYID"].AsUInt = uint.MaxValue;
obj["m_ClipID"].AsInt = count;
obj["m_Duration"].AsFloat = ((timeScale == 0f) ? 100f : (1f / timeScale));
obj["m_CycleOffset"].AsFloat = cycleOffset;
obj["m_Mirror"].AsBool = mirror;
nodeArray.Children.Add(val2);
return nodeArray.Children.Count - 1;
}
private int CreateBlendTreeNodeFromBlendTree(AssetTypeValueField animationClips, AssetTypeValueField nodeArray, IBlendTree blendTree, float cycleOffset = 0f, bool mirror = false)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected I4, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Invalid comparison between Unknown and I4
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Invalid comparison between Unknown and I4
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Expected I4, but got Unknown
//IL_034c: Unknown result type (might be due to invalid IL or missing references)
//IL_0369: Unknown result type (might be due to invalid IL or missing references)
uint orAddName = GetOrAddName(blendTree.BlendParameter);
uint orAddName2 = GetOrAddName(blendTree.BlendParameterY);
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(nodeArray.TemplateField.Children[1]);
nodeArray.Children.Add(val);
int result = nodeArray.Children.Count - 1;
AssetTypeValueField val2 = val["data"];
val2["m_BlendType"].AsUInt = (uint)(int)blendTree.BlendType;
if ((int)blendTree.BlendType != 4)
{
val2["m_BlendEventID"].AsUInt = orAddName;
}
else
{
val2["m_BlendEventID"].AsUInt = uint.MaxValue;
}
if ((int)blendTree.BlendType != 0 && (int)blendTree.BlendType != 4)
{
val2["m_BlendEventYID"].AsUInt = orAddName2;
}
else
{
val2["m_BlendEventYID"].AsUInt = uint.MaxValue;
}
val2["m_ClipID"].AsUInt = uint.MaxValue;
val2["m_Duration"].AsFloat = 0f;
val2["m_CycleOffset"].AsFloat = cycleOffset;
val2["m_Mirror"].AsBool = mirror;
AssetTypeValueField val3 = val2["m_ChildIndices"]["Array"];
foreach (IChildMotion child in blendTree.Children)
{
if (Object.op_Implicit((Object)(object)((IMotion)child).Clip))
{
AssetTypeValueField val4 = ValueBuilder.DefaultValueFieldFromTemplate(val3.TemplateField.Children[1]);
val4.AsInt = CreateBlendTreeNodeFromClip(animationClips, nodeArray, ((IMotion)child).Clip, child.CycleOffset, child.Mirror, child.TimeScale);
val3.Children.Add(val4);
}
else if (((IMotion)child).BlendTree != null)
{
AssetTypeValueField val5 = ValueBuilder.DefaultValueFieldFromTemplate(val3.TemplateField.Children[1]);
val5.AsInt = CreateBlendTreeNodeFromBlendTree(animationClips, nodeArray, ((IMotion)child).BlendTree, child.CycleOffset, child.Mirror);
val3.Children.Add(val5);
}
}
BlendTreeType blendType = blendTree.BlendType;
switch ((int)blendType)
{
case 0:
{
AssetTypeValueField val10 = val2["m_Blend1dData"]["data"]["m_ChildThresholdArray"]["Array"];
foreach (IChildMotion child2 in blendTree.Children)
{
AssetTypeValueField val11 = ValueBuilder.DefaultValueFieldFromTemplate(val10.TemplateField.Children[1]);
val11.AsFloat = child2.Threshold;
val10.Children.Add(val11);
}
break;
}
case 1:
{
AssetTypeValueField val8 = val2["m_Blend2dData"]["data"]["m_ChildPositionArray"]["Array"];
foreach (IChildMotion child3 in blendTree.Children)
{
AssetTypeValueField val9 = ValueBuilder.DefaultValueFieldFromTemplate(val8.TemplateField.Children[1]);
val9["x"].AsFloat = child3.Position.x;
val9["y"].AsFloat = child3.Position.y;
val8.Children.Add(val9);
}
break;
}
case 2:
case 3:
ComputeFreeform(blendTree, val2);
break;
case 4:
{
AssetTypeValueField val6 = val2["m_BlendDirectData"]["data"]["m_ChildBlendEventIDArray"]["Array"];
foreach (IChildMotion child4 in blendTree.Children)
{
AssetTypeValueField val7 = ValueBuilder.DefaultValueFieldFromTemplate(val6.TemplateField.Children[1]);
val7.AsUInt = GetOrAddName(child4.DirectBlendParameter);
val6.Children.Add(val7);
}
break;
}
}
return result;
}
private void ComputeFreeform(IBlendTree blendTree, AssetTypeValueField nodeDataField)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Invalid comparison between Unknown and I4
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Invalid comparison between Unknown and I4
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Invalid comparison between Unknown and I4
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Invalid comparison between Unknown and I4
//IL_0426: Unknown result type (might be due to invalid IL or missing references)
//IL_042b: Unknown result type (might be due to invalid IL or missing references)
//IL_0452: Unknown result type (might be due to invalid IL or missing references)
//IL_046a: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
int count = blendTree.Children.Count;
Vector2[] array = (Vector2[])(object)new Vector2[count];
float[] array2 = new float[count];
Vector2[] array3 = (Vector2[])(object)new Vector2[count * count];
float[] array4 = new float[count * count];
bool[] array5 = new bool[count * count];
Vector2 val2;
for (int i = 0; i < blendTree.Children.Count; i++)
{
IChildMotion val = blendTree.Children[i];
array[i] = val.Position;
if ((int)blendTree.BlendType == 2)
{
int num = i;
val2 = val.Position;
array2[num] = ((Vector2)(ref val2)).magnitude;
}
}
if ((int)blendTree.BlendType == 2)
{
for (int j = 0; j < count; j++)
{
IChildMotion val3 = blendTree.Children[j];
for (int k = 0; k < count; k++)
{
IChildMotion val4 = blendTree.Children[k];
int num2 = j + k * count;
float num3 = array2[j];
float num4 = array2[k];
float num5 = num4 + num3;
num5 = (array4[num2] = ((num5 == 0f) ? float.PositiveInfinity : (2f / num5)));
float num6 = 0f;
if (num4 != 0f && num3 != 0f)
{
num6 = Vector2.SignedAngle(val3.Position, val4.Position) * (MathF.PI / 180f);
}
float num7 = (num4 - num3) * num5;
array3[num2] = new Vector2(num6, num7);
}
}
}
else if ((int)blendTree.BlendType == 3)
{
for (int l = 0; l < count; l++)
{
IChildMotion val5 = blendTree.Children[l];
for (int m = 0; m < count; m++)
{
IChildMotion val6 = blendTree.Children[m];
int num8 = l + m * count;
val2 = val6.Position - val5.Position;
array4[num8] = 1f / ((Vector2)(ref val2)).sqrMagnitude;
Vector2 val7 = val6.Position - val5.Position;
array3[num8] = val7;
}
}
}
ComputeNeighborsFreeform(blendTree, array, array2, array3, array4, array5);
AssetTypeValueField obj = nodeDataField["m_Blend2dData"]["data"];
AssetTypeValueField val8 = obj["m_ChildPositionArray"]["Array"];
AssetTypeValueField val9 = obj["m_ChildMagnitudeArray"]["Array"];
AssetTypeValueField val10 = obj["m_ChildPairVectorArray"]["Array"];
AssetTypeValueField val11 = obj["m_ChildPairAvgMagInvArray"]["Array"];
AssetTypeValueField val12 = obj["m_ChildNeighborListArray"]["Array"];
for (int n = 0; n < array.Length; n++)
{
Vector2 val13 = array[n];
AssetTypeValueField val14 = ValueBuilder.DefaultValueFieldFromTemplate(val8.TemplateField.Children[1]);
val14["x"].AsFloat = val13.x;
val14["y"].AsFloat = val13.y;
val8.Children.Add(val14);
if ((int)blendTree.BlendType == 2)
{
float asFloat = array2[n];
AssetTypeValueField val15 = ValueBuilder.DefaultValueFieldFromTemplate(val9.TemplateField.Children[1]);
val15.AsFloat = asFloat;
val9.Children.Add(val15);
}
AssetTypeValueField val16 = ValueBuilder.DefaultValueFieldFromTemplate(val12.TemplateField.Children[1]);
val12.Children.Add(val16);
AssetTypeValueField val17 = val16["m_NeighborArray"]["Array"];
for (int num9 = 0; num9 < count; num9++)
{
if (array5[n * count + num9])
{
AssetTypeValueField val18 = ValueBuilder.DefaultValueFieldFromTemplate(val17.TemplateField.Children[1]);
val18.AsInt = num9;
val17.Children.Add(val18);
}
}
}
for (int num10 = 0; num10 < array3.Length; num10++)
{
float asFloat2 = array4[num10];
AssetTypeValueField val19 = ValueBuilder.DefaultValueFieldFromTemplate(val11.TemplateField.Children[1]);
val19.AsFloat = asFloat2;
val11.Children.Add(val19);
Vector2 val20 = array3[num10];
AssetTypeValueField val21 = ValueBuilder.DefaultValueFieldFromTemplate(val10.TemplateField.Children[1]);
val21["x"].AsFloat = val20.x;
val21["y"].AsFloat = val20.y;
val10.Children.Add(val21);
}
}
private void ComputeNeighborsFreeform(IBlendTree blendTree, Vector2[] positions, float[] magnitudes, Vector2[] pairVectors, float[] pairAvgMagInvs, bool[] neighbors)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Invalid comparison between Unknown and I4
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Invalid comparison between Unknown and I4
int count = blendTree.Children.Count;
int[] array = new int[count];
Vector2[] workspaceBlendVectors = (Vector2[])(object)new Vector2[count];
float num = 10000f;
float num2 = -10000f;
float num3 = 10000f;
float num4 = -10000f;
foreach (Vector2 val in positions)
{
num = Mathf.Min(num, val.x);
num2 = Mathf.Max(num2, val.x);
num3 = Mathf.Min(num3, val.y);
num4 = Mathf.Max(num4, val.y);
}
float num5 = (num2 - num) * 0.5f;
float num6 = (num4 - num3) * 0.5f;
num -= num5;
num2 += num5;
num3 -= num6;
num4 += num6;
for (int j = 0; j <= 100; j++)
{
float num7 = (float)j * 0.01f;
for (int k = 0; k <= 100; k++)
{
float num8 = (float)k * 0.01f;
if ((int)blendTree.BlendType == 2)
{
GetWeightsFreeformDirectional(positions, magnitudes, pairVectors, pairAvgMagInvs, array, workspaceBlendVectors, num * (1f - num7) + num2 * num7, num3 * (1f - num8) + num4 * num8);
}
else if ((int)blendTree.BlendType == 3)
{
GetWeightsFreeformCartesian(positions, pairVectors, pairAvgMagInvs, array, workspaceBlendVectors, num * (1f - num7) + num2 * num7, num3 * (1f - num8) + num4 * num8);
}
for (int l = 0; l < count; l++)
{
if (array[l] >= 0)
{
neighbors[l * count + array[l]] = true;
}
}
}
}
}
private void GetWeightsFreeformCartesian(Vector2[] positions, Vector2[] pairVectors, float[] pairAvgMagInvs, int[] cropArray, Vector2[] workspaceBlendVectors, float blendValueX, float blendValueY)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
int num = positions.Length;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(blendValueX, blendValueY);
for (int i = 0; i < num; i++)
{
workspaceBlendVectors[i] = val - positions[i];
}
for (int j = 0; j < num; j++)
{
cropArray[j] = -1;
Vector2 val2 = workspaceBlendVectors[j];
float num2 = 1f;
for (int k = 0; k < num; k++)
{
if (j != k)
{
int num3 = j + k * num;
Vector2 val3 = pairVectors[num3];
float num4 = 1f - Vector2.Dot(val3, val2) * pairAvgMagInvs[num3];
if (num4 <= 0f)
{
cropArray[j] = -1;
break;
}
if (num4 < num2)
{
cropArray[j] = k;
num2 = num4;
}
}
}
}
}
private float GetWeightFreeformDirectional(Vector2[] positions, Vector2[] pairVectors, float[] pairAvgMagInvs, Vector2[] workspaceBlendVectors, int i, int j, Vector2 blendPosition)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
int num = i + j * positions.Length;
Vector2 val = pairVectors[num];
Vector2 val2 = workspaceBlendVectors[i];
val2.y *= pairAvgMagInvs[num];
if (positions[i] == Vector2.zero)
{
val.x = workspaceBlendVectors[j].x;
}
else if (positions[j] == Vector2.zero)
{
val.x = workspaceBlendVectors[i].x;
}
else if (val.x == 0f || blendPosition == Vector2.zero)
{
val2.x = val.x;
}
return 1f - Vector2.Dot(val, val2) / ((Vector2)(ref val)).sqrMagnitude;
}
private void GetWeightsFreeformDirectional(Vector2[] positions, float[] magnitudes, Vector2[] pairVectors, float[] pairAvgMagInvs, int[] cropArray, Vector2[] workspaceBlendVectors, float blendValueX, float blendValueY)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
int num = positions.Length;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(blendValueX, blendValueY);
float magnitude = ((Vector2)(ref val)).magnitude;
if (val == Vector2.zero)
{
for (int i = 0; i < num; i++)
{
workspaceBlendVectors[i] = new Vector2(0f, magnitude - magnitudes[i]);
}
}
else
{
for (int j = 0; j < num; j++)
{
Vector2 val2 = positions[j];
float num2 = 0f;
if (val2 != Vector2.zero)
{
num2 = Vector2.SignedAngle(val2, val) * (MathF.PI / 180f);
}
workspaceBlendVectors[j] = new Vector2(num2, magnitude - magnitudes[j]);
}
}
for (int k = 0; k < num; k++)
{
float num3 = 1f - Mathf.Abs(workspaceBlendVectors[k].x) * (1f / MathF.PI);
cropArray[k] = -1;
for (int l = 0; l < num; l++)
{
if (k != l)
{
float weightFreeformDirectional = GetWeightFreeformDirectional(positions, pairVectors, pairAvgMagInvs, workspaceBlendVectors, k, l, val);
if (weightFreeformDirectional <= 0f)
{
cropArray[k] = -1;
break;
}
if (weightFreeformDirectional < num3)
{
cropArray[k] = l;
num3 = weightFreeformDirectional;
}
}
}
}
}
public ModificationsBundleCreator(AssetsManager manager, AssetsFileInstance assetFile, long sourceAnimatorControllerPathID, AssetsFileInstance dummyAssetFile, BundleFileInstance dummyBundleFile, long dummyAnimatorControllerPathID, List<AnimatorModifications> modifications, string modifiedBundlePath)
{
this.manager = manager;
this.assetFile = assetFile;
this.sourceAnimatorControllerPathID = sourceAnimatorControllerPathID;
this.dummyAssetFile = dummyAssetFile;
this.dummyBundleFile = dummyBundleFile;
this.dummyAnimatorControllerPathID = dummyAnimatorControllerPathID;
this.modifications = modifications;
this.modifiedBundlePath = modifiedBundlePath;
}
public void Run()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
AssetExternal extAsset = manager.GetExtAsset(assetFile, 0, sourceAnimatorControllerPathID, false, (AssetReadFlags)0);
baseField = extAsset.baseField;
GatherNames();
RemapPPtrs();
AddLayers();
AddStates();
AddTransitions();
foreach (Action delayedAction in delayedActions)
{
delayedAction();
}
AddBehaviours();
AddParameters();
AddTOS();
SetExternals();
SaveBundle();
}
private void GatherNames()
{
foreach (AssetTypeValueField item in baseField["m_TOS"]["Array"])
{
uint asUInt = item["first"].AsUInt;
string asString = item["second"].AsString;
hashToName[asUInt] = asString;
nameToHash[asString] = asUInt;
}
}
private void AddLayers()
{
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Expected I4, but got Unknown
AssetTypeValueField animationClips = baseField["m_AnimationClips"]["Array"];
AssetTypeValueField val = baseField["m_Controller"];
string asString = baseField["m_Name"].AsString;
AssetTypeValueField val2 = val["m_LayerArray"]["Array"];
AssetTypeValueField val3 = val["m_StateMachineArray"]["Array"];
AssetTypeValueField val4 = baseField["m_StateMachineBehaviourVectorDescription"]["m_StateMachineBehaviourRanges"]["Array"];
foreach (AnimatorModifications modification in modifications)
{
AnimatorModifications animatorModifications = (currentModification = modification);
foreach (ExistingLayer layer in animatorModifications.Layers)
{
uint layerHash = GetOrAddName(layer.Name);
AssetTypeValueField val5 = ((IEnumerable<AssetTypeValueField>)val["m_LayerArray"]["Array"]).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField f) => f["data"]["m_Binding"].AsUInt == layerHash));
if (val5 == null)
{
LogError("Layer \"" + layer.Name + "\" not found for a controller \"" + asString + "\".");
}
else if (Object.op_Implicit((Object)(object)layer.StateMachine))
{
uint asUInt = val5["data"]["m_StateMachineIndex"].AsUInt;
AssetTypeValueField stateMachineField = val3[(int)asUInt];
ModifyStateMachine(animationClips, (IExistingStateMachine)(object)layer.StateMachine, stateMachineField, "");
}
}
foreach (Layer item in animatorModifications.NewLayers.OrderBy((Layer l) => string.IsNullOrEmpty(l.SyncedLayerName)))
{
AssetTypeValueField val6 = ValueBuilder.DefaultValueFieldFromTemplate(val2.TemplateField.Children[1]);
AssetTypeValueField val7 = val6["data"];
CreateBodyMaskFromAvatarMask(val7["m_BodyMask"], item.AvatarMask);
AssetTypeValueField skeletonMaskArrayField = val7["m_SkeletonMask"]["data"]["m_Data"]["Array"];
CreateSkeletonMaskFromAvatarMask(skeletonMaskArrayField, item.AvatarMask);
uint orAddName = GetOrAddName(item.Name);
val7["m_Binding"].AsUInt = orAddName;
val7["m_DefaultWeight"].AsFloat = item.DefaultWeight;
val7["m_IKPass"].AsBool = item.IKPass;
val7["m_SyncedLayerAffectsTiming"].AsBool = item.SyncedLayerAffectsTiming;
val7["(int&)m_LayerBlendingMode"].AsInt = (int)item.BlendingMode;
if (!string.IsNullOrEmpty(item.SyncedLayerName))
{
uint syncedLayerHash = GetOrAddName(item.SyncedLayerName);
uint asUInt2 = ((IEnumerable<AssetTypeValueField>)val2).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField f) => f["data"]["m_Binding"].AsUInt == syncedLayerHash))["data"]["m_StateMachineIndex"].AsUInt;
AssetTypeValueField obj = val3[(int)asUInt2];
AssetTypeValueField val8 = obj["data"]["m_SynchronizedLayerCount"];
val7["m_StateMachineIndex"].AsUInt = asUInt2;
val7["m_StateMachineSynchronizedLayerIndex"].AsUInt = val8.AsUInt;
uint asUInt3 = val8.AsUInt;
val8.AsUInt = asUInt3 + 1;
Dictionary<uint, SyncedMotion> dictionary = item.SyncedMotions.ToDictionary((SyncedMotion f) => GetOrAddName(f.StateMachinePath + "." + f.StateName));
foreach (AssetTypeValueField item2 in obj["data"]["m_StateConstantArray"]["Array"])
{
AssetTypeValueField blendTreeIndexArray = item2["data"]["m_BlendTreeConstantIndexArray"]["Array"];
AssetTypeValueField blendTreeConstantArray = item2["data"]["m_BlendTreeConstantArray"]["Array"];
uint asUInt4 = item2["data"]["m_FullPathID"].AsUInt;
SyncedMotion valueOrDefault = dictionary.GetValueOrDefault(asUInt4);
CreateBlendTreeFromMotion(animationClips, (IMotion)(object)valueOrDefault, blendTreeIndexArray, blendTreeConstantArray);
}
}
else
{
val7["m_StateMachineIndex"].AsUInt = CreateStateMachine((IStateMachine)(object)item.StateMachine, animationClips, val3);
val7["m_StateMachineSynchronizedLayerIndex"].AsUInt = 0u;
}
int num = -1;
if (!string.IsNullOrEmpty(item.PreviousLayerName))
{
uint previousLayerHash = GetOrAddName(item.PreviousLayerName);
num = ((IEnumerable<AssetTypeValueField>)val2).IndexOf((AssetTypeValueField f) => f["data"]["m_Binding"].AsUInt == previousLayerHash);
}
foreach (AssetTypeValueField item3 in val4)
{
AssetTypeValueField val9 = item3["first"]["m_LayerIndex"];
if (val9.AsInt > num)
{
int asInt = val9.AsInt;
val9.AsInt = asInt + 1;
}
}
val2.Children.Insert(num + 1, val6);
}
}
currentModification = null;
}
private void ModifyStateMachine(AssetTypeValueField animationClips, IExistingStateMachine stateMachine, AssetTypeValueField stateMachineField, string stateMachinePath)
{
IExistingStateMachine stateMachine2 = stateMachine;
uint asUInt = stateMachineField["data"]["m_SynchronizedLayerCount"].AsUInt;
AssetTypeValueField statesArray = stateMachineField["data"]["m_StateConstantArray"]["Array"];
AssetTypeValueField anyStateTransitionsArray = stateMachineField["data"]["m_AnyStateTransitionConstantArray"]["Array"];
AssetTypeValueField selectorStatesArray = stateMachineField["data"]["m_SelectorStateConstantArray"]["Array"];
string newStateMachinePath = (string.IsNullOrEmpty(stateMachinePath) ? stateMachine2.Name : (stateMachinePath + "." + stateMachine2.Name));
delayedActions.Add(delegate
{
foreach (ISimpleTransition newEntryTransition in stateMachine2.NewEntryTransitions)
{
CreateSelectorTransition(newStateMachinePath, newEntryTransition, statesArray, selectorStatesArray);
}
foreach (ITransition newAnyStateTransition in stateMachine2.NewAnyStateTransitions)
{
CreateTransition(newStateMachinePath, "AnyState", newAnyStateTransition, anyStateTransitionsArray, statesArray, selectorStatesArray, "Entry");
}
});
foreach (IExistingState state in stateMachine2.States)
{
ModifyState(newStateMachinePath, statesArray, selectorStatesArray, state);
}
foreach (IState newState in stateMachine2.NewStates)
{
CreateState(animationClips, newStateMachinePath, stateMachine2.Name, asUInt, statesArray, selectorStatesArray, newState);
}
foreach (IExistingStateMachine subStateMachine in stateMachine2.SubStateMachines)
{
ModifyStateMachine(animationClips, subStateMachine, stateMachineField, newStateMachinePath);
}
foreach (IStateMachine newSubStateMachine in stateMachine2.NewSubStateMachines)
{
CreateSubStateMachine(newStateMachinePath, newSubStateMachine, stateMachineField, animationClips);
}
}
private void CreateSubStateMachine(string stateMachinePath, IStateMachine stateMachine, AssetTypeValueField stateMachineField, AssetTypeValueField animationClips)
{
IStateMachine stateMachine2 = stateMachine;
string stateMachinePath2 = stateMachinePath;
uint asUInt = stateMachineField["data"]["m_SynchronizedLayerCount"].AsUInt;
AssetTypeValueField statesArray = stateMachineField["data"]["m_StateConstantArray"]["Array"];
AssetTypeValueField anyStateTransitionsArray = stateMachineField["data"]["m_AnyStateTransitionConstantArray"]["Array"];
AssetTypeValueField selectorStatesArray = stateMachineField["data"]["m_SelectorStateConstantArray"]["Array"];
string newStateMachinePath = (string.IsNullOrEmpty(stateMachinePath2) ? stateMachine2.Name : (stateMachinePath2 + "." + stateMachine2.Name));
uint orAddName = GetOrAddName(newStateMachinePath);
CreateSelectorState(orAddName, selectorStatesArray, isEntry: true);
AssetTypeValueField exitSelectorState = CreateSelectorState(orAddName, selectorStatesArray, isEntry: false);
delayedActions.Add(delegate
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
if (string.IsNullOrEmpty(stateMachine2.Name) && string.IsNullOrEmpty(stateMachine2.DefaultStateMachinePath))
{
CreateSelectorTransition(uint.MaxValue, exitSelectorState);
}
else
{
CreateSelectorTransition(newStateMachinePath, (ISimpleTransition)new EntryTransition
{
DestinationStateName = stateMachine2.DefaultStateName,
DestinationStateMachinePath = stateMachine2.DefaultStateMachinePath
}, statesArray, selectorStatesArray);
}
if (string.IsNullOrEmpty(stateMachinePath2))
{
CreateSelectorTransition(30000u, exitSelectorState);
}
else
{
uint orAddName2 = GetOrAddName(stateMachinePath2);
uint destinationState = 30000u;
for (int i = 0; i < selectorStatesArray.Children.Count; i++)
{
AssetTypeValueField val = selectorStatesArray[i]["data"];
if (val["m_FullPathID"].AsUInt == orAddName2 && val["m_IsEntry"].AsBool)
{
destinationState = val["m_TransitionConstantArray"]["Array"][0]["data"]["m_Destination"].AsUInt;
break;
}
}
CreateSelectorTransition(destinationState, exitSelectorState);
}
foreach (ISimpleTransition entryTransition in stateMachine2.EntryTransitions)
{
CreateSelectorTransition(newStateMachinePath, entryTransition, statesArray, selectorStatesArray);
}
foreach (ITransition anyStateTransition in stateMachine2.AnyStateTransitions)
{
CreateTransition(newStateMachinePath, "AnyState", anyStateTransition, anyStateTransitionsArray, statesArray, selectorStatesArray, "Entry");
}
});
foreach (IState state in stateMachine2.States)
{
CreateState(animationClips, newStateMachinePath, stateMachine2.Name, asUInt, statesArray, selectorStatesArray, state);
}
foreach (IStateMachine subStateMachine in stateMachine2.SubStateMachines)
{
CreateSubStateMachine(newStateMachinePath, subStateMachine, stateMachineField, selectorStatesArray);
}
}
private AssetTypeValueField CreateSelectorState(uint stateMachinePathHash, AssetTypeValueField selectorStatesArray, bool isEntry)
{
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(selectorStatesArray.TemplateField.Children[1]);
selectorStatesArray.Children.Add(val);
AssetTypeValueField obj = val["data"];
obj["m_FullPathID"].AsUInt = stateMachinePathHash;
obj["m_IsEntry"].AsBool = isEntry;
return val;
}
private void CreateSelectorTransition(string stateMachinePath, ISimpleTransition entryTransition, AssetTypeValueField statesArray, AssetTypeValueField selectorStatesArray)
{
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected I4, but got Unknown
string text = (string.IsNullOrEmpty(entryTransition.DestinationStateMachinePath) ? stateMachinePath : entryTransition.DestinationStateMachinePath) + "." + entryTransition.DestinationStateName;
uint orAddName = GetOrAddName(text);
uint transitionFullPathHash = GetOrAddName(stateMachinePath);
uint transitionDestinationState = GetTransitionDestinationState(entryTransition.DestinationStateName, statesArray, selectorStatesArray, orAddName);
if (transitionDestinationState == uint.MaxValue)
{
LogError("Destination state by path \"" + text + "\" was not found.");
return;
}
AssetTypeValueField val = ((IEnumerable<AssetTypeValueField>)selectorStatesArray).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField s) => s["data"]["m_FullPathID"].AsUInt == transitionFullPathHash && s["data"]["m_IsEntry"].AsBool));
if (val == null)
{
LogError("StateMachine \"" + stateMachinePath + "\" was not found.");
return;
}
AssetTypeValueField val2 = CreateSelectorTransition(transitionDestinationState, val)["data"]["m_ConditionConstantArray"]["Array"];
foreach (ICondition condition in entryTransition.Conditions)
{
uint orAddName2 = GetOrAddName(condition.ParamName);
AssetTypeValueField val3 = ValueBuilder.DefaultValueFieldFromTemplate(val2.TemplateField.Children[1]);
AssetTypeValueField obj = val3["data"];
obj["m_ConditionMode"].AsUInt = (uint)(int)condition.ConditionMode;
obj["m_EventID"].AsUInt = orAddName2;
obj["m_EventThreshold"].AsFloat = condition.Value;
obj["m_ExitTime"].AsFloat = 0f;
val2.Children.Add(val3);
}
}
private AssetTypeValueField CreateSelectorTransition(uint destinationState, AssetTypeValueField selectorState)
{
AssetTypeValueField obj = selectorState["data"]["m_TransitionConstantArray"]["Array"];
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(obj.TemplateField.Children[1]);
val["data"]["m_Destination"].AsUInt = destinationState;
obj.Children.Add(val);
return val;
}
private void ModifyState(string stateMachinePath, AssetTypeValueField statesArray, AssetTypeValueField selectorStatesArray, IExistingState state)
{
IExistingState state2 = state;
string stateMachinePath2 = stateMachinePath;
AssetTypeValueField statesArray2 = statesArray;
AssetTypeValueField selectorStatesArray2 = selectorStatesArray;
string text = stateMachinePath2 + "." + state2.Name;
uint fullPathID = GetOrAddName(text);
AssetTypeValueField stateField = ((IEnumerable<AssetTypeValueField>)statesArray2).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField s) => s["data"]["m_FullPathID"].AsUInt == fullPathID));
if (stateField == null)
{
LogError("State \"" + text + "\" was not found.");
return;
}
delayedActions.Add(delegate
{
AssetTypeValueField transitions = stateField["data"]["m_TransitionConstantArray"]["Array"];
foreach (ITransition newTransition in state2.NewTransitions)
{
CreateTransition(stateMachinePath2, state2.Name, newTransition, transitions, statesArray2, selectorStatesArray2);
}
});
}
private uint CreateStateMachine(IStateMachine stateMachine, AssetTypeValueField animationClips, AssetTypeValueField stateMachineArray)
{
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(stateMachineArray.TemplateField.Children[1]);
int count = stateMachineArray.Children.Count;
stateMachineArray.Children.Add(val);
AssetTypeValueField val2 = val["data"];
AssetTypeValueField states = val2["m_StateConstantArray"]["Array"];
AssetTypeValueField selectorStates = val2["m_SelectorStateConstantArray"]["Array"];
val2["m_SynchronizedLayerCount"].AsUInt = 1u;
CreateSubStateMachine("", stateMachine, val, animationClips);
if (string.IsNullOrEmpty(stateMachine.DefaultStateName))
{
string name = (string.IsNullOrEmpty(stateMachine.DefaultStateMachinePath) ? stateMachine.Name : stateMachine.DefaultStateMachinePath);
val2["m_DefaultState"].AsUInt = GetTransitionDestinationState(stateMachine.DefaultStateName, states, selectorStates, GetOrAddName(name));
return (uint)count;
}
val2["m_DefaultState"].AsUInt = 0u;
return (uint)count;
}
private void CreateSkeletonMaskFromAvatarMask(AssetTypeValueField skeletonMaskArrayField, AvatarMask avatarMask)
{
if (Object.op_Implicit((Object)(object)avatarMask))
{
int transformCount = avatarMask.transformCount;
for (int i = 0; i < transformCount; i++)
{
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(skeletonMaskArrayField.TemplateField.Children[1]);
skeletonMaskArrayField.Children.Add(val);
val["m_PathHash"].AsUInt = GetOrAddName(avatarMask.GetTransformPath(i));
val["m_Weight"].AsFloat = avatarMask.GetTransformWeight(i);
}
}
}
private void CreateBodyMaskFromAvatarMask(AssetTypeValueField bodyMask, AvatarMask avatarMask)
{
uint num = 0u;
uint num2 = 0u;
uint num3 = 0u;
if (Object.op_Implicit((Object)(object)avatarMask))
{
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)0))
{
num |= 1u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)1))
{
num |= 0x3FEu;
num2 |= 0xC0000000u;
num3 |= 1u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)2))
{
num |= 0x3FFC00u;
num3 |= 6u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)3))
{
num |= 0x3FC00000u;
num3 |= 0x78u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)4))
{
num |= 0xC0000000u;
num2 |= 0x3Fu;
num3 |= 0x780u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)5))
{
num2 |= 0x7FC0u;
num3 |= 0x7800u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)6))
{
num2 |= 0xFF8000u;
num3 |= 0x78000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)7))
{
num2 |= 0x10000000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)8))
{
num2 |= 0x20000000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)9))
{
num2 |= 0x1000000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)10))
{
num2 |= 0x2000000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)11))
{
num2 |= 0x4000000u;
}
if (avatarMask.GetHumanoidBodyPartActive((AvatarMaskBodyPart)12))
{
num2 |= 0x8000000u;
}
}
else
{
num = uint.MaxValue;
num2 = uint.MaxValue;
num3 = 524287u;
}
bodyMask["word0"].Value.AsUInt = num;
bodyMask["word1"].Value.AsUInt = num2;
bodyMask["word2"].Value.AsUInt = num3;
}
private void AddParameters()
{
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Expected I4, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Invalid comparison between Unknown and I4
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Expected I4, but got Unknown
HashSet<uint> hashSet = new HashSet<uint>();
AssetTypeValueField obj = baseField["m_Controller"];
AssetTypeValueField val = obj["m_Values"]["data"]["m_ValueArray"]["Array"];
AssetTypeValueField obj2 = obj["m_DefaultValues"]["data"];
AssetTypeValueField val2 = obj2["m_BoolValues"]["Array"];
AssetTypeValueField val3 = obj2["m_FloatValues"]["Array"];
AssetTypeValueField val4 = obj2["m_IntValues"]["Array"];
foreach (AssetTypeValueField item in val)
{
hashSet.Add(item["m_ID"].AsUInt);
}
foreach (AnimatorModifications modification in modifications)
{
foreach (Parameter newParameter in (currentModification = modification).NewParameters)
{
uint orAddName = GetOrAddName(newParameter.Name);
if (!hashSet.Add(orAddName))
{
LogError("Parameter " + newParameter.Name + " already exists for " + baseField["m_Name"].AsString + ".");
continue;
}
ParameterType type = newParameter.Type;
int count;
switch (type - 1)
{
default:
if ((int)type == 9)
{
goto case 3;
}
goto case 1;
case 0:
{
count = val3.Children.Count;
AssetTypeValueField val6 = ValueBuilder.DefaultValueFieldFromTemplate(val3.TemplateField.Children[1]);
val6.AsFloat = ParameterValue.op_Implicit(newParameter.Value);
val3.Children.Add(val6);
break;
}
case 2:
{
count = val4.Children.Count;
AssetTypeValueField val5 = ValueBuilder.DefaultValueFieldFromTemplate(val4.TemplateField.Children[1]);
val5.AsInt = ParameterValue.op_Implicit(newParameter.Value);
val4.Children.Add(val5);
break;
}
case 3:
{
count = val2.Children.Count;
AssetTypeValueField val7 = ValueBuilder.DefaultValueFieldFromTemplate(val2.TemplateField.Children[1]);
val7.AsBool = ParameterValue.op_Implicit(newParameter.Value);
val2.Children.Add(val7);
break;
}
case 1:
LogError($"Not supported parameter type {newParameter.Type} for parameter \"{newParameter.Name}\".");
continue;
}
AssetTypeValueField val8 = ValueBuilder.DefaultValueFieldFromTemplate(val.TemplateField.Children[1]);
val8["m_ID"].AsUInt = orAddName;
val8["m_Type"].AsUInt = (uint)(int)newParameter.Type;
val8["m_Index"].AsUInt = (uint)count;
val.Children.Add(val8);
}
}
currentModification = null;
}
private void AddStates()
{
AssetTypeValueField animationClips = baseField["m_AnimationClips"]["Array"];
AssetTypeValueField val = baseField["m_Controller"];
string asString = baseField["m_Name"].AsString;
foreach (AnimatorModifications modification in modifications)
{
foreach (KeyValuePair<string, List<State>> newState in (currentModification = modification).NewStates)
{
newState.Deconstruct(out var key, out var value);
string text = key;
List<State> list = value;
uint layerHash = GetOrAddName(text);
AssetTypeValueField val2 = ((IEnumerable<AssetTypeValueField>)val["m_LayerArray"]["Array"]).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField f) => f["data"]["m_Binding"].AsUInt == layerHash));
if (val2 == null)
{
LogError("Layer \"" + text + "\" not found for a controller \"" + asString + "\".");
continue;
}
uint asUInt = val2["data"]["m_StateMachineIndex"].AsUInt;
AssetTypeValueField obj = val["m_StateMachineArray"]["Array"][(int)asUInt];
uint asUInt2 = obj["data"]["m_SynchronizedLayerCount"].AsUInt;
AssetTypeValueField statesArray = obj["data"]["m_StateConstantArray"]["Array"];
AssetTypeValueField selectorStatesArray = obj["data"]["m_SelectorStateConstantArray"]["Array"];
foreach (State item in list)
{
CreateState(animationClips, text, text, asUInt2, statesArray, selectorStatesArray, (IState)(object)item);
}
}
}
currentModification = null;
}
private void CreateState(AssetTypeValueField animationClips, string stateMachinePath, string stateMachineName, uint synchronizedLayerCount, AssetTypeValueField statesArray, AssetTypeValueField selectorStatesArray, IState state)
{
IState state2 = state;
string stateMachinePath2 = stateMachinePath;
AssetTypeValueField statesArray2 = statesArray;
AssetTypeValueField selectorStatesArray2 = selectorStatesArray;
uint orAddName = GetOrAddName(state2.Name);
string name = stateMachineName + "." + state2.Name;
uint orAddName2 = GetOrAddName(name);
string name2 = stateMachinePath2 + "." + state2.Name;
uint orAddName3 = GetOrAddName(name2);
uint orAddName4 = GetOrAddName(state2.Tag);
uint orAddName5 = GetOrAddName(state2.SpeedParam);
uint orAddName6 = GetOrAddName(state2.MirrorParam);
uint orAddName7 = GetOrAddName(state2.CycleOffsetParam);
uint orAddName8 = GetOrAddName(state2.TimeParam);
AssetTypeValueField stateField = ValueBuilder.DefaultValueFieldFromTemplate(statesArray2.TemplateField.Children[1]);
AssetTypeValueField obj = stateField["data"];
obj["m_NameID"].AsUInt = orAddName;
obj["m_PathID"].AsUInt = orAddName2;
obj["m_FullPathID"].AsUInt = orAddName3;
obj["m_TagID"].AsUInt = orAddName4;
obj["m_SpeedParamID"].AsUInt = orAddName5;
obj["m_MirrorParamID"].AsUInt = orAddName6;
obj["m_CycleOffsetParamID"].AsUInt = orAddName7;
obj["m_TimeParamID"].AsUInt = orAddName8;
obj["m_Speed"].AsFloat = state2.Speed;
obj["m_CycleOffset"].AsFloat = state2.CycleOffset;
obj["m_IKOnFeet"].AsBool = state2.IKOnFeet;
obj["m_WriteDefaultValues"].AsBool = state2.WriteDefaultValues;
obj["m_Loop"].AsBool = state2.Loop;
obj["m_Mirror"].AsBool = state2.Mirror;
statesArray2.Children.Add(stateField);
delayedActions.Add(delegate
{
AssetTypeValueField transitions = stateField["data"]["m_TransitionConstantArray"]["Array"];
foreach (ITransition transition in state2.Transitions)
{
CreateTransition(stateMachinePath2, state2.Name, transition, transitions, statesArray2, selectorStatesArray2);
}
});
AssetTypeValueField blendTreeIndexArray = stateField["data"]["m_BlendTreeConstantIndexArray"]["Array"];
AssetTypeValueField blendTreeConstantArray = stateField["data"]["m_BlendTreeConstantArray"]["Array"];
CreateBlendTreeFromMotion(animationClips, (IMotion)(object)state2, blendTreeIndexArray, blendTreeConstantArray);
for (int i = 1; i < synchronizedLayerCount; i++)
{
CreateBlendTreeFromMotion(animationClips, null, blendTreeIndexArray, blendTreeConstantArray);
}
}
private bool TryAddDependency(Object obj, out int fileID, out long pathID)
{
pathID = NativeHelpers.GetAssetPathID(obj);
fileID = 0;
if (pathID == 0L)
{
return false;
}
string pathName = NativeHelpers.GetPathName(obj);
if (string.IsNullOrEmpty(pathName))
{
return false;
}
fileID = dependencies.IndexOf(pathName);
if (fileID == -1)
{
fileID = dependencies.Count;
dependencies.Add(pathName);
}
fileID++;
return true;
}
private void AddTransitions()
{
AssetTypeValueField val = baseField["m_Controller"];
string asString = baseField["m_Name"].AsString;
foreach (AnimatorModifications modification in modifications)
{
foreach (KeyValuePair<(string, string), List<Transition>> newTransition in (currentModification = modification).NewTransitions)
{
newTransition.Deconstruct(out var key, out var value);
(string, string) tuple = key;
string layerName = tuple.Item1;
string stateName = tuple.Item2;
List<Transition> transitions = value;
uint layerHash = GetOrAddName(layerName);
uint stateHash = GetOrAddName(stateName);
AssetTypeValueField val2 = ((IEnumerable<AssetTypeValueField>)val["m_LayerArray"]["Array"]).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField f) => f["data"]["m_Binding"].AsUInt == layerHash));
if (val2 == null)
{
LogError("Layer \"" + layerName + "\" not found for controller " + asString + ".");
continue;
}
uint asUInt = val2["data"]["m_StateMachineIndex"].AsUInt;
AssetTypeValueField val3 = val["m_StateMachineArray"]["Array"][(int)asUInt];
AssetTypeValueField states = val3["data"]["m_StateConstantArray"]["Array"];
AssetTypeValueField selectorStates = val3["data"]["m_SelectorStateConstantArray"]["Array"];
AssetTypeValueField stateField = ((IEnumerable<AssetTypeValueField>)states).FirstOrDefault((Func<AssetTypeValueField, bool>)((AssetTypeValueField f) => f["data"]["m_NameID"].AsUInt == stateHash));
if (stateField == null)
{
LogError("State \"" + stateName + "\" not found for a layer \"" + layerName + "\" for a controller \"" + asString + "\".");
continue;
}
delayedActions.Add(delegate
{
AssetTypeValueField transitions2 = stateField["data"]["m_TransitionConstantArray"]["Array"];
foreach (Transition item in transitions)
{
CreateTransition(layerName, stateName, (ITransition)(object)item, transitions2, states, selectorStates);
}
});
}
}
currentModification = null;
}
private void CreateTransition(string stateMachinePath, string stateName, ITransition transition, AssetTypeValueField transitions, AssetTypeValueField states, AssetTypeValueField selectorStates, string fullPathOverride = null)
{
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Expected I4, but got Unknown
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Expected I4, but got Unknown
string text = fullPathOverride ?? (stateMachinePath + "." + stateName);
string text2 = (string.IsNullOrEmpty(((ISimpleTransition)transition).DestinationStateMachinePath) ? stateMachinePath : ((ISimpleTransition)transition).DestinationStateMachinePath);
string text3 = ((ISimpleTransition)transition).DestinationStateName;
if (string.IsNullOrEmpty(text3))
{
int num = text2.LastIndexOf('.');
if (num == -1)
{
text3 = text2;
}
else
{
string text4 = text2;
int num2 = num + 1;
text3 = text4.Substring(num2, text4.Length - num2);
}
}
string text5 = (string.IsNullOrEmpty(((ISimpleTransition)transition).DestinationStateName) ? text2 : (text2 + "." + ((ISimpleTransition)transition).DestinationStateName));
uint orAddName = GetOrAddName(text5);
uint transitionDestinationState = GetTransitionDestinationState(((ISimpleTransition)transition).DestinationStateName, states, selectorStates, orAddName, transition.IsExit);
if (transitionDestinationState == uint.MaxValue)
{
LogError("Destination state by path \"" + text5 + "\" was not found.");
return;
}
string name = stateName + " -> " + (transition.IsExit ? "Exit" : text3);
uint orAddName2 = GetOrAddName(name);
string name2 = text + " -> " + ((transitionDestinationState >= 30000) ? "Exit" : text5);
uint orAddName3 = GetOrAddName(name2);
AssetTypeValueField val = ValueBuilder.DefaultValueFieldFromTemplate(transitions.TemplateField.Children[1]);
AssetTypeValueField obj = val["data"];
obj["m_DestinationState"].AsUInt = transitionDestinationState;
obj["m_FullPathID"].AsUInt = orAddName3;
obj["m_ID"].AsUInt = orAddName2;
obj["m_UserID"].AsUInt = 0u;
obj["m_TransitionOffset"].AsFloat = transition.Offset;
obj["m_TransitionDuration"].AsFloat = transition.TransitionDuration;
obj["m_HasFixedDuration"].AsBool = transition.HasFixedDuration;
obj["m_HasExitTime"].AsBool = transition.HasExitTime;
obj["m_ExitTime"].AsFloat = transition.ExitTime;
obj["m_InterruptionSource"].AsInt = (int)transition.InterruptionSource;
obj["m_CanTransitionToSelf"].AsBool = transition.CanTransitionToSelf;
obj["m_OrderedInterruption"].AsBool = transition.OrderedInterruption;
transitions.Children.Add(val);
AssetTypeValueField val2 = obj["m_ConditionConstantArray"]["Array"];
foreach (ICondition condition in ((ISimpleTransition)transition).Conditions)
{
uint orAddName4 = GetOrAddName(condition.ParamName);
AssetTypeValueField val3 = ValueBuilder.DefaultValueFieldFromTemplate(val2.TemplateField.Children[1]);
AssetTypeValueField obj2 = val3["data"];
obj2["m_ConditionMode"].AsUInt = (uint)(int)condition.ConditionMode;
obj2["m_EventID"].AsUInt = orAddName4;
obj2["m_EventThreshold"].AsFloat = condition.Value;
obj2["m_ExitTime"].AsFloat = 0f;
val2.Children.Add(val3);
}
}
private static uint GetTransitionDestinationState(string stateName, AssetTypeValueField states, AssetTypeValueField selectorStates, uint stateFullPathHash, bool isExit = false)
{
if (string.IsNullOrEmpty(stateName))
{
for (int i = 0; i < selectorStates.Children.Count; i++)
{
AssetTypeValueField val = selectorStates[i]["data"];
if (val["m_FullPathID"].AsUInt == stateFullPathHash && val["m_IsEntry"].AsBool != isExit)
{
return (uint)(i + 30000);
}
}
}
else
{
for (int j = 0; j < states.Children.Count; j++)
{
if (states[j]["data"]["m_FullPathID"].AsUInt == stateFullPathHash)
{
return (uint)j;
}
}
}
return uint.MaxValue;
}
private void AddTOS()
{
AssetTypeValueField val = baseField["m_TOS"]["Array"];
foreach (string newName in newNames)
{
uint asUInt = nameToHash[newName];
AssetTypeValueField val2 = ValueBuilder.DefaultValueFieldFromTemplate(val.TemplateField.Children[1]);
val2["first"].AsUInt = asUInt;
val2["second"].AsString = newName;
val.Children.Add(val2);
}
}
private void SaveBundle()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
AssetExternal extAsset = manager.GetExtAsset(dummyAssetFile, 0, dummyAnimatorControllerPathID, false, (AssetReadFlags)0);
baseField["m_Name"].AsString = baseField["m_Name"].AsString + " (Modified)";
extAsset.info.SetNewData(baseField);
AssetBundleDirectoryInfo val = dummyBundleFile.file.BlockAndDirInfo.DirectoryInfos[0];
val.SetNewData(dummyAssetFile.file);
val.Name = Path.GetFileNameWithoutExtension(modifiedBundlePath);
AssetExternal extAsset2 = manager.GetExtAsset(dummyAssetFile, 0, 1L, false, (AssetReadFlags)0);
AssetTypeValueField val2 = extAsset2.baseField;
val2["m_Name"].AsString = val.Name;
extAsset2.info.SetNewData(val2);
Directory.CreateDirectory(Path.GetDirectoryName(modifiedBundlePath));
using FileStream fileStream = File.Open(modifiedBundlePath, FileMode.Create, FileAccess.Write);
AssetsFileWriter val3 = new AssetsFileWriter(fileStream);
try
{
dummyBundleFile.file.Write(val3, 0L);
}
finally
{
((IDisposable)val3)?.Dispose();
}
}
private void SetExternals()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
List<AssetsFileExternal> externals = dummyAssetFile.file.Metadata.Externals;
foreach (string dependency in dependencies)
{
externals.Add(new AssetsFileExternal
{
PathName = dependency,
Type = (AssetsFileExternalType)0,
VirtualAssetPathName = ""
});
}
}
private void RemapPPtrs()
{
List<AssetTypeValueField> list = new List<AssetTypeValueField>();
GatherPPtrFileIDFields(baseField, list);
HashSet<int> hashSet = new HashSet<int>();
foreach (AssetTypeValueField item2 in list)
{
hashSet.Add(item2.AsInt);
}
int num = 1;
Dictionary<int, int> dictionary = new Dictionary<int, int>();
foreach (int item3 in hashSet.OrderBy((int d) => d))
{
dictionary[item3] = num++;
if (item3 == 0)
{
string item = "archive:/" + assetFile.name + "/" + assetFile.name;
dependencies.Add(item);
}
else
{
dependencies.Add(assetFile.file.Metadata.Externals[item3 - 1].PathName);
}
}
foreach (AssetTypeValueField item4 in list)
{
item4.AsInt = dictionary[item4.AsInt];
}
}
private void GatherPPtrFileIDFields(AssetTypeValueField field, List<AssetTypeValueField> fields)
{
if (field.TypeName.StartsWith("PPtr<"))
{
AssetTypeValueField item = field["m_FileID"];
fields.Add(item);
return;
}
foreach (AssetTypeValueField child in field.Children)
{
GatherPPtrFileIDFields(child, fields);
}
}
private uint GetOrAddName(string name)
{
if (name == null)
{
return 0u;
}
if (nameToHash.TryGetValue(name, out var value))
{
return value;
}
value = (uint)Animator.StringToHash(name);
newNames.Add(name);
hashToName[value] = name;
nameToHash[name] = value;
return value;
}
private void LogError(string message)
{
if (currentModification != null)
{
AnimationsPlugin.Logger.LogError((object)(message + " | Mod: " + currentModification.Key));
}
else
{
AnimationsPlugin.Logger.LogError((object)message);
}
}
}
internal static class NativeHelpers
{
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private unsafe delegate void InstanceIDToSerializedObjectIdentifierHandler(IntPtr remapper, int instanceID, SerializedObjectIdentifier* identifier);
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private unsafe delegate IntPtr PersistentManagerGetPathNameHandler(PersistentManager* persistentManager, StringStorageDefaultV2* returnString, int instanceID);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void FreeAllocInternalHandler(IntPtr ptr, int label, IntPtr file, int line);
private const int InstanceIDToSerializedObjectIdentifierOffset = 6881312;
private const int PersistentManagerGetPathNameOffset = 6809328;
private const int FreeAllocInternalOffset = 2593600;
private const int PersistentManagerOffset = 28557672;
private static IntPtr PersistentManagerPtr;
private static InstanceIDToSerializedObjectIdentifierHandler InstanceIDToSerializedObjectIdentifier;
private static PersistentManagerGetPathNameHandler PersistentManagerGetPathName;
private static FreeAllocInternalHandler FreeAllocInternal;
private unsafe static PersistentManager* PersistentManager => *(PersistentManager**)PersistentManagerPtr.ToPointer();
public static void Init()
{
IntPtr baseAddress = (Process.GetCurrentProcess().Modules.Cast<ProcessModule>().FirstOrDefault(IsUnityPlayer) ?? Process.GetCurrentProcess().MainModule).BaseAddress;
PersistentManagerPtr = baseAddress + 28557672;
InstanceIDToSerializedObjectIdentifier = Marshal.GetDelegateForFunctionPointer<InstanceIDToSerializedObjectIdentifierHandler>(baseAddress + 6881312);
PersistentManagerGetPathName = Marshal.GetDelegateForFunctionPointer<PersistentManagerGetPathNameHandler>(baseAddress + 6809328);
FreeAllocInternal = Marshal.GetDelegateForFunctionPointer<FreeAllocInternalHandler>(baseAddress + 2593600);
static bool IsUnityPlayer(ProcessModule p)
{
return p.ModuleName.ToLowerInvariant().Contains("unityplayer");
}
}
public static long GetAssetPathID(Object obj)
{
if (!Object.op_Implicit(obj))
{
return 0L;
}
return GetAssetPathID(obj.GetInstanceID());
}
public unsafe static long GetAssetPathID(int instanceID)
{
SerializedObjectIdentifier serializedObjectIdentifier = default(SerializedObjectIdentifier);
IntPtr remapper = PersistentManager->Remapper;
InstanceIDToSerializedObjectIdentifier(remapper, instanceID, &serializedObjectIdentifier);
return serializedObjectIdentifier.pathID;
}
public static string GetPathName(Object obj)
{
if (!Object.op_Implicit(obj))
{
return "";
}
return GetPathName(obj.GetInstanceID());
}
public unsafe static string GetPathName(int instanceID)
{
StringStorageDefaultV2 stringStorageDefaultV = default(StringStorageDefaultV2);
PersistentManagerGetPathName(PersistentManager, &stringStorageDefaultV, instanceID);
if (stringStorageDefaultV.data_repr != StringRepresentation.Embedded && (stringStorageDefaultV.union.heap.data == 0 || stringStorageDefaultV.union.heap.size == 0L))
{
return "";
}
if (stringStorageDefaultV.data_repr == StringRepresentation.Embedded)
{
return Marshal.PtrToStringAnsi((IntPtr)stringStorageDefaultV.union.embedded.data);
}
string text = Marshal.PtrToStringAnsi(stringStorageDefaultV.union.heap.data, (int)stringStorageDefaultV.union.heap.size);
if (text != null)
{
FreeAllocInternal(stringStorageDefaultV.union.heap.data, stringStorageDefaultV.label, IntPtr.Zero, 0);
return text;
}
return "";
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}
namespace R2API.NativeStructs
{
[StructLayout(LayoutKind.Explicit)]
public struct PersistentManager
{
[FieldOffset(88)]
public IntPtr Remapper;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct SerializedObjectIdentifier
{
public int fileID;
public long pathID;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct StringStorageDefaultV2
{
public StringStorageDefaultV2Union union;
public StringRepresentation data_repr;
public int label;
}
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct StringStorageDefaultV2Union
{
[FieldOffset(0)]
public StackAllocatedRepresentationV2 embedded;
[FieldOffset(0)]
public HeapAllocatedRepresentationV2 heap;
}
public struct StackAllocatedRepresentationV2
{
public unsafe fixed byte data[25];
}
public struct HeapAllocatedRepresentationV2
{
public nint data;
public ulong capacity;
public ulong size;
}
public enum StringRepresentation
{
Heap,
Embedded,
External
}
}using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using AssetsTools.NET.Extra;
using AssetsTools.NET.Extra.Decompressors.LZ4;
using LZ4ps;
using SevenZip;
using SevenZip.Compression.LZ;
using SevenZip.Compression.LZMA;
using SevenZip.Compression.RangeCoder;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AssetsTools.NET")]
[assembly: AssemblyDescription("A remake and port of SeriousCache's AssetTools")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("nesrak1")]
[assembly: AssemblyProduct("AssetsTools.NET")]
[assembly: AssemblyCopyright("Written by nes")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e09d5ac2-1a2e-4ec1-94ad-3f5e22f17658")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyVersion("3.0.0.0")]
namespace SevenZip
{
internal class CRC
{
public static readonly uint[] Table;
private uint _value = uint.MaxValue;
static CRC()
{
Table = new uint[256];
for (uint num = 0u; num < 256; num++)
{
uint num2 = num;
for (int i = 0; i < 8; i++)
{
num2 = (((num2 & 1) == 0) ? (num2 >> 1) : ((num2 >> 1) ^ 0xEDB88320u));
}
Table[num] = num2;
}
}
public void Init()
{
_value = uint.MaxValue;
}
public void UpdateByte(byte b)
{
_value = Table[(byte)_value ^ b] ^ (_value >> 8);
}
public void Update(byte[] data, uint offset, uint size)
{
for (uint num = 0u; num < size; num++)
{
_value = Table[(byte)_value ^ data[offset + num]] ^ (_value >> 8);
}
}
public uint GetDigest()
{
return _value ^ 0xFFFFFFFFu;
}
private static uint CalculateDigest(byte[] data, uint offset, uint size)
{
CRC cRC = new CRC();
cRC.Update(data, offset, size);
return cRC.GetDigest();
}
private static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
{
return CalculateDigest(data, offset, size) == digest;
}
}
internal class DataErrorException : ApplicationException
{
public DataErrorException()
: base("Data Error")
{
}
}
internal class InvalidParamException : ApplicationException
{
public InvalidParamException()
: base("Invalid Parameter")
{
}
}
public interface ICodeProgress
{
void SetProgress(long inSize, long outSize);
}
public interface ICoder
{
void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress);
}
public enum CoderPropID
{
DefaultProp,
DictionarySize,
UsedMemorySize,
Order,
BlockSize,
PosStateBits,
LitContextBits,
LitPosBits,
NumFastBytes,
MatchFinder,
MatchFinderCycles,
NumPasses,
Algorithm,
NumThreads,
EndMarker
}
public interface ISetCoderProperties
{
void SetCoderProperties(CoderPropID[] propIDs, object[] properties);
}
public interface IWriteCoderProperties
{
void WriteCoderProperties(Stream outStream);
}
public interface ISetDecoderProperties
{
void SetDecoderProperties(byte[] properties);
}
}
namespace SevenZip.Compression.RangeCoder
{
internal class Encoder
{
public const uint kTopValue = 16777216u;
private Stream Stream;
public ulong Low;
public uint Range;
private uint _cacheSize;
private byte _cache;
private long StartPosition;
public void SetStream(Stream stream)
{
Stream = stream;
}
public void ReleaseStream()
{
Stream = null;
}
public void Init()
{
StartPosition = Stream.Position;
Low = 0uL;
Range = uint.MaxValue;
_cacheSize = 1u;
_cache = 0;
}
public void FlushData()
{
for (int i = 0; i < 5; i++)
{
ShiftLow();
}
}
public void FlushStream()
{
Stream.Flush();
}
public void CloseStream()
{
Stream.Close();
}
public void Encode(uint start, uint size, uint total)
{
Low += start * (Range /= total);
Range *= size;
while (Range < 16777216)
{
Range <<= 8;
ShiftLow();
}
}
public void ShiftLow()
{
if ((uint)Low < 4278190080u || (int)(Low >> 32) == 1)
{
byte b = _cache;
do
{
Stream.WriteByte((byte)(b + (Low >> 32)));
b = byte.MaxValue;
}
while (--_cacheSize != 0);
_cache = (byte)((uint)Low >> 24);
}
_cacheSize++;
Low = (uint)((int)Low << 8);
}
public void EncodeDirectBits(uint v, int numTotalBits)
{
for (int num = numTotalBits - 1; num >= 0; num--)
{
Range >>= 1;
if (((v >> num) & 1) == 1)
{
Low += Range;
}
if (Range < 16777216)
{
Range <<= 8;
ShiftLow();
}
}
}
public void EncodeBit(uint size0, int numTotalBits, uint symbol)
{
uint num = (Range >> numTotalBits) * size0;
if (symbol == 0)
{
Range = num;
}
else
{
Low += num;
Range -= num;
}
while (Range < 16777216)
{
Range <<= 8;
ShiftLow();
}
}
public long GetProcessedSizeAdd()
{
return _cacheSize + Stream.Position - StartPosition + 4;
}
}
internal class Decoder
{
public const uint kTopValue = 16777216u;
public uint Range;
public uint Code;
public Stream Stream;
public void Init(Stream stream)
{
Stream = stream;
Code = 0u;
Range = uint.MaxValue;
for (int i = 0; i < 5; i++)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
}
}
public void ReleaseStream()
{
Stream = null;
}
public void CloseStream()
{
Stream.Close();
}
public void Normalize()
{
while (Range < 16777216)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
Range <<= 8;
}
}
public void Normalize2()
{
if (Range < 16777216)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
Range <<= 8;
}
}
public uint GetThreshold(uint total)
{
return Code / (Range /= total);
}
public void Decode(uint start, uint size, uint total)
{
Code -= start * Range;
Range *= size;
Normalize();
}
public uint DecodeDirectBits(int numTotalBits)
{
uint num = Range;
uint num2 = Code;
uint num3 = 0u;
for (int num4 = numTotalBits; num4 > 0; num4--)
{
num >>= 1;
uint num5 = num2 - num >> 31;
num2 -= num & (num5 - 1);
num3 = (num3 << 1) | (1 - num5);
if (num < 16777216)
{
num2 = (num2 << 8) | (byte)Stream.ReadByte();
num <<= 8;
}
}
Range = num;
Code = num2;
return num3;
}
public uint DecodeBit(uint size0, int numTotalBits)
{
uint num = (Range >> numTotalBits) * size0;
uint result;
if (Code < num)
{
result = 0u;
Range = num;
}
else
{
result = 1u;
Code -= num;
Range -= num;
}
Normalize();
return result;
}
}
internal struct BitEncoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = 2048u;
private const int kNumMoveBits = 5;
private const int kNumMoveReducingBits = 2;
public const int kNumBitPriceShiftBits = 6;
private uint Prob;
private static uint[] ProbPrices;
public void Init()
{
Prob = 1024u;
}
public void UpdateModel(uint symbol)
{
if (symbol == 0)
{
Prob += 2048 - Prob >> 5;
}
else
{
Prob -= Prob >> 5;
}
}
public void Encode(Encoder encoder, uint symbol)
{
uint num = (encoder.Range >> 11) * Prob;
if (symbol == 0)
{
encoder.Range = num;
Prob += 2048 - Prob >> 5;
}
else
{
encoder.Low += num;
encoder.Range -= num;
Prob -= Prob >> 5;
}
if (encoder.Range < 16777216)
{
encoder.Range <<= 8;
encoder.ShiftLow();
}
}
static BitEncoder()
{
ProbPrices = new uint[512];
for (int num = 8; num >= 0; num--)
{
int num2 = 1 << 9 - num - 1;
uint num3 = (uint)(1 << 9 - num);
for (uint num4 = (uint)num2; num4 < num3; num4++)
{
ProbPrices[num4] = (uint)(num << 6) + (num3 - num4 << 6 >> 9 - num - 1);
}
}
}
public uint GetPrice(uint symbol)
{
return ProbPrices[(((Prob - symbol) ^ (int)(0 - symbol)) & 0x7FF) >> 2];
}
public uint GetPrice0()
{
return ProbPrices[Prob >> 2];
}
public uint GetPrice1()
{
return ProbPrices[2048 - Prob >> 2];
}
}
internal struct BitDecoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = 2048u;
private const int kNumMoveBits = 5;
private uint Prob;
public void UpdateModel(int numMoveBits, uint symbol)
{
if (symbol == 0)
{
Prob += 2048 - Prob >> numMoveBits;
}
else
{
Prob -= Prob >> numMoveBits;
}
}
public void Init()
{
Prob = 1024u;
}
public uint Decode(Decoder rangeDecoder)
{
uint num = (rangeDecoder.Range >> 11) * Prob;
if (rangeDecoder.Code < num)
{
rangeDecoder.Range = num;
Prob += 2048 - Prob >> 5;
if (rangeDecoder.Range < 16777216)
{
rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();
rangeDecoder.Range <<= 8;
}
return 0u;
}
rangeDecoder.Range -= num;
rangeDecoder.Code -= num;
Prob -= Prob >> 5;
if (rangeDecoder.Range < 16777216)
{
rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();
rangeDecoder.Range <<= 8;
}
return 1u;
}
}
internal struct BitTreeEncoder
{
private BitEncoder[] Models;
private int NumBitLevels;
public BitTreeEncoder(int numBitLevels)
{
NumBitLevels = numBitLevels;
Models = new BitEncoder[1 << numBitLevels];
}
public void Init()
{
for (uint num = 1u; num < 1 << NumBitLevels; num++)
{
Models[num].Init();
}
}
public void Encode(Encoder rangeEncoder, uint symbol)
{
uint num = 1u;
int num2 = NumBitLevels;
while (num2 > 0)
{
num2--;
uint num3 = (symbol >> num2) & 1u;
Models[num].Encode(rangeEncoder, num3);
num = (num << 1) | num3;
}
}
public void ReverseEncode(Encoder rangeEncoder, uint symbol)
{
uint num = 1u;
for (uint num2 = 0u; num2 < NumBitLevels; num2++)
{
uint num3 = symbol & 1u;
Models[num].Encode(rangeEncoder, num3);
num = (num << 1) | num3;
symbol >>= 1;
}
}
public uint GetPrice(uint symbol)
{
uint num = 0u;
uint num2 = 1u;
int num3 = NumBitLevels;
while (num3 > 0)
{
num3--;
uint num4 = (symbol >> num3) & 1u;
num += Models[num2].GetPrice(num4);
num2 = (num2 << 1) + num4;
}
return num;
}
public uint ReverseGetPrice(uint symbol)
{
uint num = 0u;
uint num2 = 1u;
for (int num3 = NumBitLevels; num3 > 0; num3--)
{
uint num4 = symbol & 1u;
symbol >>= 1;
num += Models[num2].GetPrice(num4);
num2 = (num2 << 1) | num4;
}
return num;
}
public static uint ReverseGetPrice(BitEncoder[] Models, uint startIndex, int NumBitLevels, uint symbol)
{
uint num = 0u;
uint num2 = 1u;
for (int num3 = NumBitLevels; num3 > 0; num3--)
{
uint num4 = symbol & 1u;
symbol >>= 1;
num += Models[startIndex + num2].GetPrice(num4);
num2 = (num2 << 1) | num4;
}
return num;
}
public static void ReverseEncode(BitEncoder[] Models, uint startIndex, Encoder rangeEncoder, int NumBitLevels, uint symbol)
{
uint num = 1u;
for (int i = 0; i < NumBitLevels; i++)
{
uint num2 = symbol & 1u;
Models[startIndex + num].Encode(rangeEncoder, num2);
num = (num << 1) | num2;
symbol >>= 1;
}
}
}
internal struct BitTreeDecoder
{
private BitDecoder[] Models;
private int NumBitLevels;
public BitTreeDecoder(int numBitLevels)
{
NumBitLevels = numBitLevels;
Models = new BitDecoder[1 << numBitLevels];
}
public void Init()
{
for (uint num = 1u; num < 1 << NumBitLevels; num++)
{
Models[num].Init();
}
}
public uint Decode(Decoder rangeDecoder)
{
uint num = 1u;
for (int num2 = NumBitLevels; num2 > 0; num2--)
{
num = (num << 1) + Models[num].Decode(rangeDecoder);
}
return num - (uint)(1 << NumBitLevels);
}
public uint ReverseDecode(Decoder rangeDecoder)
{
uint num = 1u;
uint num2 = 0u;
for (int i = 0; i < NumBitLevels; i++)
{
uint num3 = Models[num].Decode(rangeDecoder);
num <<= 1;
num += num3;
num2 |= num3 << i;
}
return num2;
}
public static uint ReverseDecode(BitDecoder[] Models, uint startIndex, Decoder rangeDecoder, int NumBitLevels)
{
uint num = 1u;
uint num2 = 0u;
for (int i = 0; i < NumBitLevels; i++)
{
uint num3 = Models[startIndex + num].Decode(rangeDecoder);
num <<= 1;
num += num3;
num2 |= num3 << i;
}
return num2;
}
}
}
namespace SevenZip.Compression.LZ
{
internal interface IInWindowStream
{
void SetStream(Stream inStream);
void Init();
void ReleaseStream();
byte GetIndexByte(int index);
uint GetMatchLen(int index, uint distance, uint limit);
uint GetNumAvailableBytes();
}
internal interface IMatchFinder : IInWindowStream
{
void Create(uint historySize, uint keepAddBufferBefore, uint matchMaxLen, uint keepAddBufferAfter);
uint GetMatches(uint[] distances);
void Skip(uint num);
}
public class BinTree : InWindow, IMatchFinder, IInWindowStream
{
private uint _cyclicBufferPos;
private uint _cyclicBufferSize;
private uint _matchMaxLen;
private uint[] _son;
private uint[] _hash;
private uint _cutValue = 255u;
private uint _hashMask;
private uint _hashSizeSum;
private bool HASH_ARRAY = true;
private const uint kHash2Size = 1024u;
private const uint kHash3Size = 65536u;
private const uint kBT2HashSize = 65536u;
private const uint kStartMaxLen = 1u;
private const uint kHash3Offset = 1024u;
private const uint kEmptyHashValue = 0u;
private const uint kMaxValForNormalize = 2147483647u;
private uint kNumHashDirectBytes;
private uint kMinMatchCheck = 4u;
private uint kFixHashSize = 66560u;
public void SetType(int numHashBytes)
{
HASH_ARRAY = numHashBytes > 2;
if (HASH_ARRAY)
{
kNumHashDirectBytes = 0u;
kMinMatchCheck = 4u;
kFixHashSize = 66560u;
}
else
{
kNumHashDirectBytes = 2u;
kMinMatchCheck = 3u;
kFixHashSize = 0u;
}
}
public new void SetStream(Stream stream)
{
base.SetStream(stream);
}
public new void ReleaseStream()
{
base.ReleaseStream();
}
public new void Init()
{
base.Init();
for (uint num = 0u; num < _hashSizeSum; num++)
{
_hash[num] = 0u;
}
_cyclicBufferPos = 0u;
ReduceOffsets(-1);
}
public new void MovePos()
{
if (++_cyclicBufferPos >= _cyclicBufferSize)
{
_cyclicBufferPos = 0u;
}
base.MovePos();
if (_pos == int.MaxValue)
{
Normalize();
}
}
public new byte GetIndexByte(int index)
{
return base.GetIndexByte(index);
}
public new uint GetMatchLen(int index, uint distance, uint limit)
{
return base.GetMatchLen(index, distance, limit);
}
public new uint GetNumAvailableBytes()
{
return base.GetNumAvailableBytes();
}
public void Create(uint historySize, uint keepAddBufferBefore, uint matchMaxLen, uint keepAddBufferAfter)
{
if (historySize > 2147483391)
{
throw new Exception();
}
_cutValue = 16 + (matchMaxLen >> 1);
uint keepSizeReserv = (historySize + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + 256;
Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, keepSizeReserv);
_matchMaxLen = matchMaxLen;
uint num = historySize + 1;
if (_cyclicBufferSize != num)
{
_son = new uint[(_cyclicBufferSize = num) * 2];
}
uint num2 = 65536u;
if (HASH_ARRAY)
{
num2 = historySize - 1;
num2 |= num2 >> 1;
num2 |= num2 >> 2;
num2 |= num2 >> 4;
num2 |= num2 >> 8;
num2 >>= 1;
num2 |= 0xFFFFu;
if (num2 > 16777216)
{
num2 >>= 1;
}
_hashMask = num2;
num2++;
num2 += kFixHashSize;
}
if (num2 != _hashSizeSum)
{
_hash = new uint[_hashSizeSum = num2];
}
}
public uint GetMatches(uint[] distances)
{
uint num;
if (_pos + _matchMaxLen <= _streamPos)
{
num = _matchMaxLen;
}
else
{
num = _streamPos - _pos;
if (num < kMinMatchCheck)
{
MovePos();
return 0u;
}
}
uint num2 = 0u;
uint num3 = ((_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0u);
uint num4 = _bufferOffset + _pos;
uint num5 = 1u;
uint num6 = 0u;
uint num7 = 0u;
uint num10;
if (HASH_ARRAY)
{
uint num8 = CRC.Table[_bufferBase[num4]] ^ _bufferBase[num4 + 1];
num6 = num8 & 0x3FFu;
int num9 = (int)num8 ^ (_bufferBase[num4 + 2] << 8);
num7 = (uint)num9 & 0xFFFFu;
num10 = ((uint)num9 ^ (CRC.Table[_bufferBase[num4 + 3]] << 5)) & _hashMask;
}
else
{
num10 = (uint)(_bufferBase[num4] ^ (_bufferBase[num4 + 1] << 8));
}
uint num11 = _hash[kFixHashSize + num10];
if (HASH_ARRAY)
{
uint num12 = _hash[num6];
uint num13 = _hash[1024 + num7];
_hash[num6] = _pos;
_hash[1024 + num7] = _pos;
if (num12 > num3 && _bufferBase[_bufferOffset + num12] == _bufferBase[num4])
{
num5 = (distances[num2++] = 2u);
distances[num2++] = _pos - num12 - 1;
}
if (num13 > num3 && _bufferBase[_bufferOffset + num13] == _bufferBase[num4])
{
if (num13 == num12)
{
num2 -= 2;
}
num5 = (distances[num2++] = 3u);
distances[num2++] = _pos - num13 - 1;
num12 = num13;
}
if (num2 != 0 && num12 == num11)
{
num2 -= 2;
num5 = 1u;
}
}
_hash[kFixHashSize + num10] = _pos;
uint num14 = (_cyclicBufferPos << 1) + 1;
uint num15 = _cyclicBufferPos << 1;
uint val;
uint val2 = (val = kNumHashDirectBytes);
if (kNumHashDirectBytes != 0 && num11 > num3 && _bufferBase[_bufferOffset + num11 + kNumHashDirectBytes] != _bufferBase[num4 + kNumHashDirectBytes])
{
num5 = (distances[num2++] = kNumHashDirectBytes);
distances[num2++] = _pos - num11 - 1;
}
uint cutValue = _cutValue;
while (true)
{
if (num11 <= num3 || cutValue-- == 0)
{
_son[num14] = (_son[num15] = 0u);
break;
}
uint num16 = _pos - num11;
uint num17 = ((num16 <= _cyclicBufferPos) ? (_cyclicBufferPos - num16) : (_cyclicBufferPos - num16 + _cyclicBufferSize)) << 1;
uint num18 = _bufferOffset + num11;
uint num19 = Math.Min(val2, val);
if (_bufferBase[num18 + num19] == _bufferBase[num4 + num19])
{
while (++num19 != num && _bufferBase[num18 + num19] == _bufferBase[num4 + num19])
{
}
if (num5 < num19)
{
num5 = (distances[num2++] = num19);
distances[num2++] = num16 - 1;
if (num19 == num)
{
_son[num15] = _son[num17];
_son[num14] = _son[num17 + 1];
break;
}
}
}
if (_bufferBase[num18 + num19] < _bufferBase[num4 + num19])
{
_son[num15] = num11;
num15 = num17 + 1;
num11 = _son[num15];
val = num19;
}
else
{
_son[num14] = num11;
num14 = num17;
num11 = _son[num14];
val2 = num19;
}
}
MovePos();
return num2;
}
public void Skip(uint num)
{
do
{
uint num2;
if (_pos + _matchMaxLen <= _streamPos)
{
num2 = _matchMaxLen;
}
else
{
num2 = _streamPos - _pos;
if (num2 < kMinMatchCheck)
{
MovePos();
continue;
}
}
uint num3 = ((_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0u);
uint num4 = _bufferOffset + _pos;
uint num9;
if (HASH_ARRAY)
{
uint num5 = CRC.Table[_bufferBase[num4]] ^ _bufferBase[num4 + 1];
uint num6 = num5 & 0x3FFu;
_hash[num6] = _pos;
int num7 = (int)num5 ^ (_bufferBase[num4 + 2] << 8);
uint num8 = (uint)num7 & 0xFFFFu;
_hash[1024 + num8] = _pos;
num9 = ((uint)num7 ^ (CRC.Table[_bufferBase[num4 + 3]] << 5)) & _hashMask;
}
else
{
num9 = (uint)(_bufferBase[num4] ^ (_bufferBase[num4 + 1] << 8));
}
uint num10 = _hash[kFixHashSize + num9];
_hash[kFixHashSize + num9] = _pos;
uint num11 = (_cyclicBufferPos << 1) + 1;
uint num12 = _cyclicBufferPos << 1;
uint val;
uint val2 = (val = kNumHashDirectBytes);
uint cutValue = _cutValue;
while (true)
{
if (num10 <= num3 || cutValue-- == 0)
{
_son[num11] = (_son[num12] = 0u);
break;
}
uint num13 = _pos - num10;
uint num14 = ((num13 <= _cyclicBufferPos) ? (_cyclicBufferPos - num13) : (_cyclicBufferPos - num13 + _cyclicBufferSize)) << 1;
uint num15 = _bufferOffset + num10;
uint num16 = Math.Min(val2, val);
if (_bufferBase[num15 + num16] == _bufferBase[num4 + num16])
{
while (++num16 != num2 && _bufferBase[num15 + num16] == _bufferBase[num4 + num16])
{
}
if (num16 == num2)
{
_son[num12] = _son[num14];
_son[num11] = _son[num14 + 1];
break;
}
}
if (_bufferBase[num15 + num16] < _bufferBase[num4 + num16])
{
_son[num12] = num10;
num12 = num14 + 1;
num10 = _son[num12];
val = num16;
}
else
{
_son[num11] = num10;
num11 = num14;
num10 = _son[num11];
val2 = num16;
}
}
MovePos();
}
while (--num != 0);
}
private void NormalizeLinks(uint[] items, uint numItems, uint subValue)
{
for (uint num = 0u; num < numItems; num++)
{
uint num2 = items[num];
num2 = ((num2 > subValue) ? (num2 - subValue) : 0u);
items[num] = num2;
}
}
private void Normalize()
{
uint subValue = _pos - _cyclicBufferSize;
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue);
NormalizeLinks(_hash, _hashSizeSum, subValue);
ReduceOffsets((int)subValue);
}
public void SetCutValue(uint cutValue)
{
_cutValue = cutValue;
}
}
public class InWindow
{
public byte[] _bufferBase;
private Stream _stream;
private uint _posLimit;
private bool _streamEndWasReached;
private uint _pointerToLastSafePosition;
public uint _bufferOffset;
public uint _blockSize;
public uint _pos;
private uint _keepSizeBefore;
private uint _keepSizeAfter;
public uint _streamPos;
public void MoveBlock()
{
uint num = _bufferOffset + _pos - _keepSizeBefore;
if (num != 0)
{
num--;
}
uint num2 = _bufferOffset + _streamPos - num;
for (uint num3 = 0u; num3 < num2; num3++)
{
_bufferBase[num3] = _bufferBase[num + num3];
}
_bufferOffset -= num;
}
public virtual void ReadBlock()
{
if (_streamEndWasReached)
{
return;
}
while (true)
{
int num = (int)(0 - _bufferOffset + _blockSize - _streamPos);
if (num == 0)
{
return;
}
int num2 = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), num);
if (num2 == 0)
{
break;
}
_streamPos += (uint)num2;
if (_streamPos >= _pos + _keepSizeAfter)
{
_posLimit = _streamPos - _keepSizeAfter;
}
}
_posLimit = _streamPos;
if (_bufferOffset + _posLimit > _pointerToLastSafePosition)
{
_posLimit = _pointerToLastSafePosition - _bufferOffset;
}
_streamEndWasReached = true;
}
private void Free()
{
_bufferBase = null;
}
public void Create(uint keepSizeBefore, uint keepSizeAfter, uint keepSizeReserv)
{
_keepSizeBefore = keepSizeBefore;
_keepSizeAfter = keepSizeAfter;
uint num = keepSizeBefore + keepSizeAfter + keepSizeReserv;
if (_bufferBase == null || _blockSize != num)
{
Free();
_blockSize = num;
_bufferBase = new byte[_blockSize];
}
_pointerToLastSafePosition = _blockSize - keepSizeAfter;
}
public void SetStream(Stream stream)
{
_stream = stream;
}
public void ReleaseStream()
{
_stream = null;
}
public void Init()
{
_bufferOffset = 0u;
_pos = 0u;
_streamPos = 0u;
_streamEndWasReached = false;
ReadBlock();
}
public void MovePos()
{
_pos++;
if (_pos > _posLimit)
{
if (_bufferOffset + _pos > _pointerToLastSafePosition)
{
MoveBlock();
}
ReadBlock();
}
}
public byte GetIndexByte(int index)
{
return _bufferBase[_bufferOffset + _pos + index];
}
public uint GetMatchLen(int index, uint distance, uint limit)
{
if (_streamEndWasReached && _pos + index + limit > _streamPos)
{
limit = _streamPos - (uint)(int)(_pos + index);
}
distance++;
uint num = _bufferOffset + _pos + (uint)index;
uint num2;
for (num2 = 0u; num2 < limit && _bufferBase[num + num2] == _bufferBase[num + num2 - distance]; num2++)
{
}
return num2;
}
public uint GetNumAvailableBytes()
{
return _streamPos - _pos;
}
public void ReduceOffsets(int subValue)
{
_bufferOffset += (uint)subValue;
_posLimit -= (uint)subValue;
_pos -= (uint)subValue;
_streamPos -= (uint)subValue;
}
}
public class OutWindow
{
private byte[] _buffer;
private uint _pos;
private uint _windowSize;
private uint _streamPos;
private Stream _stream;
public uint TrainSize;
public void Create(uint windowSize)
{
if (_windowSize != windowSize)
{
_buffer = new byte[windowSize];
}
_windowSize = windowSize;
_pos = 0u;
_streamPos = 0u;
}
public void Init(Stream stream, bool solid)
{
ReleaseStream();
_stream = stream;
if (!solid)
{
_streamPos = 0u;
_pos = 0u;
TrainSize = 0u;
}
}
public bool Train(Stream stream)
{
long length = stream.Length;
uint num = (TrainSize = (uint)((length < _windowSize) ? length : _windowSize));
stream.Position = length - num;
_streamPos = (_pos = 0u);
while (num != 0)
{
uint num2 = _windowSize - _pos;
if (num < num2)
{
num2 = num;
}
int num3 = stream.Read(_buffer, (int)_pos, (int)num2);
if (num3 == 0)
{
return false;
}
num -= (uint)num3;
_pos += (uint)num3;
_streamPos += (uint)num3;
if (_pos == _windowSize)
{
_streamPos = (_pos = 0u);
}
}
return true;
}
public void ReleaseStream()
{
Flush();
_stream = null;
}
public void Flush()
{
uint num = _pos - _streamPos;
if (num != 0)
{
_stream.Write(_buffer, (int)_streamPos, (int)num);
if (_pos >= _windowSize)
{
_pos = 0u;
}
_streamPos = _pos;
}
}
public void CopyBlock(uint distance, uint len)
{
uint num = _pos - distance - 1;
if (num >= _windowSize)
{
num += _windowSize;
}
while (len != 0)
{
if (num >= _windowSize)
{
num = 0u;
}
_buffer[_pos++] = _buffer[num++];
if (_pos >= _windowSize)
{
Flush();
}
len--;
}
}
public void PutByte(byte b)
{
_buffer[_pos++] = b;
if (_pos >= _windowSize)
{
Flush();
}
}
public byte GetByte(uint distance)
{
uint num = _pos - distance - 1;
if (num >= _windowSize)
{
num += _windowSize;
}
return _buffer[num];
}
}
}
namespace SevenZip.Compression.LZMA
{
internal abstract class Base
{
public struct State
{
public uint Index;
public void Init()
{
Index = 0u;
}
public void UpdateChar()
{
if (Index < 4)
{
Index = 0u;
}
else if (Index < 10)
{
Index -= 3u;
}
else
{
Index -= 6u;
}
}
public void UpdateMatch()
{
Index = ((Index < 7) ? 7u : 10u);
}
public void UpdateRep()
{
Index = ((Index < 7) ? 8u : 11u);
}
public void UpdateShortRep()
{
Index = ((Index < 7) ? 9u : 11u);
}
public bool IsCharState()
{
return Index < 7;
}
}
public const uint kNumRepDistances = 4u;
public const uint kNumStates = 12u;
public const int kNumPosSlotBits = 6;
public const int kDicLogSizeMin = 0;
public const int kNumLenToPosStatesBits = 2;
public const uint kNumLenToPosStates = 4u;
public const uint kMatchMinLen = 2u;
public const int kNumAlignBits = 4;
public const uint kAlignTableSize = 16u;
public const uint kAlignMask = 15u;
public const uint kStartPosModelIndex = 4u;
public const uint kEndPosModelIndex = 14u;
public const uint kNumPosModels = 10u;
public const uint kNumFullDistances = 128u;
public const uint kNumLitPosStatesBitsEncodingMax = 4u;
public const uint kNumLitContextBitsMax = 8u;
public const int kNumPosStatesBitsMax = 4;
public const uint kNumPosStatesMax = 16u;
public const int kNumPosStatesBitsEncodingMax = 4;
public const uint kNumPosStatesEncodingMax = 16u;
public const int kNumLowLenBits = 3;
public const int kNumMidLenBits = 3;
public const int kNumHighLenBits = 8;
public const uint kNumLowLenSymbols = 8u;
public const uint kNumMidLenSymbols = 8u;
public const uint kNumLenSymbols = 272u;
public const uint kMatchMaxLen = 273u;
public static uint GetLenToPosState(uint len)
{
len -= 2;
if (len < 4)
{
return len;
}
return 3u;
}
}
public class Decoder : ICoder, ISetDecoderProperties
{
private class LenDecoder
{
private BitDecoder m_Choice;
private BitDecoder m_Choice2;
private BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[16];
private BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[16];
private BitTreeDecoder m_HighCoder = new BitTreeDecoder(8);
private uint m_NumPosStates;
public void Create(uint numPosStates)
{
for (uint num = m_NumPosStates; num < numPosStates; num++)
{
m_LowCoder[num] = new BitTreeDecoder(3);
m_MidCoder[num] = new BitTreeDecoder(3);
}
m_NumPosStates = numPosStates;
}
public void Init()
{
m_Choice.Init();
for (uint num = 0u; num < m_NumPosStates; num++)
{
m_LowCoder[num].Init();
m_MidCoder[num].Init();
}
m_Choice2.Init();
m_HighCoder.Init();
}
public uint Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, uint posState)
{
if (m_Choice.Decode(rangeDecoder) == 0)
{
return m_LowCoder[posState].Decode(rangeDecoder);
}
uint num = 8u;
if (m_Choice2.Decode(rangeDecoder) == 0)
{
return num + m_MidCoder[posState].Decode(rangeDecoder);
}
num += 8;
return num + m_HighCoder.Decode(rangeDecoder);
}
}
private class LiteralDecoder
{
private struct Decoder2
{
private BitDecoder[] m_Decoders;
public void Create()
{
m_Decoders = new BitDecoder[768];
}
public void Init()
{
for (int i = 0; i < 768; i++)
{
m_Decoders[i].Init();
}
}
public byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder)
{
uint num = 1u;
do
{
num = (num << 1) | m_Decoders[num].Decode(rangeDecoder);
}
while (num < 256);
return (byte)num;
}
public byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte)
{
uint num = 1u;
do
{
uint num2 = (uint)(matchByte >> 7) & 1u;
matchByte <<= 1;
uint num3 = m_Decoders[(1 + num2 << 8) + num].Decode(rangeDecoder);
num = (num << 1) | num3;
if (num2 != num3)
{
while (num < 256)
{
num = (num << 1) | m_Decoders[num].Decode(rangeDecoder);
}
break;
}
}
while (num < 256);
return (byte)num;
}
}
private Decoder2[] m_Coders;
private int m_NumPrevBits;
private int m_NumPosBits;
private uint m_PosMask;
public void Create(int numPosBits, int numPrevBits)
{
if (m_Coders == null || m_NumPrevBits != numPrevBits || m_NumPosBits != numPosBits)
{
m_NumPosBits = numPosBits;
m_PosMask = (uint)((1 << numPosBits) - 1);
m_NumPrevBits = numPrevBits;
uint num = (uint)(1 << m_NumPrevBits + m_NumPosBits);
m_Coders = new Decoder2[num];
for (uint num2 = 0u; num2 < num; num2++)
{
m_Coders[num2].Create();
}
}
}
public void Init()
{
uint num = (uint)(1 << m_NumPrevBits + m_NumPosBits);
for (uint num2 = 0u; num2 < num; num2++)
{
m_Coders[num2].Init();
}
}
private uint GetState(uint pos, byte prevByte)
{
return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> 8 - m_NumPrevBits);
}
public byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)
{
return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
}
public byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)
{
return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
}
}
private OutWindow m_OutWindow = new OutWindow();
private SevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();
private BitDecoder[] m_IsMatchDecoders = new BitDecoder[192];
private BitDecoder[] m_IsRepDecoders = new BitDecoder[12];
private BitDecoder[] m_IsRepG0Decoders = new BitDecoder[12];
private BitDecoder[] m_IsRepG1Decoders = new BitDecoder[12];
private BitDecoder[] m_IsRepG2Decoders = new BitDecoder[12];
private BitDecoder[] m_IsRep0LongDecoders = new BitDecoder[192];
private BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[4];
private BitDecoder[] m_PosDecoders = new BitDecoder[114];
private BitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(4);
private LenDecoder m_LenDecoder = new LenDecoder();
private LenDecoder m_RepLenDecoder = new LenDecoder();
private LiteralDecoder m_LiteralDecoder = new LiteralDecoder();
private uint m_DictionarySize;
private uint m_DictionarySizeCheck;
private uint m_PosStateMask;
private bool _solid;
public Decoder()
{
m_DictionarySize = uint.MaxValue;
for (int i = 0; (long)i < 4L; i++)
{
m_PosSlotDecoder[i] = new BitTreeDecoder(6);
}
}
private void SetDictionarySize(uint dictionarySize)
{
if (m_DictionarySize != dictionarySize)
{
m_DictionarySize = dictionarySize;
m_DictionarySizeCheck = Math.Max(m_DictionarySize, 1u);
uint windowSize = Math.Max(m_DictionarySizeCheck, 4096u);
m_OutWindow.Create(windowSize);
}
}
private void SetLiteralProperties(int lp, int lc)
{
if (lp > 8)
{
throw new InvalidParamException();
}
if (lc > 8)
{
throw new InvalidParamException();
}
m_LiteralDecoder.Create(lp, lc);
}
private void SetPosBitsProperties(int pb)
{
if (pb > 4)
{
throw new InvalidParamException();
}
uint num = (uint)(1 << pb);
m_LenDecoder.Create(num);
m_RepLenDecoder.Create(num);
m_PosStateMask = num - 1;
}
private void Init(Stream inStream, Stream outStream)
{
m_RangeDecoder.Init(inStream);
m_OutWindow.Init(outStream, _solid);
for (uint num = 0u; num < 12; num++)
{
for (uint num2 = 0u; num2 <= m_PosStateMask; num2++)
{
uint num3 = (num << 4) + num2;
m_IsMatchDecoders[num3].Init();
m_IsRep0LongDecoders[num3].Init();
}
m_IsRepDecoders[num].Init();
m_IsRepG0Decoders[num].Init();
m_IsRepG1Decoders[num].Init();
m_IsRepG2Decoders[num].Init();
}
m_LiteralDecoder.Init();
for (uint num = 0u; num < 4; num++)
{
m_PosSlotDecoder[num].Init();
}
for (uint num = 0u; num < 114; num++)
{
m_PosDecoders[num].Init();
}
m_LenDecoder.Init();
m_RepLenDecoder.Init();
m_PosAlignDecoder.Init();
}
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress)
{
Init(inStream, outStream);
Base.State state = default(Base.State);
state.Init();
uint num = 0u;
uint num2 = 0u;
uint num3 = 0u;
uint num4 = 0u;
ulong num5 = 0uL;
if (num5 < (ulong)outSize)
{
if (m_IsMatchDecoders[state.Index << 4].Decode(m_RangeDecoder) != 0)
{
throw new DataErrorException();
}
state.UpdateChar();
byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0u, 0);
m_OutWindow.PutByte(b);
num5++;
}
while (num5 < (ulong)outSize)
{
uint num6 = (uint)(int)num5 & m_PosStateMask;
if (m_IsMatchDecoders[(state.Index << 4) + num6].Decode(m_RangeDecoder) == 0)
{
byte @byte = m_OutWindow.GetByte(0u);
byte b2 = (state.IsCharState() ? m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)num5, @byte) : m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)num5, @byte, m_OutWindow.GetByte(num)));
m_OutWindow.PutByte(b2);
state.UpdateChar();
num5++;
continue;
}
uint num8;
if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)
{
if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)
{
if (m_IsRep0LongDecoders[(state.Index << 4) + num6].Decode(m_RangeDecoder) == 0)
{
state.UpdateShortRep();
m_OutWindow.PutByte(m_OutWindow.GetByte(num));
num5++;
continue;
}
}
else
{
uint num7;
if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)
{
num7 = num2;
}
else
{
if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)
{
num7 = num3;
}
else
{
num7 = num4;
num4 = num3;
}
num3 = num2;
}
num2 = num;
num = num7;
}
num8 = m_RepLenDecoder.Decode(m_RangeDecoder, num6) + 2;
state.UpdateRep();
}
else
{
num4 = num3;
num3 = num2;
num2 = num;
num8 = 2 + m_LenDecoder.Decode(m_RangeDecoder, num6);
state.UpdateMatch();
uint num9 = m_PosSlotDecoder[Base.GetLenToPosState(num8)].Decode(m_RangeDecoder);
if (num9 >= 4)
{
int num10 = (int)((num9 >> 1) - 1);
num = (2 | (num9 & 1)) << num10;
if (num9 < 14)
{
num += BitTreeDecoder.ReverseDecode(m_PosDecoders, num - num9 - 1, m_RangeDecoder, num10);
}
else
{
num += m_RangeDecoder.DecodeDirectBits(num10 - 4) << 4;
num += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);
}
}
else
{
num = num9;
}
}
if (num >= m_OutWindow.TrainSize + num5 || num >= m_DictionarySizeCheck)
{
if (num == uint.MaxValue)
{
break;
}
throw new DataErrorException();
}
m_OutWindow.CopyBlock(num, num8);
num5 += num8;
}
m_OutWindow.Flush();
m_OutWindow.ReleaseStream();
m_RangeDecoder.ReleaseStream();
}
public void SetDecoderProperties(byte[] properties)
{
if (properties.Length < 5)
{
throw new InvalidParamException();
}
int lc = properties[0] % 9;
int num = properties[0] / 9;
int lp = num % 5;
int num2 = num / 5;
if (num2 > 4)
{
throw new InvalidParamException();
}
uint num3 = 0u;
for (int i = 0; i < 4; i++)
{
num3 += (uint)(properties[1 + i] << i * 8);
}
SetDictionarySize(num3);
SetLiteralProperties(lp, lc);
SetPosBitsProperties(num2);
}
public bool Train(Stream stream)
{
_solid = true;
return m_OutWindow.Train(stream);
}
}
public class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties
{
private enum EMatchFinderType
{
BT2,
BT4
}
private class LiteralEncoder
{
public struct Encoder2
{
private BitEncoder[] m_Encoders;
public void Create()
{
m_Encoders = new BitEncoder[768];
}
public void Init()
{
for (int i = 0; i < 768; i++)
{
m_Encoders[i].Init();
}
}
public void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol)
{
uint num = 1u;
for (int num2 = 7; num2 >= 0; num2--)
{
uint num3 = (uint)(symbol >> num2) & 1u;
m_Encoders[num].Encode(rangeEncoder, num3);
num = (num << 1) | num3;
}
}
public void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)
{
uint num = 1u;
bool flag = true;
for (int num2 = 7; num2 >= 0; num2--)
{
uint num3 = (uint)(symbol >> num2) & 1u;
uint num4 = num;
if (flag)
{
uint num5 = (uint)(matchByte >> num2) & 1u;
num4 += 1 + num5 << 8;
flag = num5 == num3;
}
m_Encoders[num4].Encode(rangeEncoder, num3);
num = (num << 1) | num3;
}
}
public uint GetPrice(bool matchMode, byte matchByte, byte symbol)
{
uint num = 0u;
uint num2 = 1u;
int num3 = 7;
if (matchMode)
{
while (num3 >= 0)
{
uint num4 = (uint)(matchByte >> num3) & 1u;
uint num5 = (uint)(symbol >> num3) & 1u;
num += m_Encoders[(1 + num4 << 8) + num2].GetPrice(num5);
num2 = (num2 << 1) | num5;
if (num4 != num5)
{
num3--;
break;
}
num3--;
}
}
while (num3 >= 0)
{
uint num6 = (uint)(symbol >> num3) & 1u;
num += m_Encoders[num2].GetPrice(num6);
num2 = (num2 << 1) | num6;
num3--;
}
return num;
}
}
private Encoder2[] m_Coders;
private int m_NumPrevBits;
private int m_NumPosBits;
private uint m_PosMask;
public void Create(int numPosBits, int numPrevBits)
{
if (m_Coders == null || m_NumPrevBits != numPrevBits || m_NumPosBits != numPosBits)
{
m_NumPosBits = numPosBits;
m_PosMask = (uint)((1 << numPosBits) - 1);
m_NumPrevBits = numPrevBits;
uint num = (uint)(1 << m_NumPrevBits + m_NumPosBits);
m_Coders = new Encoder2[num];
for (uint num2 = 0u; num2 < num; num2++)
{
m_Coders[num2].Create();
}
}
}
public void Init()
{
uint num = (uint)(1 << m_NumPrevBits + m_NumPosBits);
for (uint num2 = 0u; num2 < num; num2++)
{
m_Coders[num2].Init();
}
}
public Encoder2 GetSubCoder(uint pos, byte prevByte)
{
return m_Coders[(int)((pos & m_PosMask) << m_NumPrevBits) + (prevByte >> 8 - m_NumPrevBits)];
}
}
private class LenEncoder
{
private BitEncoder _choice;
private BitEncoder _choice2;
private BitTreeEncoder[] _lowCoder = new BitTreeEncoder[16];
private BitTreeEncoder[] _midCoder = new BitTreeEncoder[16];
private BitTreeEncoder _highCoder = new BitTreeEncoder(8);
public LenEncoder()
{
for (uint num = 0u; num < 16; num++)
{
_lowCoder[num] = new BitTreeEncoder(3);
_midCoder[num] = new BitTreeEncoder(3);
}
}
public void Init(uint numPosStates)
{
_choice.Init();
_choice2.Init();
for (uint num = 0u; num < numPosStates; num++)
{
_lowCoder[num].Init();
_midCoder[num].Init();
}
_highCoder.Init();
}
public void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, uint symbol, uint posState)
{
if (symbol < 8)
{
_choice.Encode(rangeEncoder, 0u);
_lowCoder[posState].Encode(rangeEncoder, symbol);
return;
}
symbol -= 8;
_choice.Encode(rangeEncoder, 1u);
if (symbol < 8)
{
_choice2.Encode(rangeEncoder, 0u);
_midCoder[posState].Encode(rangeEncoder, symbol);
}
else
{
_choice2.Encode(rangeEncoder, 1u);
_highCoder.Encode(rangeEncoder, symbol - 8);
}
}
public void SetPrices(uint posState, uint numSymbols, uint[] prices, uint st)
{
uint price = _choice.GetPrice0();
uint price2 = _choice.GetPrice1();
uint num = price2 + _choice2.GetPrice0();
uint num2 = price2 + _choice2.GetPrice1();
uint num3 = 0u;
for (num3 = 0u; num3 < 8; num3++)
{
if (num3 >= numSymbols)
{
return;
}
prices[st + num3] = price + _lowCoder[posState].GetPrice(num3);
}
for (; num3 < 16; num3++)
{
if (num3 >= numSymbols)
{
return;
}
prices[st + num3] = num + _midCoder[posState].GetPrice(num3 - 8);
}
for (; num3 < numSymbols; num3++)
{
prices[st + num3] = num2 + _highCoder.GetPrice(num3 - 8 - 8);
}
}
}
private class LenPriceTableEncoder : LenEncoder
{
private uint[] _prices = new uint[4352];
private uint _tableSize;
private uint[] _counters = new uint[16];
public void SetTableSize(uint tableSize)
{
_tableSize = tableSize;
}
public uint GetPrice(uint symbol, uint posState)
{
return _prices[posState * 272 + symbol];
}
private void UpdateTable(uint posState)
{
SetPrices(posState, _tableSize, _prices, posState * 272);
_counters[posState] = _tableSize;
}
public void UpdateTables(uint numPosStates)
{
for (uint num = 0u; num < numPosStates; num++)
{
UpdateTable(num);
}
}
public new void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, uint symbol, uint posState)
{
base.Encode(rangeEncoder, symbol, posState);
if (--_counters[posState] == 0)
{
UpdateTable(posState);
}
}
}
private class Optimal
{
public Base.State State;
public bool Prev1IsChar;
public bool Prev2;
public uint PosPrev2;
public uint BackPrev2;
public uint Price;
public uint PosPrev;
public uint BackPrev;
public uint Backs0;
public uint Backs1;
public uint Backs2;
public uint Backs3;
public void MakeAsChar()
{
BackPrev = uint.MaxValue;
Prev1IsChar = false;
}
public void MakeAsShortRep()
{
BackPrev = 0u;
Prev1IsChar = false;
}
public bool IsShortRep()
{
return BackPrev == 0;
}
}
private const uint kIfinityPrice = 268435455u;
private static byte[] g_FastPos;
private Base.State _state;
private byte _previousByte;
private uint[] _repDistances = new uint[4];
private const int kDefaultDictionaryLogSize = 22;
private const uint kNumFastBytesDefault = 32u;
private const uint kNumLenSpecSymbols = 16u;
private const uint kNumOpts = 4096u;
private Optimal[] _optimum = new Optimal[4096];
private IMatchFinder _matchFinder;
private SevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();
private BitEncoder[] _isMatch = new BitEncoder[192];
private BitEncoder[] _isRep = new BitEncoder[12];
private BitEncoder[] _isRepG0 = new BitEncoder[12];
private BitEncoder[] _isRepG1 = new BitEncoder[12];
private BitEncoder[] _isRepG2 = new BitEncoder[12];
private BitEncoder[] _isRep0Long = new BitEncoder[192];
private BitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[4];
private BitEncoder[] _posEncoders = new BitEncoder[114];
private BitTreeEncoder _posAlignEncoder = new BitTreeEncoder(4);
private LenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();
private LenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();
private LiteralEncoder _literalEncoder = new LiteralEncoder();
private uint[] _matchDistances = new uint[548];
private uint _numFastBytes = 32u;
private uint _longestMatchLength;
private uint _numDistancePairs;
private uint _additionalOffset;
private uint _optimumEndIndex;
private uint _optimumCurrentIndex;
private bool _longestMatchWasFound;
private uint[] _posSlotPrices = new uint[256];
private uint[] _distancesPrices = new uint[512];
private uint[] _alignPrices = new uint[16];
private uint _alignPriceCount;
private uint _distTableSize = 44u;
private int _posStateBits = 2;
private uint _posStateMask = 3u;
private int _numLiteralPosStateBits;
private int _numLiteralContextBits = 3;
private uint _dictionarySize = 4194304u;
private uint _dictionarySizePrev = uint.MaxValue;
private uint _numFastBytesPrev = uint.MaxValue;
private long nowPos64;
private bool _finished;
private Stream _inStream;
private EMatchFinderType _matchFinderType = EMatchFinderType.BT4;
private bool _writeEndMark;
private bool _needReleaseMFStream;
private uint[] reps = new uint[4];
private uint[] repLens = new uint[4];
private const int kPropSize = 5;
private byte[] properties = new byte[5];
private uint[] tempPrices = new uint[128];
private uint _matchPriceCount;
private static string[] kMatchFinderIDs;
private uint _trainSize;
static Encoder()
{
g_FastPos = new byte[2048];
kMatchFinderIDs = new string[2] { "BT2", "BT4" };
int num = 2;
g_FastPos[0] = 0;
g_FastPos[1] = 1;
for (byte b = 2; b < 22; b++)
{
uint num2 = (uint)(1 << (b >> 1) - 1);
uint num3 = 0u;
while (num3 < num2)
{
g_FastPos[num] = b;
num3++;
num++;
}
}
}
private static uint GetPosSlot(uint pos)
{
if (pos < 2048)
{
return g_FastPos[pos];
}
if (pos < 2097152)
{
return (uint)(g_FastPos[pos >> 10] + 20);
}
return (uint)(g_FastPos[pos >> 20] + 40);
}
private static uint GetPosSlot2(uint pos)
{
if (pos < 131072)
{
return (uint)(g_FastPos[pos >> 6] + 12);
}
if (pos < 134217728)
{
return (uint)(g_FastPos[pos >> 16] + 32);
}
return (uint)(g_FastPos[pos >> 26] + 52);
}
private void BaseInit()
{
_state.Init();
_previousByte = 0;
for (uint num = 0u; num < 4; num++)
{
_repDistances[num] = 0u;
}
}
private void Create()
{
if (_matchFinder == null)
{
BinTree binTree = new BinTree();
int type = 4;
if (_matchFinderType == EMatchFinderType.BT2)
{
type = 2;
}
binTree.SetType(type);
_matchFinder = binTree;
}
_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);
if (_dictionarySize != _dictionarySizePrev || _numFastBytesPrev != _numFastBytes)
{
_matchFinder.Create(_dictionarySize, 4096u, _numFastBytes, 274u);
_dictionarySizePrev = _dictionarySize;
_numFastBytesPrev = _numFastBytes;
}
}
public Encoder()
{
for (int i = 0; (long)i < 4096L; i++)
{
_optimum[i] = new Optimal();
}
for (int j = 0; (long)j < 4L; j++)
{
_posSlotEncoder[j] = new BitTreeEncoder(6);
}
}
private void SetWriteEndMarkerMode(bool writeEndMarker)
{
_writeEndMark = writeEndMarker;
}
private void Init()
{
BaseInit();
_rangeEncoder.Init();
for (uint num = 0u; num < 12; num++)
{
for (uint num2 = 0u; num2 <= _posStateMask; num2++)
{
uint num3 = (num << 4) + num2;
_isMatch[num3].Init();
_isRep0Long[num3].Init();
}
_isRep[num].Init();
_isRepG0[num].Init();
_isRepG1[num].Init();
_isRepG2[num].Init();
}
_literalEncoder.Init();
for (uint num = 0u; num < 4; num++)
{
_posSlotEncoder[num].Init();
}
for (uint num = 0u; num < 114; num++)
{
_posEncoders[num].Init();
}
_lenEncoder.Init((uint)(1 << _posStateBits));
_repMatchLenEncoder.Init((uint)(1 << _posStateBits));
_posAlignEncoder.Init();
_longestMatchWasFound = false;
_optimumEndIndex = 0u;
_optimumCurrentIndex = 0u;
_additionalOffset = 0u;
}
private void ReadMatchDistances(out uint lenRes, out uint numDistancePairs)
{
lenRes = 0u;
numDistancePairs = _matchFinder.GetMatches(_matchDistances);
if (numDistancePairs != 0)
{
lenRes = _matchDistances[numDistancePairs - 2];
if (lenRes == _numFastBytes)
{
lenRes += _matchFinder.GetMatchLen((int)(lenRes - 1), _matchDistances[numDistancePairs - 1], 273 - lenRes);
}
}
_additionalOffset++;
}
private void MovePos(uint num)
{
if (num != 0)
{
_matchFinder.Skip(num);
_additionalOffset += num;
}
}
private uint GetRepLen1Price(Base.State state, uint posState)
{
return _isRepG0[state.Index].GetPrice0() + _isRep0Long[(state.Index << 4) + posState].GetPrice0();
}
private uint GetPureRepPrice(uint repIndex, Base.State state, uint posState)
{
uint price;
if (repIndex == 0)
{
price = _isRepG0[state.Index].GetPrice0();
return price + _isRep0Long[(state.Index << 4) + posState].GetPrice1();
}
price = _isRepG0[state.Index].GetPrice1();
if (repIndex == 1)
{
return price + _isRepG1[state.Index].GetPrice0();
}
price += _isRepG1[state.Index].GetPrice1();
return price + _isRepG2[state.Index].GetPrice(repIndex - 2);
}
private uint GetRepPrice(uint repIndex, uint len, Base.State state, uint posState)
{
return _repMatchLenEncoder.GetPrice(len - 2, posState) + GetPureRepPrice(repIndex, state, posState);
}
private uint GetPosLenPrice(uint pos, uint len, uint posState)
{
uint lenToPosState = Base.GetLenToPosState(len);
uint num = ((pos >= 128) ? (_posSlotPrices[(lenToPosState << 6) + GetPosSlot2(pos)] + _alignPrices[pos & 0xF]) : _distancesPrices[lenToPosState * 128 + pos]);
return num + _lenEncoder.GetPrice(len - 2, posState);
}
private uint Backward(out uint backRes, uint cur)
{
_optimumEndIndex = cur;
uint posPrev = _optimum[cur].PosPrev;
uint backPrev = _optimum[cur].BackPrev;
do
{
if (_optimum[cur].Prev1IsChar)
{
_optimum[posPrev].MakeAsChar();
_optimum[posPrev].PosPrev = posPrev - 1;
if (_optimum[cur].Prev2)
{
_optimum[posPrev - 1].Prev1IsChar = false;
_optimum[posPrev - 1].PosPrev = _optimum[cur].PosPrev2;
_optimum[posPrev - 1].BackPrev = _optimum[cur].BackPrev2;
}
}
uint num = posPrev;
uint backPrev2 = backPrev;
backPrev = _optimum[num].BackPrev;
posPrev = _optimum[num].PosPrev;
_optimum[num].BackPrev = backPrev2;
_optimum[num].PosPrev = cur;
cur = num;
}
while (cur != 0);
backRes = _optimum[0].BackPrev;
_optimumCurrentIndex = _optimum[0].PosPrev;
return _optimumCurrentIndex;
}
private uint GetOptimum(uint position, out uint backRes)
{
if (_optimumEndIndex != _optimumCurrentIndex)
{
uint result = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;
backRes = _optimum[_optimumCurrentIndex].BackPrev;
_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;
return result;
}
_optimumCurrentIndex = (_optimumEndIndex = 0u);
uint lenRes;
uint numDistancePairs;
if (!_longestMatchWasFound)
{
ReadMatchDistances(out lenRes, out numDistancePairs);
}
else
{
lenRes = _longestMatchLength;
numDistancePairs = _numDistancePairs;
_longestMatchWasFound = false;
}
uint num = _matchFinder.GetNumAvailableBytes() + 1;
if (num < 2)
{
backRes = uint.MaxValue;
return 1u;
}
if (num > 273)
{
num = 273u;
}
uint num2 = 0u;
for (uint num3 = 0u; num3 < 4; num3++)
{
reps[num3] = _repDistances[num3];
repLens[num3] = _matchFinder.GetMatchLen(-1, reps[num3], 273u);
if (repLens[num3] > repLens[num2])
{
num2 = num3;
}
}
if (repLens[num2] >= _numFastBytes)
{
backRes = num2;
uint num4 = repLens[num2];
MovePos(num4 - 1);
return num4;
}
if (lenRes >= _numFastBytes)
{
backRes = _matchDistances[numDistancePairs - 1] + 4;
MovePos(lenRes - 1);
return lenRes;
}
byte indexByte = _matchFinder.GetIndexByte(-1);
byte indexByte2 = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - 1));
if (lenRes < 2 && indexByte != indexByte2 && repLens[num2] < 2)
{
backRes = uint.MaxValue;
return 1u;
}
_optimum[0].State = _state;
uint num5 = position & _posStateMask;
_optimum[1].Price = _isMatch[(_state.Index << 4) + num5].GetPrice0() + _literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), indexByte2, indexByte);
_optimum[1].MakeAsChar();
uint price = _isMatch[(_state.Index << 4) + num5].GetPrice1();
uint num6 = price + _isRep[_state.Index].GetPrice1();
if (indexByte2 == indexByte)
{
uint num7 = num6 + GetRepLen1Price(_state, num5);
if (num7 < _optimum[1].Price)
{
_optimum[1].Price = num7;
_optimum[1].MakeAsShortRep();
}
}
uint num8 = ((lenRes >= repLens[num2]) ? lenRes : repLens[num2]);
if (num8 < 2)
{
backRes = _optimum[1].BackPrev;
return 1u;
}
_optimum[1].PosPrev = 0u;
_optimum[0].Backs0 = reps[0];
_optimum[0].Backs1 = reps[1];
_optimum[0].Backs2 = reps[2];
_optimum[0].Backs3 = reps[3];
uint num9 = num8;
do
{
_optimum[num9--].Price = 268435455u;
}
while (num9 >= 2);
for (uint num3 = 0u; num3 < 4; num3++)
{
uint num10 = repLens[num3];
if (num10 < 2)
{
continue;
}
uint num11 = num6 + GetPureRepPrice(num3, _state, num5);
do
{
uint num12 = num11 + _repMatchLenEncoder.GetPrice(num10 - 2, num5);
Optimal optimal = _optimum[num10];
if (num12 < optimal.Price)
{
optimal.Price = num12;
optimal.PosPrev = 0u;
optimal.BackPrev = num3;
optimal.Prev1IsChar = false;
}
}
while (--num10 >= 2);
}
uint num13 = price + _isRep[_state.Index].GetPrice0();
num9 = ((repLens[0] >= 2) ? (repLens[0] + 1) : 2u);
if (num9 <= lenRes)
{
uint num14;
for (num14 = 0u; num9 > _matchDistances[num14]; num14 += 2)
{
}
while (true)
{
uint num15 = _matchDistances[num14 + 1];
uint num16 = num13 + GetPosLenPrice(num15, num9, num5);
Optimal optimal2 = _optimum[num9];
if (num16 < optimal2.Price)
{
optimal2.Price = num16;
optimal2.PosPrev = 0u;
optimal2.BackPrev = num15 + 4;
optimal2.Prev1IsChar = false;
}
if (num9 == _matchDistances[num14])
{
num14 += 2;
if (num14 == numDistancePairs)
{
break;
}
}
num9++;
}
}
uint num17 = 0u;
uint lenRes2;
while (true)
{
num17++;
if (num17 == num8)
{
return Backward(out backRes, num17);
}
ReadMatchDistances(out lenRes2, out numDistancePairs);
if (lenRes2 >= _numFastBytes)
{
break;
}
position++;
uint num18 = _optimum[num17].PosPrev;
Base.State state;
if (_optimum[num17].Prev1IsChar)
{
num18--;
if (_optimum[num17].Prev2)
{
state = _optimum[_optimum[num17].PosPrev2].State;
if (_optimum[num17].BackPrev2 < 4)
{
state.UpdateRep();
}
else
{
state.UpdateMatch();
}
}
else
{
state = _optimum[num18].State;
}
state.UpdateChar();
}
else
{
state = _optimum[num18].State;
}
if (num18 == num17 - 1)
{
if (_optimum[num17].IsShortRep())
{
state.UpdateShortRep();
}
else
{
state.UpdateChar();
}
}
else
{
uint num19;
if (_optimum[num17].Prev1IsChar && _optimum[num17].Prev2)
{
num18 = _optimum[num17].PosPrev2;
num19 = _optimum[num17].BackPrev2;
state.UpdateRep();
}
else
{
num19 = _optimum[num17].BackPrev;
if (num19 < 4)
{
state.UpdateRep();
}
else
{
state.UpdateMatch();
}
}
Optimal optimal3 = _optimum[num18];
switch (num19)
{
case 0u:
reps[0] = optimal3.Backs0;
reps[1] = optimal3.Backs1;
reps[2] = optimal3.Backs2;
reps[3] = optimal3.Backs3;
break;
case 1u:
reps[0] = optimal3.Backs1;
reps[1] = optimal3.Backs0;
reps[2] = optimal3.Backs2;
reps[3] = optimal3.Backs3;
break;
case 2u:
reps[0] = optimal3.Backs2;
reps[1] = optimal3.Backs0;
reps[2] = optimal3.Backs1;
reps[3] = optimal3.Backs3;
break;
case 3u:
reps[0] = optimal3.Backs3;
reps[1] = optimal3.Backs0;
reps[2] = optimal3.Backs1;
reps[3] = optimal3.Backs2;
break;
default:
reps[0] = num19 - 4;
reps[1] = optimal3.Backs0;
reps[2] = optimal3.Backs1;
reps[3] = optimal3.Backs2;
break;
}
}
_optimum[num17].State = state;
_optimum[num17].Backs0 = reps[0];
_optimum[num17].Backs1 = reps[1];
_optimum[num17].Backs2 = reps[2];
_optimum[num17].Backs3 = reps[3];
uint price2 = _optimum[num17].Price;
indexByte = _matchFinder.GetIndexByte(-1);
indexByte2 = _matchFinder.GetIndexByte((int)(0 - reps[0] - 1 - 1));
num5 = position & _posStateMask;
uint num20 = price2 + _isMatch[(state.Index << 4) + num5].GetPrice0() + _literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(-2)).GetPrice(!state.IsCharState(), indexByte2, indexByte);
Optimal optimal4 = _optimum[num17 + 1];
bool flag = false;
if (num20 < optimal4.Price)
{
optimal4.Price = num20;
optimal4.PosPrev = num17;
optimal4.MakeAsChar();
flag = true;
}
price = price2 + _isMatch[(state.Index << 4) + num5].GetPrice1();
num6 = price + _isRep[state.Index].GetPrice1();
if (indexByte2 == indexByte && (optimal4.PosPrev >= num17 || optimal4.BackPrev != 0))
{
uint num21 = num6 + GetRepLen1Price(state, num5);
if (num21 <= optimal4.Price)
{
optimal4.Price = num21;
optimal4.PosPrev = num17;
optimal4.MakeAsShortRep();
flag = true;
}
}
uint val = _matchFinder.GetNumAvailableBytes() + 1;
val = Math.Min(4095 - num17, val);
num = val;
if (num < 2)
{
continue;
}
if (num > _numFastBytes)
{
num = _numFastBytes;
}
if (!flag && indexByte2 != indexByte)
{
uint limit = Math.Min(val - 1, _numFastBytes);
uint matchLen = _matchFinder.GetMatchLen(0, reps[0], limit);
if (matchLen >= 2)
{
Base.State state2 = state;
state2.UpdateChar();
uint num22 = (position + 1) & _posStateMask;
uint num23 = num20 + _isMatch[(state2.Index << 4) + num22].GetPrice1() + _isRep[state2.Index].GetPrice1();
uint num24 = num17 + 1 + matchLen;
while (num8 < num24)
{
_optimum[++num8].Price = 268435455u;
}
uint num25 = num23 + GetRepPrice(0u, matchLen, state2, num22);
Optimal optimal5 = _optimum[num24];
if (num25 < optimal5.Price)
{
optimal5.Price = num25;
optimal5.PosPrev = num17 + 1;
optimal5.BackPrev = 0u;
optimal5.Prev1IsChar = true;
optimal5.Prev2 = false;
}
}
}
uint num26 = 2u;
for (uint num27 = 0u; num27 < 4; num27++)
{
uint num28 = _matchFinder.GetMatchLen(-1, reps[num27], num);
if (num28 < 2)
{
continue;
}
uint num29 = num28;
while (true)
{
if (num8 < num17 + num28)
{
_optimum[++num8].Price = 268435455u;
continue;
}
uint num30 = num6 + GetRepPrice(num27, num28, state, num5);
Optimal optimal6 = _optimum[num17 + num28];
if (num30 < optimal6.Price)
{
optimal6.Price = num30;
optimal6.PosPrev = num17;
optimal6.BackPrev = num27;
optimal6.Prev1IsChar = false;
}
if (--num28 < 2)
{
break;
}
}
num28 = num29;
if (num27 == 0)
{
num26 = num28 + 1;
}
if (num28 >= val)
{
continue;
}
uint limit2 = Math.Min(val - 1 - num28, _numFastBytes);
uint matchLen2 = _matchFinder.GetMatchLen((int)num28, reps[num27], limit2);
if (matchLen2 >= 2)
{
Base.State state3 = state;
state3.UpdateRep();
uint num31 = (position + num28) & _posStateMask;
uint num32 = num6 + GetRepPrice(num27, num28, state, num5) + _isMatch[(state3.Index << 4) + num31].GetPrice0() + _literalEncoder.GetSubCoder(position + num28, _matchFinder.GetIndexByte((int)(num28 - 1 - 1))).GetPrice(matchMode: true, _matchFinder.GetIndexByte((int)(num28 - 1 - (reps[num27] + 1))), _matchFinder.GetIndexByte((int)(num28 - 1)));
state3.UpdateChar();
num31 = (position + num28 + 1) & _posStateMask;
uint num33 = num32 + _isMatch[(state3.Index << 4) + num31].GetPrice1() + _isRep[state3.Index].GetPrice1();
uint num34 = num28 + 1 + matchLen2;
while (num8 < num17 + num34)
{
_optimum[++num8].Price = 268435455u;
}
uint num35 = num33 + GetRepPrice(0u, matchLen2, state3, num31);
Optimal optimal7 = _optimum[num17 + num34];
if (num35 < optimal7.Price)
{
optimal7.Price = num35;
optimal7.PosPrev = num17 + num28 + 1;
optimal7.BackPrev = 0u;
optimal7.Prev1IsChar = true;
optimal7.Prev2 = true;
optimal7.PosPrev2 = num17;
optimal7.BackPrev2 = num27;
}
}
}
if (lenRes2 > num)
{
lenRes2 = num;
for (numDistancePairs = 0u; lenRes2 > _matchDistances[numDistancePairs]; numDistancePairs += 2)
{
}
_matchDistances[numDistancePairs] = lenRes2;
numDistancePairs += 2;
}
if (lenRes2 < num26)
{
continue;
}
num13 = price + _isRep[state.Index].GetPrice0();
while (num8 < num17 + lenRes2)
{
_optimum[++num8].Price = 268435455u;
}
uint num36;
for (num36 = 0u; num26 > _matchDistances[num36]; num36 += 2)
{
}
uint num37 = num26;
while (true)
{
uint num38 = _matchDistances[num36 + 1];
uint num39 = num13 + GetPosLenPrice(num38, num37, num5);
Optimal optimal8 = _optimum[num17 + num37];
if (num39 < optimal8.Price)
{
optimal8.Price = num39;
optimal8.PosPrev = num17;
optimal8.BackPrev = num38 + 4;
optimal8.Prev1IsChar = false;
}
if (num37 == _matchDistances[num36])
{
if (num37 < val)
{
uint limit3 = Math.Min(val - 1 - num37, _numFastBytes);
uint matchLen3 = _matchFinder.GetMatchLen((int)num37, num38, limit3);
if (matchLen3 >= 2)
{
Base.State state4 = state;
state4.UpdateMatch();
uint num40 = (position + num37) & _posStateMask;
uint num41 = num39 + _isMatch[(state4.Index << 4) + num40].GetPrice0() + _literalEncoder.GetSubCoder(position + num37, _matchFinder.GetIndexByte((int)(num37 - 1 - 1))).GetPrice(matchMode: true, _matchFinder.GetIndexByte((int)(num37 - (num38 + 1) - 1)), _matchFinder.GetIndexByte((int)(num37 - 1)));
state4.UpdateChar();
num40 = (position + num37 + 1) & _posStateMask;
uint num42 = num41 + _isMatch[(state4.Index << 4) + num40].GetPrice1() + _isRep[state4.Index].GetPrice1();
uint num43 = num37 + 1 + matchLen3;
while (num8 < num17 + num43)
{
_optimum[++num8].Price = 268435455u;
}
num39 = num42 + GetRepPrice(0u, matchLen3, state4, num40);
optimal8 = _optimum[num17 + num43];
if (num39 < optimal8.Price)
{
optimal8.Price = num39;
optimal8.PosPrev = num17 + num37 + 1;
optimal8.BackPrev = 0u;
optimal8.Prev1IsChar = true;
optimal8.Prev2 = true;
optimal8.PosPrev2 = num17;
optimal8.BackPrev2 = num38 + 4;
}
}
}
num36 += 2;
if (num36 == numDistancePairs)
{
break;
}
}
num37++;
}
}
_numDistancePairs = numDistancePairs;
_longestMatchLength = lenRes2;
_longestMatchWasFound = true;
return Backward(out backRes, num17);
}
private bool ChangePair(uint smallDist, uint bigDist)
{
if (smallDist < 33554432)
{
return bigDist >= smallDist << 7;
}
return false;
}
private void WriteEndMarker(uint posState)
{
if (_writeEndMark)
{
_isMatch[(_state.Index << 4) + posState].Encode(_rangeEncoder, 1u);
_isRep[_state.Index].Encode(_rangeEncoder, 0u);
_state.UpdateMatch();
uint num = 2u;
_lenEncoder.Encode(_rangeEncoder, num - 2, posState);
uint symbol = 63u;
uint lenToPosState = Base.GetLenToPosState(num);
_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, symbol);
int num2 = 30;
uint num3 = (uint)((1 << num2) - 1);
_rangeEncoder.EncodeDirectBits(num3 >> 4, num2 - 4);
_posAlignEncoder.ReverseEncode(_rangeEncoder, num3 & 0xFu);
}
}
private void Flush(uint nowPos)
{
ReleaseMFStream();
WriteEndMarker(nowPos & _posStateMask);
_rangeEncoder.FlushData();
_rangeEncoder.FlushStream();
}
public void CodeOneBlock(out long inSize, out long outSize, out bool finished)
{
inSize = 0L;
outSize = 0L;
finished = true;
if (_inStream != null)
{
_matchFinder.SetStream(_inStream);
_matchFinder.Init();
_needReleaseMFStream = true;
_inStream = null;
if (_trainSize != 0)
{
_matchFinder.Skip(_trainSize);
}
}
if (_finished)
{
return;
}
_finished = true;
long num = nowPos64;
if (nowPos64 == 0L)
{
if (_matchFinder.GetNumAvailableBytes() == 0)
{
Flush((uint)nowPos64);
return;
}
ReadMatchDistances(out var _, out var _);
uint num2 = (uint)(int)nowPos64 & _posStateMask;
_isMatch[(_state.Index << 4) + num2].Encode(_rangeEncoder, 0u);
_state.UpdateChar();
byte indexByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));
_literalEncoder.GetSubCoder((uint)nowPos64, _previousByte).Encode(_rangeEncoder, indexByte);
_previousByte = indexByte;
_additionalOffset--;
nowPos64++;
}
if (_matchFinder.GetNumAvailableBytes() == 0)
{
Flush((uint)nowPos64);
return;
}
while (true)
{
uint backRes;
uint optimum = GetOptimum((uint)nowPos64, out backRes);
uint num3 = (uint)(int)nowPos64 & _posStateMask;
uint num4 = (_state.Index << 4) + num3;
if (optimum == 1 && backRes == uint.MaxValue)
{
_isMatch[num4].Encode(_rangeEncoder, 0u);
byte indexByte2 = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));
LiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((uint)nowPos64, _previousByte);
if (!_state.IsCharState())
{
byte indexByte3 = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));
subCoder.EncodeMatched(_rangeEncoder, indexByte3, indexByte2);
}
else
{
subCoder.Encode(_rangeEncoder, indexByte2);
}
_previousByte = indexByte2;
_state.UpdateChar();
}
else
{
_isMatch[num4].Encode(_rangeEncoder, 1u);
if (backRes < 4)
{
_isRep[_state.Index].Encode(_rangeEncoder, 1u);
if (backRes == 0)
{
_isRepG0[_state.Index].Encode(_rangeEncoder, 0u);
if (optimum == 1)
{
_isRep0Long[num4].Encode(_rangeEncoder, 0u);
}
else
{
_isRep0Long[num4].Encode(_rangeEncoder, 1u);
}
}
else
{
_isRepG0[_state.Index].Encode(_rangeEncoder, 1u);
if (backRes == 1)
{
_isRepG1[_state.Index].Encode(_rangeEncoder, 0u);
}
else
{
_isRepG1[_state.Index].Encode(_rangeEncoder, 1u);
_isRepG2[_state.Index].Encode(_rangeEncoder, backRes - 2);
}
}
if (optimum == 1)
{
_state.UpdateShortRep();
}
else
{
_repMatchLenEncoder.Encode(_rangeEncoder, optimum - 2, num3);
_state.UpdateRep();
}
uint num5 = _repDistances[backRes];
if (backRes != 0)
{
for (uint num6 = backRes; num6 >= 1; num6--)
{
_repDistances[num6] = _repDistances[num6 - 1];
}
_repDistances[0] = num5;
}
}
else
{
_isRep[_state.Index].Encode(_rangeEncoder, 0u);
_state.UpdateMatch();
_lenEncoder.Encode(_rangeEncoder, optimum - 2, num3);
backRes -= 4;
uint posSlot = GetPosSlot(backRes);
uint lenToPosState = Base.GetLenToPosState(optimum);
_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);
if (posSlot >= 4)
{
int num7 = (int)((posSlot >> 1) - 1);
uint num8 = (2 | (posSlot & 1)) << num7;
uint num9 = backRes - num8;
if (posSlot < 14)
{
BitTreeEncoder.ReverseEncode(_posEncoders, num8 - posSlot - 1, _rangeEncoder, num7, num9);
}
else
{
_rangeEncoder.EncodeDirectBits(num9 >> 4, num7 - 4);
_posAlignEncoder.ReverseEncode(_rangeEncoder, num9 & 0xFu);
_alignPriceCount++;
}
}
uint num10 = backRes;
for (uint num11 = 3u; num11 >= 1; num11--)
{
_repDistances[num11] = _repDistances[num11 - 1];
}
_repDistances[0] = num10;
_matchPriceCount++;
}
_previousByte = _matchFinder.GetIndexByte((int)(optimum - 1 - _additionalOffset));
}
_additionalOffset -= optimum;
nowPos64 += optimum;
if (_additionalOffset == 0)
{
if (_matchPriceCount >= 128)
{
FillDistancesPrices();
}
if (_alignPriceCount >= 16)
{
FillAlignPrices();
}
inSize = nowPos64;
outSize = _rangeEncoder.GetProcessedSizeAdd();
if (_matchFinder.GetNumAvailableBytes() == 0)
{
Flush((uint)nowPos64);
return;
}
if (nowPos64 - num >= 4096)
{
break;
}
}
}
_finished = false;
finished = false;
}
private void ReleaseMFStream()
{
if (_matchFinder != null && _needReleaseMFStream)
{
_matchFinder.ReleaseStream();
_needReleaseMFStream = false;
}
}
private void SetOutStream(Stream outStream)
{
_rangeEncoder.SetStream(outStream);
}
private void ReleaseOutStream()
{
_rangeEncoder.ReleaseStream();
}
private void ReleaseStreams()
{
ReleaseMFStream();
ReleaseOutStream();
}
private void SetStreams(Stream inStream, Stream outStream, long inSize, long outSize)
{
_inStream = inStream;
_finished = false;
Create();
SetOutStream(outStream);
Init();
FillDistancesPrices();
FillAlignPrices();
_lenEncoder.SetTableSize(_numFastBytes + 1 - 2);
_lenEncoder.UpdateTables((uint)(1 << _posStateBits));
_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - 2);
_repMatchLenEncoder.UpdateTables((uint)(1 << _posStateBits));
nowPos64 = 0L;
}
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress)
{
_needReleaseMFStream = false;
try
{
SetStreams(inStream, outStream, inSize, outSize);
while (true)
{
CodeOneBlock(out var inSize2, out var outSize2, out var finished);
if (finished)
{
break;
}
progress?.SetProgress(inSize2, outSize2);
}
}
finally
{
ReleaseStreams();
}
}
public void WriteCoderProperties(Stream outStream)
{
properties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);
for (int i = 0; i < 4; i++)
{
properties[1 + i] = (byte)((_dictionarySize >> 8 * i) & 0xFFu);
}
outStream.Write(properties, 0, 5);
}
private void FillDistancesPrices()
{
for (uint num = 4u; num < 128; num++)
{
uint posSlot = GetPosSlot(num);
int num2 = (int)((posSlot >> 1) - 1);
uint num3 = (2 | (posSlot & 1)) << num2;
tempPrices[num] = BitTreeEncoder.ReverseGetPrice(_posEncoders, num3 - posSlot - 1, num2, num - num3);
}
for (uint num4 = 0u; num4 < 4; num4++)
{
BitTreeEncoder bitTreeEncoder = _posSlotEncoder[num4];
uint num5 = num4 << 6;
for (uint num6 = 0u; num6 < _distTableSize; num6++)
{
_posSlotPrices[num5 + num6] = bitTreeEncoder.GetPrice(num6);
}
for (uint num6 = 14u; num6 < _distTableSize; num6++)
{
_posSlotPrices[num5 + num6] += (num6 >> 1) - 1 - 4 << 6;
}
uint num7 = num4 * 128;
uint num8;
for (num8 = 0u; num8 < 4; num8++)
{
_distancesPrices[num7 + num8] = _posSlotPrices[num5 + num8];
}
for (; num8 < 128; num8++)
{
_distancesPrices[num7 + num8] = _posSlotPrices[num5 + GetPosSlot(num8)] + tempPrices[num8];
}
}
_matchPriceCount = 0u;
}
private void FillAlignPrices()
{
for (uint num = 0u; num < 16; num++)
{
_alignPrices[num] = _posAlignEncoder.ReverseGetPrice(num);
}
_alignPriceCount = 0u;
}
private static int FindMatchFinder(string s)
{
for (int i = 0; i < kMatchFinderIDs.Length; i++)
{
if (s == kMatchFinderIDs[i])
{
return i;
}
}
return -1;
}
public void SetCoderProperties(CoderPropID[] propIDs, object[] properties)
{
for (uint num = 0u; num < properties.Length; num++)
{
object obj = properties[num];
switch (propIDs[num])
{
case CoderPropID.NumFastBytes:
if (!(obj is int num2))
{
throw new InvalidParamException();
}
if (num2 < 5 || (long)num2 > 273L)
{
throw new InvalidParamException();
}
_numFastBytes = (uint)num2;
break;
case CoderPropID.MatchFinder:
{
if (!(obj is string))
{
throw new InvalidParamException();
}
EMatchFinderType matchFinderType = _matchFinderType;
int num6 = FindMatchFinder(((string)obj).ToUpper());
if (num6 < 0)
{
throw new InvalidParamException();
}
_matchFinderType = (EMatchFinderType)num6;
if (_matchFinder != null && matchFinderType != _matchFinderType)
{
_dictionarySizePrev = uint.MaxValue;
_matchFinder = null;
}
break;
}
case CoderPropID.DictionarySize:
{
if (!(obj is int num7))
{
throw new InvalidParamException();
}
if ((long)num7 < 1L || (long)num7 > 1073741824L)
{
throw new InvalidParamException();
}
_dictionarySize = (uint)num7;
int i;
for (i = 0; (long)i < 30L && num7 > (uint)(1 << i); i++)
{
}
_distTableSize = (uint)(i * 2);
break;
}
case CoderPropID.PosStateBits:
if (!(obj is int num3))
{
throw new InvalidParamException();
}
if (num3 < 0 || (long)num3 > 4L)
{
throw new InvalidParamException();
}
_posStateBits = num3;
_posStateMask = (uint)((1 << _posStateBits) - 1);
break;
case CoderPropID.LitPosBits:
if (!(obj is int num5))
{
throw new InvalidParamException();
}
if (num5 < 0 || (long)num5 > 4L)
{
throw new InvalidParamException();
}
_numLiteralPosStateBits = num5;
break;
case CoderPropID.LitContextBits:
if (!(obj is int num4))
{
throw new InvalidParamException();
}
if (num4 < 0 || (long)num4 > 8L)
{
throw new InvalidParamException();
}
_numLiteralContextBits = num4;
break;
case CoderPropID.EndMarker:
if (!(obj is bool))
{
throw new InvalidParamException();
}
SetWriteEndMarkerMode((bool)obj);
break;
default:
throw new InvalidParamException();
case CoderPropID.Algorithm:
break;
}
}
}
public void SetTrainSize(uint trainSize)
{
_trainSize = trainSize;
}
}
public static class SevenZipHelper
{
private static CoderPropID[] propIDs = new CoderPropID[8]
{
CoderPropID.DictionarySize,
CoderPropID.PosStateBits,
CoderPropID.LitContextBits,
CoderPropID.LitPosBits,
CoderPropID.Algorithm,
CoderPropID.NumFastBytes,
CoderPropID.MatchFinder,
CoderPropID.EndMarker
};
private static object[] properties = new object[8] { 2097152, 2, 3, 0, 2, 32, "bt4", false };
public static byte[] Compress(byte[] inputBytes, ICodeProgress progress = null)
{
MemoryStream inStream = new MemoryStream(inputBytes);
MemoryStream memoryStream = new MemoryStream();
Compress(inStream, memoryStream, progress);
return memoryStream.ToArray();
}
public static void Compress(Stream inStream, Stream outStream, ICodeProgress progress = null)
{
Encoder encoder = new Encoder();
encoder.SetCoderProperties(propIDs, properties);
encoder.WriteCoderProperties(outStream);
encoder.Code(inStream, outStream, -1L, -1L, progress);
}
public static byte[] Decompress(byte[] inputBytes)
{
MemoryStream memoryStream = new MemoryStream(inputBytes);
Decoder decoder = new Decoder();
memoryStream.Seek(0L, SeekOrigin.Begin);
MemoryStream memoryStream2 = new MemoryStream();
byte[] array = new byte[5];
if (memoryStream.Read(array, 0, 5) != 5)
{
throw new Exception("input .lzma is too short");
}
long num = 0L;
for (int i = 0; i < 8; i++)
{
int num2 = memoryStream.ReadByte();
if (num2 < 0)
{
throw new Exception("Can't Read 1");
}
num |= (long)((ulong)(byte)num2 << 8 * i);
}
decoder.SetDecoderProperties(array);
long inSize = memoryStream.Length - memoryStream.Position;
decoder.Code(memoryStream, memoryStream2, inSize, num, null);
return memoryStream2.ToArray();
}
public static MemoryStream StreamDecompress(MemoryStream newInStream)
{
Decoder decoder = new Decoder();
newInStream.Seek(0L, SeekOrigin.Begin);
MemoryStream memoryStream = new MemoryStream();
byte[] array = new byte[5];
if (newInStream.Read(array, 0, 5) != 5)
{
throw new Exception("input .lzma is too short");
}
long num = 0L;
for (int i = 0; i < 8; i++)
{
int num2 = newInStream.ReadByte();
if (num2 < 0)
{
throw new Exception("Can't Read 1");
}
num |= (long)((ulong)(byte)num2 << 8 * i);
}
decoder.SetDecoderProperties(array);
long inSize = newInStream.Length - newInStream.Position;
decoder.Code(newInStream, memoryStream, inSize, num, null);
memoryStream.Position = 0L;
return memoryStream;
}
public static MemoryStream StreamDecompress(MemoryStream newInStream, long outSize)
{
Decoder decoder = new Decoder();
newInStream.Seek(0L, SeekOrigin.Begin);
MemoryStream memoryStream = new MemoryStream();
byte[] array = new byte[5];
if (newInStream.Read(array, 0, 5) != 5)
{
throw new Exception("input .lzma is too short");
}
decoder.SetDecoderProperties(array);
long inSize = newInStream.Length - newInStream.Position;
decoder.Code(newInStream, memoryStream, inSize, outSize, null);
memoryStream.Position = 0L;
return memoryStream;
}
public static void StreamDecompress(Stream compressedStream, Stream decompressedStream, long compressedSize, long decompressedSize)
{
long position = compressedStream.Position;
Decoder decoder = new Decoder();
byte[] array = new byte[5];
if (compressedStream.Read(array, 0, 5) != 5)
{
throw new Exception("input .lzma is too short");
}
decoder.SetDecoderProperties(array);
decoder.Code(compressedStream, decompressedStream, compressedSize - 5, decompressedSize, null);
compressedStream.Position = position + compressedSize;
}
}
}
namespace SevenZip.Buffer
{
public class InBuffer
{
private byte[] m_Buffer;
private uint m_Pos;
private uint m_Limit;
private uint m_BufferSize;
private Stream m_Stream;
private bool m_StreamWasExhausted;
private ulong m_ProcessedSize;
public InBuffer(uint bufferSize)
{
m_Buffer = new byte[bufferSize];
m_BufferSize = bufferSize;
}
public void Init(Stream stream)
{
m_Stream = stream;
m_ProcessedSize = 0uL;
m_Limit = 0u;
m_Pos = 0u;
m_StreamWasExhausted = false;
}
public bool ReadBlock()
{
if (m_StreamWasExhausted)
{
return false;
}
m_ProcessedSize += m_Pos;
int num = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);
m_Pos = 0u;
m_Limit = (uint)num;
m_StreamWasExhausted = num == 0;
return !m_StreamWasExhausted;
}
public void ReleaseStream()
{
m_Stream = null;
}
public bool ReadByte(byte b)
{
if (m_Pos >= m_Limit && !ReadBlock())
{
return false;
}
b = m_Buffer[m_Pos++];
return true;
}
public byte ReadByte()
{
if (m_Pos >= m_Limit && !ReadBlock())
{
return byte.MaxValue;
}
return m_Buffer[m_Pos++];
}
public ulong GetProcessedSize()
{
return m_ProcessedSize + m_Pos;
}
}
public class OutBuffer
{
private byte[] m_Buffer;
private uint m_Pos;
private uint m_BufferSize;
private Stream m_Stream;
private ulong m_ProcessedSize;
public OutBuffer(uint bufferSize)
{
m_Buffer = new byte[bufferSize];
m_BufferSize = bufferSize;
}
public void SetStream(Stream stream)
{
m_Stream = stream;
}
public void FlushStream()
{
m_Stream.Flush();
}
public void CloseStream()
{
m_Stream.Close();
}
public void ReleaseStream()
{
m_Stream = null;
}
public void Init()
{
m_ProcessedSize = 0uL;
m_Pos = 0u;
}
public void WriteByte(byte b)
{
m_Buffer[m_Pos++] = b;
if (m_Pos >= m_BufferSize)
{
FlushData();
}
}
public void FlushData()
{
if (m_Pos != 0)
{
m_Stream.Write(m_Buffer, 0, (int)m_Pos);
m_Pos = 0u;
}
}
public ulong GetProcessedSize()
{
return m_ProcessedSize + m_Pos;
}
}
}
namespace SevenZip.CommandLineParser
{
public enum SwitchType
{
Simple,
PostMinus,
LimitedPostString,
UnLimitedPostString,
PostChar
}
public class SwitchForm
{
public string IDString;
public SwitchType Type;
public bool Multi;
public int MinLen;
public int MaxLen;
public string PostCharSet;
public SwitchForm(string idString, SwitchType type, bool multi, int minLen, int maxLen, string postCharSet)
{
IDString = idString;
Type = type;
Multi = multi;
MinLen = minLen;
MaxLen = maxLen;
PostCharSet = postCharSet;
}
public SwitchForm(string idString, SwitchType type, bool multi, int minLen)
: this(idString, type, multi, minLen, 0, "")
{
}
public SwitchForm(string idString, SwitchType type, bool multi)
: this(idString, type, multi, 0)
{
}
}
public class SwitchResult
{
public bool ThereIs;
public bool WithMinus;
public ArrayList PostStrings = new ArrayList();
public int PostCharIndex;
public SwitchResult()
{
ThereIs = false;
}
}
public class Parser
{
public ArrayList NonSwitchStrings = new ArrayList();
private SwitchResult[] _switches;
private const char kSwitchID1 = '-';
private const char kSwitchID2 = '/';
private const char kSwitchMinus = '-';
private const string kStopSwitchParsing = "--";
public SwitchResult this[int index] => _switches[index];
public Parser(int numSwitches)
{
_switches = new SwitchResult[numSwitches];
for (int i = 0; i < numSwitches; i++)
{
_switches[i] = new SwitchResult();
}
}
private bool ParseString(string srcString, SwitchForm[] switchForms)
{
int length = srcString.Length;
if (length == 0)
{
return false;
}
int num = 0;
if (!IsItSwitchChar(srcString[num]))
{
return false;
}
while (num < length)
{
if (IsItSwitchChar(srcString[num]))
{
num++;
}
int num2 = 0;
int num3 = -1;
for (int i = 0; i < _switches.Length; i++)
{
int length2 = switchForms[i].IDString.Length;
if (length2 > num3 && num + length2 <= length && string.Compare(switchForms[i].IDString, 0, srcString, num, length2, ignoreCase: true) == 0)
{
num2 = i;
num3 = length2;
}
}
if (num3 == -1)
{
throw new Exception("maxLen == kNoLen");
}
SwitchResult switchResult = _switches[num2];
SwitchForm switchForm = switchForms[num2];
if (!switchForm.Multi && switchResult.ThereIs)
{
throw new Exception("switch must be single");
}
switchResult.ThereIs = true;
num += num3;
int num4 = length - num;
SwitchType type = switchForm.Type;
switch (type)
{
case SwitchType.PostMinus:
if (num4 == 0)
{
switchResult.WithMinus = false;
break;
}
switchResult.WithMinus = srcString[num] == '-';
if (switchResult.WithMinus)
{
num++;
}
break;
case SwitchType.PostChar:
{
if (num4 < switchForm.MinLen)
{
throw new Exception("switch is not full");
}
string postCharSet = switchForm.PostCharSet;
if (num4 == 0)
{
switchResult.PostCharIndex = -1;
break;
}
int num6 = postCharSet.IndexOf(srcString[num]);
if (num6 < 0)
{
switchResult.PostCharIndex = -1;
break;
}
switchResult.PostCharIndex = num6;
num++;
break;
}
case SwitchType.LimitedPostString:
case SwitchType.UnLimitedPostString:
{
int minLen = switchForm.MinLen;
if (num4 < minLen)
{
throw new Exception("switch is not full");
}
if (type == SwitchType.UnLimitedPostString)
{
switchResult.PostStrings.Add(srcString.Substring(num));
return true;
}
string text = srcString.Substring(num, minLen);
num += minLen;
int num5 = minLen;
while (num5 < switchForm.MaxLen && num < length)
{
char c = srcString[num];
if (IsItSwitchChar(c))
{
break;
}
text += c;
num5++;
num++;
}
switchResult.PostStrings.Add(text);
break;
}
}
}
return true;
}
public void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)
{
int num = commandStrings.Length;
bool flag = false;
for (int i = 0; i < num; i++)
{
string text = commandStrings[i];
if (flag)
{
NonSwitchStrings.Add(text);
}
else if (text == "--")
{
flag = true;
}
else if (!ParseString(text, switchForms))
{
NonSwitchStrings.Add(text);
}
}
}
public static int ParseCommand(CommandForm[] commandForms, string commandString, out string postString)
{
for (int i = 0; i < commandForms.Length; i++)
{
string iDString = commandForms[i].IDString;
if (commandForms[i].PostStringMode)
{
if (commandString.IndexOf(iDString) == 0)
{
postString = commandString.Substring(iDString.Length);
return i;
}
}
else if (commandString == iDString)
{
postString = "";
return i;
}
}
postString = "";
return -1;
}
private static bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms, string commandString, ArrayList indices)
{
indices.Clear();
int num = 0;
for (int i = 0; i < numForms; i++)
{
CommandSubCharsSet commandSubCharsSet = forms[i];
int num2 = -1;
int length = commandSubCharsSet.Chars.Length;
for (int j = 0; j < length; j++)
{
char value = commandSubCharsSet.Chars[j];
int num3 = commandString.IndexOf(value);
if (num3 >= 0)
{
if (num2 >= 0)
{
return false;
}
if (commandString.IndexOf(value, num3 + 1) >= 0)
{
return false;
}
num2 = j;
num++;
}
}
if (num2 == -1 && !commandSubCharsSet.EmptyAllowed)
{
return false;
}
indices.Add(num2);
}
return num == commandString.Length;
}
private static bool IsItSwitchChar(char c)
{
if (c != '-')
{
return c == '/';
}
return true;
}
}
public class CommandForm
{
public string IDString = "";
public bool PostStringMode;
public CommandForm(string idString, bool postStringMode)
{
IDString = idString;
PostStringMode = postStringMode;
}
}
internal class CommandSubCharsSet
{
public string Chars = "";
public bool EmptyAllowed;
}
}
namespace LZ4ps
{
public static class LZ4Codec
{
private class LZ4HC_Data_Structure
{
public byte[] src;
public int src_base;
public int src_end;
public int src_LASTLITERALS;
public byte[] dst;
public int dst_base;
public int dst_len;
public int dst_end;
public int[] hashTable;
public ushort[] chainTable;
public int nextToUpdate;
}
private const int MEMORY_USAGE = 14;
private const int NOTCOMPRESSIBLE_DETECTIONLEVEL = 6;
private const int BLOCK_COPY_LIMIT = 16;
private const int MINMATCH = 4;
private const int SKIPSTRENGTH = 6;
private const int COPYLENGTH = 8;
private const int LASTLITERALS = 5;
private const int MFLIMIT = 12;
private const int MINLENGTH = 13;
private const int MAXD_LOG = 16;
private const int MAXD = 65536;
private const int MAXD_MASK = 65535;
private const int MAX_DISTANCE = 65535;
private const int ML_BITS = 4;
private const int ML_MASK = 15;
private const int RUN_BITS = 4;
private const int RUN_MASK = 15;
private const int STEPSIZE_64 = 8;
private const int STEPSIZE_32 = 4;
private const int LZ4_64KLIMIT = 65547;
private const int HASH_LOG = 12;
private const int HASH_TABLESIZE = 4096;
private const int HASH_ADJUST = 20;
private const int HASH64K_LOG = 13;
private const int HASH64K_TABLESIZE = 8192;
private const int HASH64K_ADJUST = 19;
private const int HASHHC_LOG = 15;
private const int HASHHC_TABLESIZE = 32768;
private const int HASHHC_ADJUST = 17;
private static readonly int[] DECODER_TABLE_32 = new int[8] { 0, 3, 2, 3, 0, 0, 0, 0 };
private static readonly int[] DECODER_TABLE_64 = new int[8] { 0, 0, 0, -1, 0, 1, 2, 3 };
private static readonly int[] DEBRUIJN_TABLE_32 = new int[32]
{
0, 0, 3, 0, 3, 1, 3, 0, 3, 2,
2, 1, 3, 2, 0, 1, 3, 3, 1, 2,
2, 2, 2, 0, 3, 1, 2, 0, 1, 0,
1, 1
};
private static readonly int[] DEBRUIJN_TABLE_64 = new int[64]
{
0, 0, 0, 0, 0, 1, 1, 2, 0, 3,
1, 3, 1, 4, 2, 7, 0, 2, 3, 6,
1, 5, 3, 5, 1, 3, 4, 4, 2, 5,
6, 7, 7, 0, 1, 2, 3, 3, 4, 6,
2, 6, 5, 5, 3, 4, 5, 6, 7, 1,
2, 4, 6, 4, 4, 5, 7, 2, 6, 5,
7, 6, 7, 7
};
private const int MAX_NB_ATTEMPTS = 256;
private const int OPTIMAL_ML = 18;
public static int MaximumOutputLength(int inputLength)
{
return inputLength + inputLength / 255 + 16;
}
internal static void CheckArguments(byte[] input, int inputOffset, ref int inputLength, byte[] output, int outputOffset, ref int outputLength)
{
if (inputLength < 0)
{
inputLength = input.Length - inputOffset;
}
if (inputLength == 0)
{
outputLength = 0;
return;
}
if (input == null)
{
throw new ArgumentNullException("input");
}
if (inputOffset < 0 || inputOffset + inputLength > input.Length)
{
throw new ArgumentException("inputOffset and inputLength are invalid for given input");
}
if (outputLength < 0)
{
outputLength = output.Length - outputOffset;
}
if (output == null)
{
throw new ArgumentNullException("output");
}
if (outputOffset >= 0 && outputOffset + outputLength <= output.Length)
{
return;
}
throw new ArgumentException("outputOffset and outputLength are invalid for given output");
}
[Conditional("DEBUG")]
private static void Assert(bool condition, string errorMessage)
{
if (!condition)
{
throw new ArgumentException(errorMessage);
}
}
internal static void Poke2(byte[] buffer, int offset, ushort value)
{
buffer[offset] = (byte)value;
buffer[offset + 1] = (byte)(value >> 8);
}
internal static ushort Peek2(byte[] buffer, int offset)
{
return (ushort)(buffer[offset] | (buffer[offset + 1] << 8));
}
internal static uint Peek4(byte[] buffer, int offset)
{
return (uint)(buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24));
}
private static uint Xor4(byte[] buffer, int offset1, int offset2)
{
int num = buffer[offset1] | (buffer[offset1 + 1] << 8) | (buffer[offset1 + 2] << 16) | (buffer[offset1 + 3] << 24);
uint num2 = (uint)(buffer[offset2] | (buffer[offset2 + 1] << 8) | (buffer[offset2 + 2] << 16) | (buffer[offset2 + 3] << 24));
return (uint)num ^ num2;
}
private static ulong Xor8(byte[] buffer, int offset1, int offset2)
{
ulong num = buffer[offset1] | ((ulong)buffer[offset1 + 1] << 8) | ((ulong)buffer[offset1 + 2] << 16) | ((ulong)buffer[offset1 + 3] << 24) | ((ulong)buffer[offset1 + 4] << 32) | ((ulong)buffer[offset1 + 5] << 40) | ((ulong)buffer[offset1 + 6] << 48) | ((ulong)buffer[offset1 + 7] << 56);
ulong num2 = buffer[offset2] | ((ulong)buffer[offset2 + 1] << 8) | ((ulong)buffer[offset2 + 2] << 16) | ((ulong)buffer[offset2 + 3] << 24) | ((ulong)buffer[offset2 + 4] << 32) | ((ulong)buffer[offset2 + 5] << 40) | ((ulong)buffer[offset2 + 6] << 48) | ((ulong)buffer[offset2 + 7] << 56);
return num ^ num2;
}
private static bool Equal2(byte[] buffer, int offset1, int offset2)
{
if (buffer[offset1] != buffer[offset2])
{
return false;
}
return buffer[offset1 + 1] == buffer[offset2 + 1];
}
private static bool Equal4(byte[] buffer, int offset1, int offset2)
{
if (buffer[offset1] != buffer[offset2])
{
return false;
}
if (buffer[offset1 + 1] != buffer[offset2 + 1])
{
return false;
}
if (buffer[offset1 + 2] != buffer[offset2 + 2])
{
return false;
}
return buffer[offset1 + 3] == buffer[offset2 + 3];
}
private static void Copy4(byte[] buf, int src, int dst)
{
buf[dst + 3] = buf[src + 3];
buf[dst + 2] = buf[src + 2];
buf[dst + 1] = buf[src + 1];
buf[dst] = buf[src];
}
private static void Copy8(byte[] buf, int src, int dst)
{
buf[dst + 7] = buf[src + 7];
buf[dst + 6] = buf[src + 6];
buf[dst + 5] = buf[src + 5];
buf[dst + 4] = buf[src + 4];
buf[dst + 3] = buf[src + 3];
buf[dst + 2] = buf[src + 2];
buf[dst + 1] = buf[src + 1];
buf[dst] = buf[src];
}
private static void BlockCopy(byte[] src, int src_0, byte[] dst, int dst_0, int len)
{
if (len >= 16)
{
Buffer.BlockCopy(src, src_0, dst, dst_0, len);
return;
}
while (len >= 8)
{
dst[dst_0] = src[src_0];
dst[dst_0 + 1] = src[src_0 + 1];
dst[dst_0 + 2] = src[src_0 + 2];
dst[dst_0 + 3] = src[src_0 + 3];
dst[dst_0 + 4] = src[src_0 + 4];
dst[dst_0 + 5] = src[src_0 + 5];
dst[dst_0 + 6] = src[src_0 + 6];
dst[dst_0 + 7] = src[src_0 + 7];
len -= 8;
src_0 += 8;
dst_0 += 8;
}
while (len >= 4)
{
dst[dst_0] = src[src_0];
dst[dst_0 + 1] = src[src_0 + 1];
dst[dst_0 + 2] = src[src_0 + 2];
dst[dst_0 + 3] = src[src_0 + 3];
len -= 4;
src_0 += 4;
dst_0 += 4;
}
while (len-- > 0)
{
dst[dst_0++] = src[src_0++];
}
}
private static int WildCopy(byte[] src, int src_0, byte[] dst, int dst_0, int dst_end)
{
int num = dst_end - dst_0;
if (num >= 16)
{
Buffer.BlockCopy(src, src_0, dst, dst_0, num);
}
else
{
while (num >= 4)
{
dst[dst_0] = src[src_0];
dst[dst_0 + 1] = src[src_0 + 1];
dst[dst_0 + 2] = src[src_0 + 2];
dst[dst_0 + 3] = src[src_0 + 3];
num -= 4;
src_0 += 4;
dst_0 += 4;
}
while (num-- > 0)
{
dst[dst_0++] = src[src_0++];
}
}
return num;
}
private static int SecureCopy(byte[] buffer, int src, int dst, int dst_end)
{
int num = dst - src;
int num2 = dst_end - dst;
int num3 = num2;
if (num >= 16)
{
if (num >= num2)
{
Buffer.BlockCopy(buffer, src, buffer, dst, num2);
return num2;
}
do
{
Buffer.BlockCopy(buffer, src, buffer, dst, num);
src += num;
dst += num;
num3 -= num;
}
while (num3 >= num);
}
while (num3 >= 4)
{
buffer[dst] = buffer[src];
buffer[dst + 1] = buffer[src + 1];
buffer[dst + 2] = buffer[src + 2];
buffer[dst + 3] = buffer[src + 3];
dst += 4;
src += 4;
num3 -= 4;
}
while (num3-- > 0)
{
buffer[dst++] = buffer[src++];
}
return num2;
}
public static int Encode32(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength)
{
CheckArguments(input, inputOffset, ref inputLength, output, outputOffset, ref outputLength);
if (outputLength == 0)
{
return 0;
}
if (inputLength < 65547)
{
return LZ4_compress64kCtx_safe32(new ushort[8192], input, output, inputOffset, outputOffset, inputLength, outputLength);
}
return LZ4_compressCtx_safe32(new int[4096], input, output, inputOffset, outputOffset, inputLength, outputLength);
}
public static byte[] Encode32(byte[] input, int inputOffset, int inputLength)
{
if (inputLength < 0)
{
inputLength = input.Length - inputOffset;
}
if (input == null)
{
throw new ArgumentNullException("input");
}
if (inputOffset < 0 || inputOffset + inputLength > input.Length)
{
throw new ArgumentException("inputOffset and inputLength are invalid for given input");
}
byte[] array = new byte[MaximumOutputLength(inputLength)];
int num = Encode32(input, inputOffset, inputLength, array, 0, array.Length);
if (num != array.Length)
{
if (num < 0)
{
throw new InvalidOperationException("Compression has been corrupted");
}
byte[] array2 = new byte[num];
Buffer.BlockCopy(array, 0, array2, 0, num);
return array2;
}
return array;
}
public static int Encode64(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength)
{
CheckArguments(input, inputOffset, ref inputLength, output, outputOffset, ref outputLength);
if (outputLength == 0)
{
return 0;
}
if (inputLength < 65547)
{
return LZ4_compress64kCtx_safe64(new ushort[8192], input, output, inputOffset, outputOffset, inputLength, outputLength);
}
return LZ4_compressCtx_safe64(new int[4096], input, output, inputOffset, outputOffset, inputLength, outputLength);
}
public static byte[] Encode64(byte[] input, int inputOffset, int inputLength)
{
if (inputLength < 0)
{
inputLength = input.Length - inputOffset;
}
if (input == null)
{
throw new ArgumentNullException("input");
}
if (inputOffset < 0 || inputOffset + inputLength > input.Length)
{
throw new ArgumentException("inputOffset and inputLength are invalid for given input");
}
byte[] array = new byte[MaximumOutputLength(inputLength)];
int num = Encode64(input, inputOffset, inputLength, array, 0, array.Length);
if (num != array.Length)
{
if (num < 0)
{
throw new InvalidOperationException("Compression has been corrupted");
}
byte[] array2 = new byte[num];
Buffer.BlockCopy(array, 0, array2, 0, num);
return array2;
}
return array;
}
public static int Decode32(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength, bool knownOutputLength)
{
CheckArguments(input, inputOffset, ref inputLength, output, outputOffset, ref outputLength);
if (outputLength == 0)
{
return 0;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Microsoft.CodeAnalysis;
using R2API.Animations.Models.Interfaces;
using R2API.Models;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.Animations.Runtime")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4c3fa0aa1bf06bccbf6fd22f858a2b3d0c968b1c")]
[assembly: AssemblyProduct("R2API.Animations.Runtime")]
[assembly: AssemblyTitle("R2API.Animations.Runtime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}
namespace R2API.Animations.Models.Interfaces
{
public interface IBlendTree
{
string BlendParameter { get; }
string BlendParameterY { get; }
BlendTreeType BlendType { get; }
IReadOnlyList<IChildMotion> Children { get; }
}
public interface IChildMotion : IMotion
{
float Threshold { get; }
Vector2 Position { get; }
float TimeScale { get; }
float CycleOffset { get; }
string DirectBlendParameter { get; }
bool Mirror { get; }
}
public interface ICondition
{
ConditionMode ConditionMode { get; }
string ParamName { get; }
float Value { get; }
}
public interface IExistingAnimatorController
{
IReadOnlyList<IExistingLayer> Layers { get; }
IReadOnlyList<ILayer> NewLayers { get; }
IReadOnlyList<IParameter> NewParameters { get; }
}
public interface IExistingLayer
{
string Name { get; }
IExistingStateMachine StateMachine { get; }
IReadOnlyList<ISyncedBehaviour> NewSyncedBehaviours { get; }
}
public interface IExistingState
{
string Name { get; }
IReadOnlyList<ITransition> NewTransitions { get; }
IReadOnlyList<StateMachineBehaviour> NewBehaviours { get; }
}
public interface IExistingStateMachine
{
string Name { get; }
IReadOnlyList<IState> NewStates { get; }
IReadOnlyList<IExistingState> States { get; }
IReadOnlyList<ITransition> NewAnyStateTransitions { get; }
IReadOnlyList<ISimpleTransition> NewEntryTransitions { get; }
IReadOnlyList<IStateMachine> NewSubStateMachines { get; }
IReadOnlyList<IExistingStateMachine> SubStateMachines { get; }
IReadOnlyList<StateMachineBehaviour> NewBehaviours { get; }
}
public interface ILayer
{
string Name { get; }
string PreviousLayerName { get; }
IStateMachine StateMachine { get; }
AvatarMask AvatarMask { get; }
AnimatorLayerBlendingMode BlendingMode { get; }
string SyncedLayerName { get; }
bool IKPass { get; }
float DefaultWeight { get; }
bool SyncedLayerAffectsTiming { get; }
IReadOnlyList<ISyncedMotion> SyncedMotions { get; }
IReadOnlyList<ISyncedBehaviour> SyncedBehaviours { get; }
}
public interface IMotion
{
AnimationClip Clip { get; }
IBlendTree BlendTree { get; }
}
public interface IParameter
{
string Name { get; }
ParameterType Type { get; }
ParameterValue Value { get; }
}
public interface ISimpleTransition
{
string DestinationStateName { get; }
string DestinationStateMachinePath { get; }
IReadOnlyList<ICondition> Conditions { get; }
}
public interface IState : IMotion
{
string Name { get; }
string Tag { get; }
string SpeedParam { get; }
string MirrorParam { get; }
string CycleOffsetParam { get; }
string TimeParam { get; }
float Speed { get; }
float CycleOffset { get; }
bool IKOnFeet { get; }
bool WriteDefaultValues { get; }
bool Loop { get; }
bool Mirror { get; }
IReadOnlyList<ITransition> Transitions { get; }
IReadOnlyList<StateMachineBehaviour> Behaviours { get; }
}
public interface IStateMachine
{
string Name { get; }
string DefaultStateName { get; }
string DefaultStateMachinePath { get; }
IReadOnlyList<IState> States { get; }
IReadOnlyList<ITransition> AnyStateTransitions { get; }
IReadOnlyList<ISimpleTransition> EntryTransitions { get; }
IReadOnlyList<IStateMachine> SubStateMachines { get; }
IReadOnlyList<StateMachineBehaviour> Behaviours { get; }
}
public interface ISyncedBehaviour
{
string StateName { get; }
string StateMachinePath { get; }
IReadOnlyList<StateMachineBehaviour> Behaviours { get; }
}
public interface ISyncedMotion : IMotion
{
string StateName { get; }
string StateMachinePath { get; }
}
public interface ITransition : ISimpleTransition
{
float TransitionDuration { get; }
float Offset { get; }
float ExitTime { get; }
bool HasExitTime { get; }
bool HasFixedDuration { get; }
InterruptionSource InterruptionSource { get; }
bool OrderedInterruption { get; }
bool CanTransitionToSelf { get; }
bool IsExit { get; }
}
}
namespace R2API.Models
{
public class AnimatorDiff : ScriptableObject, IExistingAnimatorController
{
[SerializeField]
private List<ExistingLayer> layers = new List<ExistingLayer>();
[SerializeField]
private List<Layer> newLayers = new List<Layer>();
[SerializeField]
private List<Parameter> newParameters = new List<Parameter>();
public List<ExistingLayer> Layers => layers;
IReadOnlyList<IExistingLayer> IExistingAnimatorController.Layers => layers;
public List<Layer> NewLayers => newLayers;
IReadOnlyList<ILayer> IExistingAnimatorController.NewLayers => newLayers;
public List<Parameter> NewParameters => newParameters;
IReadOnlyList<IParameter> IExistingAnimatorController.NewParameters => newParameters;
}
public enum AnimatorLayerBlendingMode
{
Override,
Additive
}
public class BlendTree : ScriptableObject, IBlendTree
{
[SerializeField]
private string blendParameter;
[SerializeField]
private string blendParameterY;
[SerializeField]
private BlendTreeType blendType;
[SerializeField]
private List<ChildMotion> children = new List<ChildMotion>();
public string BlendParameter
{
get
{
return blendParameter;
}
set
{
blendParameter = value;
}
}
public string BlendParameterY
{
get
{
return blendParameterY;
}
set
{
blendParameterY = value;
}
}
public BlendTreeType BlendType
{
get
{
return blendType;
}
set
{
blendType = value;
}
}
public List<ChildMotion> Children => children;
IReadOnlyList<IChildMotion> IBlendTree.Children => children;
}
public enum BlendTreeType
{
Simple1D,
SimpleDirectional2D,
FreeformDirectional2D,
FreeformCartesian2D,
Direct
}
[Serializable]
public class ChildMotion : IChildMotion, IMotion
{
[SerializeField]
private AnimationClip clip;
[SerializeField]
private BlendTree blendTree;
[SerializeField]
private float threshold;
[SerializeField]
private Vector2 position;
[SerializeField]
private float timeScale;
[SerializeField]
private float cycleOffset;
[SerializeField]
private string directBlendParameter;
[SerializeField]
private bool mirror;
[Obsolete("No longer required")]
public string ClipBundlePath
{
get
{
return "";
}
set
{
}
}
public AnimationClip Clip
{
get
{
return clip;
}
set
{
clip = value;
}
}
public BlendTree BlendTree
{
get
{
return blendTree;
}
set
{
blendTree = value;
}
}
IBlendTree IMotion.BlendTree => blendTree;
public float Threshold
{
get
{
return threshold;
}
set
{
threshold = value;
}
}
public Vector2 Position
{
get
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return position;
}
set
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
position = value;
}
}
public float TimeScale
{
get
{
return timeScale;
}
set
{
timeScale = value;
}
}
public float CycleOffset
{
get
{
return cycleOffset;
}
set
{
cycleOffset = value;
}
}
public string DirectBlendParameter
{
get
{
return directBlendParameter;
}
set
{
directBlendParameter = value;
}
}
public bool Mirror
{
get
{
return mirror;
}
set
{
mirror = value;
}
}
}
[Serializable]
public class Condition : ICondition
{
[SerializeField]
private ConditionMode conditionMode;
[SerializeField]
private string paramName;
[SerializeField]
private float value;
public ConditionMode ConditionMode
{
get
{
return conditionMode;
}
set
{
conditionMode = value;
}
}
public string ParamName
{
get
{
return paramName;
}
set
{
paramName = value;
}
}
public float Value
{
get
{
return value;
}
set
{
this.value = value;
}
}
}
public enum ConditionMode
{
IsTrue = 1,
IsFalse = 2,
IsGreater = 3,
IsLess = 4,
IsEqual = 6,
IsNotEqual = 7
}
[Serializable]
public class EntryTransition : ISimpleTransition
{
[SerializeField]
private string destinationStateName;
[SerializeField]
private string destinationStateMachineName;
[SerializeField]
private List<Condition> conditions = new List<Condition>();
public string DestinationStateName
{
get
{
return destinationStateName;
}
set
{
destinationStateName = value;
}
}
public string DestinationStateMachinePath
{
get
{
return destinationStateMachineName;
}
set
{
destinationStateMachineName = value;
}
}
public List<Condition> Conditions => conditions;
IReadOnlyList<ICondition> ISimpleTransition.Conditions => conditions;
}
[Serializable]
public class ExistingLayer : IExistingLayer
{
[SerializeField]
private string name;
[SerializeField]
[HideInInspector]
private List<State> newStates = new List<State>();
[SerializeField]
[HideInInspector]
private List<ExistingState> existingStates = new List<ExistingState>();
[SerializeField]
private ExistingStateMachine stateMachine;
[SerializeField]
private List<SyncedBehaviour> newSyncedBehaviours = new List<SyncedBehaviour>();
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
[Obsolete("Use StateMachine field instead")]
public List<State> NewStates => newStates;
[Obsolete("Use StateMachine field instead")]
public List<ExistingState> ExistingStates => existingStates;
public ExistingStateMachine StateMachine
{
get
{
return stateMachine;
}
set
{
stateMachine = value;
}
}
IExistingStateMachine IExistingLayer.StateMachine => stateMachine;
public List<SyncedBehaviour> NewSyncedBehaviours => newSyncedBehaviours;
IReadOnlyList<ISyncedBehaviour> IExistingLayer.NewSyncedBehaviours => newSyncedBehaviours;
}
[Serializable]
public class ExistingState : IExistingState
{
[SerializeField]
private string name;
[SerializeField]
private List<Transition> newTransitions = new List<Transition>();
[SerializeField]
private List<StateMachineBehaviour> newBehaviours = new List<StateMachineBehaviour>();
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public List<Transition> NewTransitions => newTransitions;
IReadOnlyList<ITransition> IExistingState.NewTransitions => newTransitions;
public List<StateMachineBehaviour> NewBehaviours => newBehaviours;
IReadOnlyList<StateMachineBehaviour> IExistingState.NewBehaviours => newBehaviours;
}
public class ExistingStateMachine : ScriptableObject, IExistingStateMachine
{
[SerializeField]
private List<State> newStates = new List<State>();
[SerializeField]
private List<ExistingState> states = new List<ExistingState>();
[SerializeField]
private List<Transition> newAnyStateTransitions = new List<Transition>();
[SerializeField]
private List<EntryTransition> newEntryTransitions = new List<EntryTransition>();
[SerializeField]
private List<ExistingStateMachine> subStateMachines = new List<ExistingStateMachine>();
[SerializeField]
private List<StateMachine> newSubStateMachines = new List<StateMachine>();
[SerializeField]
private List<StateMachineBehaviour> newBehaviours = new List<StateMachineBehaviour>();
public string Name
{
get
{
return ((Object)this).name;
}
set
{
((Object)this).name = value;
}
}
public List<State> NewStates => newStates;
IReadOnlyList<IState> IExistingStateMachine.NewStates => newStates;
public List<ExistingState> States => states;
IReadOnlyList<IExistingState> IExistingStateMachine.States => states;
public List<Transition> NewAnyStateTransitions => newAnyStateTransitions;
IReadOnlyList<ITransition> IExistingStateMachine.NewAnyStateTransitions => newAnyStateTransitions;
public List<EntryTransition> NewEntryTransitions => newEntryTransitions;
IReadOnlyList<ISimpleTransition> IExistingStateMachine.NewEntryTransitions => newEntryTransitions;
public List<ExistingStateMachine> SubStateMachines => subStateMachines;
IReadOnlyList<IExistingStateMachine> IExistingStateMachine.SubStateMachines => subStateMachines;
public List<StateMachine> NewSubStateMachines => newSubStateMachines;
IReadOnlyList<IStateMachine> IExistingStateMachine.NewSubStateMachines => newSubStateMachines;
public List<StateMachineBehaviour> NewBehaviours => newBehaviours;
IReadOnlyList<StateMachineBehaviour> IExistingStateMachine.NewBehaviours => newBehaviours;
}
public enum InterruptionSource
{
None,
Source,
Destination,
SourceThenDestination,
DestinationThenSource
}
[Serializable]
public class Layer : ILayer
{
[SerializeField]
private string name;
[SerializeField]
private string previousLayerName;
[SerializeField]
private StateMachine stateMachine;
[SerializeField]
private AvatarMask avatarMask;
[SerializeField]
private AnimatorLayerBlendingMode blendingMode;
[SerializeField]
private string syncedLayerName;
[SerializeField]
private bool iKPass;
[SerializeField]
private float defaultWeight;
[SerializeField]
private bool syncedLayerAffectsTiming;
[SerializeField]
private List<SyncedMotion> syncedMotions = new List<SyncedMotion>();
[SerializeField]
private List<SyncedBehaviour> syncedBehaviours = new List<SyncedBehaviour>();
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string PreviousLayerName
{
get
{
return previousLayerName;
}
set
{
previousLayerName = value;
}
}
public StateMachine StateMachine
{
get
{
return stateMachine;
}
set
{
stateMachine = value;
}
}
IStateMachine ILayer.StateMachine => stateMachine;
public AvatarMask AvatarMask
{
get
{
return avatarMask;
}
set
{
avatarMask = value;
}
}
public AnimatorLayerBlendingMode BlendingMode
{
get
{
return blendingMode;
}
set
{
blendingMode = value;
}
}
public string SyncedLayerName
{
get
{
return syncedLayerName;
}
set
{
syncedLayerName = value;
}
}
public bool IKPass
{
get
{
return iKPass;
}
set
{
iKPass = value;
}
}
public float DefaultWeight
{
get
{
return defaultWeight;
}
set
{
defaultWeight = value;
}
}
public bool SyncedLayerAffectsTiming
{
get
{
return syncedLayerAffectsTiming;
}
set
{
syncedLayerAffectsTiming = value;
}
}
public List<SyncedMotion> SyncedMotions => syncedMotions;
IReadOnlyList<ISyncedMotion> ILayer.SyncedMotions => syncedMotions;
public List<SyncedBehaviour> SyncedBehaviours => syncedBehaviours;
IReadOnlyList<ISyncedBehaviour> ILayer.SyncedBehaviours => syncedBehaviours;
}
[Serializable]
public class Parameter : IParameter
{
[SerializeField]
private string name;
[SerializeField]
private ParameterType type;
[SerializeField]
private ParameterValue value;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public ParameterType Type
{
get
{
return type;
}
set
{
type = value;
}
}
public ParameterValue Value
{
get
{
return value;
}
set
{
this.value = value;
}
}
}
public enum ParameterType
{
Float = 1,
Int = 3,
Bool = 4,
Trigger = 9
}
[Serializable]
public struct ParameterValue
{
[SerializeField]
private bool boolValue;
[SerializeField]
private float floatValue;
[SerializeField]
private int intValue;
public bool BoolValue
{
get
{
return boolValue;
}
set
{
boolValue = value;
}
}
public float FloatValue
{
get
{
return floatValue;
}
set
{
floatValue = value;
}
}
public int IntValue
{
get
{
return intValue;
}
set
{
intValue = value;
}
}
public ParameterValue(bool value)
{
boolValue = false;
floatValue = 0f;
intValue = 0;
BoolValue = value;
}
public ParameterValue(float value)
{
boolValue = false;
floatValue = 0f;
intValue = 0;
FloatValue = value;
}
public ParameterValue(int value)
{
boolValue = false;
floatValue = 0f;
intValue = 0;
IntValue = value;
}
public static implicit operator ParameterValue(bool value)
{
return new ParameterValue(value);
}
public static implicit operator ParameterValue(float value)
{
return new ParameterValue(value);
}
public static implicit operator ParameterValue(int value)
{
return new ParameterValue(value);
}
public static implicit operator bool(ParameterValue value)
{
return value.BoolValue;
}
public static implicit operator float(ParameterValue value)
{
return value.FloatValue;
}
public static implicit operator int(ParameterValue value)
{
return value.IntValue;
}
}
[Serializable]
public class State : IState, IMotion
{
[SerializeField]
private string name;
[SerializeField]
private AnimationClip clip;
[SerializeField]
private BlendTree blendTree;
[SerializeField]
private string tag;
[SerializeField]
private string speedParam;
[SerializeField]
private string mirrorParam;
[SerializeField]
private string cycleOffsetParam;
[SerializeField]
private string timeParam;
[SerializeField]
private float speed;
[SerializeField]
private float cycleOffset;
[SerializeField]
private bool ikOnFeet;
[SerializeField]
private bool writeDefaultValues;
[SerializeField]
private bool loop;
[SerializeField]
private bool mirror;
[SerializeField]
private List<Transition> transitions = new List<Transition>();
[SerializeField]
private List<StateMachineBehaviour> behaviours = new List<StateMachineBehaviour>();
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
[Obsolete("No longer required")]
public string ClipBundlePath
{
get
{
return "";
}
set
{
}
}
public AnimationClip Clip
{
get
{
return clip;
}
set
{
clip = value;
}
}
public BlendTree BlendTree
{
get
{
return blendTree;
}
set
{
blendTree = value;
}
}
IBlendTree IMotion.BlendTree => blendTree;
public string Tag
{
get
{
return tag;
}
set
{
tag = value;
}
}
public string SpeedParam
{
get
{
return speedParam;
}
set
{
speedParam = value;
}
}
public string MirrorParam
{
get
{
return mirrorParam;
}
set
{
mirrorParam = value;
}
}
public string CycleOffsetParam
{
get
{
return cycleOffsetParam;
}
set
{
cycleOffsetParam = value;
}
}
public string TimeParam
{
get
{
return timeParam;
}
set
{
timeParam = value;
}
}
public float Speed
{
get
{
return speed;
}
set
{
speed = value;
}
}
public float CycleOffset
{
get
{
return cycleOffset;
}
set
{
cycleOffset = value;
}
}
public bool IKOnFeet
{
get
{
return ikOnFeet;
}
set
{
ikOnFeet = value;
}
}
public bool WriteDefaultValues
{
get
{
return writeDefaultValues;
}
set
{
writeDefaultValues = value;
}
}
public bool Loop
{
get
{
return loop;
}
set
{
loop = value;
}
}
public bool Mirror
{
get
{
return mirror;
}
set
{
mirror = value;
}
}
public List<Transition> Transitions => transitions;
IReadOnlyList<ITransition> IState.Transitions => transitions;
public List<StateMachineBehaviour> Behaviours => behaviours;
IReadOnlyList<StateMachineBehaviour> IState.Behaviours => behaviours;
}
public class StateMachine : ScriptableObject, IStateMachine
{
[SerializeField]
private string defaultStateName;
[SerializeField]
private string defaultStateMachinePath;
[SerializeField]
private List<State> states = new List<State>();
[SerializeField]
private List<Transition> anyStateTransitions = new List<Transition>();
[SerializeField]
private List<EntryTransition> entryTransitions = new List<EntryTransition>();
[SerializeField]
private List<StateMachine> subStateMachines = new List<StateMachine>();
[SerializeField]
private List<StateMachineBehaviour> behaviours = new List<StateMachineBehaviour>();
public string Name
{
get
{
return ((Object)this).name;
}
set
{
((Object)this).name = value;
}
}
public string DefaultStateName
{
get
{
return defaultStateName;
}
set
{
defaultStateName = value;
}
}
public string DefaultStateMachinePath
{
get
{
return defaultStateMachinePath;
}
set
{
defaultStateMachinePath = value;
}
}
public List<State> States => states;
IReadOnlyList<IState> IStateMachine.States => states;
public List<Transition> AnyStateTransitions => anyStateTransitions;
IReadOnlyList<ITransition> IStateMachine.AnyStateTransitions => anyStateTransitions;
public List<EntryTransition> EntryTransitions => entryTransitions;
IReadOnlyList<ISimpleTransition> IStateMachine.EntryTransitions => entryTransitions;
public List<StateMachine> SubStateMachines => subStateMachines;
IReadOnlyList<IStateMachine> IStateMachine.SubStateMachines => subStateMachines;
public List<StateMachineBehaviour> Behaviours => behaviours;
IReadOnlyList<StateMachineBehaviour> IStateMachine.Behaviours => behaviours;
}
[Serializable]
public class SyncedBehaviour : ISyncedBehaviour
{
[SerializeField]
private string stateName;
[SerializeField]
private string stateMachinePath;
[SerializeField]
private List<StateMachineBehaviour> behaviours = new List<StateMachineBehaviour>();
public string StateName
{
get
{
return stateName;
}
set
{
stateName = value;
}
}
public string StateMachinePath
{
get
{
return stateMachinePath;
}
set
{
stateMachinePath = value;
}
}
public List<StateMachineBehaviour> Behaviours => behaviours;
IReadOnlyList<StateMachineBehaviour> ISyncedBehaviour.Behaviours => behaviours;
}
[Serializable]
public class SyncedMotion : ISyncedMotion, IMotion
{
[SerializeField]
private string stateName;
[SerializeField]
private string stateMachinePath;
[SerializeField]
private AnimationClip clip;
[SerializeField]
private BlendTree blendTree;
public string StateName
{
get
{
return stateName;
}
set
{
stateName = value;
}
}
public string StateMachinePath
{
get
{
return stateMachinePath;
}
set
{
stateMachinePath = value;
}
}
public AnimationClip Clip
{
get
{
return clip;
}
set
{
clip = value;
}
}
public BlendTree BlendTree
{
get
{
return blendTree;
}
set
{
blendTree = value;
}
}
IBlendTree IMotion.BlendTree => blendTree;
}
[Serializable]
public class Transition : ITransition, ISimpleTransition
{
[SerializeField]
private string destinationStateName;
[SerializeField]
private string destinationStateMachineName;
[SerializeField]
private float transitionDuration;
[SerializeField]
private float offset;
[SerializeField]
private float exitTime;
[SerializeField]
private bool hasExitTime;
[SerializeField]
private bool hasFixedDuration;
[SerializeField]
private InterruptionSource interruptionSource;
[SerializeField]
private bool orderedInterruption;
[SerializeField]
private bool canTransitionToSelf;
[SerializeField]
private bool isExit;
[SerializeField]
private List<Condition> conditions = new List<Condition>();
public string DestinationStateName
{
get
{
return destinationStateName;
}
set
{
destinationStateName = value;
}
}
public string DestinationStateMachinePath
{
get
{
return destinationStateMachineName;
}
set
{
destinationStateMachineName = value;
}
}
public float TransitionDuration
{
get
{
return transitionDuration;
}
set
{
transitionDuration = value;
}
}
public float Offset
{
get
{
return offset;
}
set
{
offset = value;
}
}
public float ExitTime
{
get
{
return exitTime;
}
set
{
exitTime = value;
}
}
public bool HasExitTime
{
get
{
return hasExitTime;
}
set
{
hasExitTime = value;
}
}
public bool HasFixedDuration
{
get
{
return hasFixedDuration;
}
set
{
hasFixedDuration = value;
}
}
public InterruptionSource InterruptionSource
{
get
{
return interruptionSource;
}
set
{
interruptionSource = value;
}
}
public bool OrderedInterruption
{
get
{
return orderedInterruption;
}
set
{
orderedInterruption = value;
}
}
public bool CanTransitionToSelf
{
get
{
return canTransitionToSelf;
}
set
{
canTransitionToSelf = value;
}
}
public bool IsExit
{
get
{
return isExit;
}
set
{
isExit = value;
}
}
public List<Condition> Conditions => conditions;
IReadOnlyList<ICondition> ISimpleTransition.Conditions => conditions;
}
}using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Microsoft.CodeAnalysis;
using R2API.Models;
using UnityEditor;
using UnityEditor.Animations;
using UnityEditor.AssetImporters;
using UnityEditor.Callbacks;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.Animations.Editor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4c3fa0aa1bf06bccbf6fd22f858a2b3d0c968b1c")]
[assembly: AssemblyProduct("R2API.Animations.Editor")]
[assembly: AssemblyTitle("R2API.Animations.Editor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}
namespace R2API.Animations.Editor
{
[ScriptedImporter(2, "controllerdiff", 1000)]
public class AnimatorDiffImporter : ScriptedImporter
{
private class CreateEmptyAsset : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
File.WriteAllText(pathName, "");
AssetDatabase.ImportAsset(pathName);
Selection.activeObject = AssetDatabase.LoadAssetAtPath<Object>(pathName);
((EndNameEditAction)this).CleanUp();
}
}
private const string extension = "controllerdiff";
private const string extensionWithDot = ".controllerdiff";
private const string copyButtonName = "Copy AnimatorController for modification";
private const string copyButtonPath = "Assets/R2API/Animation/Copy AnimatorController for modification";
[SerializeField]
[HideInInspector]
[Obsolete]
private AnimatorController sourceController;
[SerializeField]
[HideInInspector]
[Obsolete]
private AnimatorController modifiedController;
public string modifiedControllerGuid;
[MenuItem("Assets/Create/R2API/Animation/AnimatorDiff", false, -1000)]
public static void CreateDiff()
{
string text = AssetDatabase.GetAssetPath(Selection.activeObject);
if (text == "")
{
text = "Assets";
}
else if (Path.GetExtension(text) != "")
{
text = text.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
string text2 = AssetDatabase.GenerateUniqueAssetPath(text + "/New Animator Diff.controllerdiff");
CreateEmptyAsset createEmptyAsset = ScriptableObject.CreateInstance<CreateEmptyAsset>();
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, (EndNameEditAction)(object)createEmptyAsset, text2, (Texture2D)null, (string)null);
}
[MenuItem("Assets/R2API/Animation/Copy AnimatorController for modification", true, 19)]
public static bool ValidateCreateCopyController()
{
if (Selection.count == 1)
{
return Selection.activeObject is AnimatorController;
}
return false;
}
[MenuItem("Assets/R2API/Animation/Copy AnimatorController for modification", false, 19)]
public static void CreateCopyController()
{
Object activeObject = Selection.activeObject;
AnimatorController val = (AnimatorController)(object)((activeObject is AnimatorController) ? activeObject : null);
string assetPath = AssetDatabase.GetAssetPath((Object)(object)val);
string text = Path.Combine(Path.GetDirectoryName(assetPath), ((Object)val).name + "_modified.controller");
text = AssetDatabase.GenerateUniqueAssetPath(text);
AssetDatabase.CopyAsset(assetPath, text);
AnimatorController val2 = AssetDatabase.LoadAssetAtPath<AnimatorController>(text);
AnimatorMap animatorMap = ScriptableObject.CreateInstance<AnimatorMap>();
((Object)animatorMap).name = ((Object)val2).name + "_map";
animatorMap.sourceController = val;
((Object)animatorMap).hideFlags = (HideFlags)8;
FillMap(animatorMap, val, val2);
AssetDatabase.AddObjectToAsset((Object)(object)animatorMap, (Object)(object)val2);
AssetDatabase.SaveAssets();
Undo.RegisterCreatedObjectUndo((Object)(object)val2, "CreateCopyController");
Selection.activeObject = (Object)(object)val2;
}
private static void FillMap(AnimatorMap map, AnimatorController source, AnimatorController target)
{
for (int i = 0; i < source.layers.Length; i++)
{
FillMap(map, source.layers[i].stateMachine, target.layers[i].stateMachine);
}
}
private static void FillMap(AnimatorMap map, AnimatorStateMachine source, AnimatorStateMachine target)
{
for (int i = 0; i < source.entryTransitions.Length; i++)
{
map.sourceObjects.Add((Object)(object)source.entryTransitions[i]);
map.modifiedObjects.Add((Object)(object)target.entryTransitions[i]);
}
for (int j = 0; j < source.anyStateTransitions.Length; j++)
{
map.sourceObjects.Add((Object)(object)source.anyStateTransitions[j]);
map.modifiedObjects.Add((Object)(object)target.anyStateTransitions[j]);
}
for (int k = 0; k < source.states.Length; k++)
{
FillMap(map, ((ChildAnimatorState)(ref source.states[k])).state, ((ChildAnimatorState)(ref target.states[k])).state);
}
for (int l = 0; l < source.stateMachines.Length; l++)
{
FillMap(map, ((ChildAnimatorStateMachine)(ref source.stateMachines[l])).stateMachine, ((ChildAnimatorStateMachine)(ref target.stateMachines[l])).stateMachine);
}
for (int m = 0; m < source.behaviours.Length; m++)
{
map.sourceObjects.Add((Object)(object)source.behaviours[m]);
map.modifiedObjects.Add((Object)(object)target.behaviours[m]);
}
}
private static void FillMap(AnimatorMap map, AnimatorState source, AnimatorState target)
{
for (int i = 0; i < source.transitions.Length; i++)
{
map.sourceObjects.Add((Object)(object)source.transitions[i]);
map.modifiedObjects.Add((Object)(object)target.transitions[i]);
}
for (int j = 0; j < source.behaviours.Length; j++)
{
map.sourceObjects.Add((Object)(object)source.behaviours[j]);
map.modifiedObjects.Add((Object)(object)target.behaviours[j]);
}
}
[OnOpenAsset]
public static bool PreventDiffDoubleClick(int instanceID, int line)
{
return Path.GetExtension(AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID))).ToLower() == ".controllerdiff";
}
public void OnValidate()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
string text = default(string);
long num = default(long);
if (Object.op_Implicit((Object)(object)modifiedController) && AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)modifiedController, ref text, ref num))
{
modifiedControllerGuid = text;
modifiedController = null;
}
if (Object.op_Implicit((Object)(object)sourceController))
{
Object obj = AssetDatabase.LoadMainAssetAtGUID(new GUID(modifiedControllerGuid));
AnimatorController val = (AnimatorController)(object)((obj is AnimatorController) ? obj : null);
if (Object.op_Implicit((Object)(object)AssetDatabase.LoadAssetAtPath<AnimatorMap>(AssetDatabase.GetAssetPath((Object)(object)val))))
{
sourceController = null;
return;
}
AnimatorMap animatorMap = ScriptableObject.CreateInstance<AnimatorMap>();
((Object)animatorMap).name = ((Object)val).name + "_map";
animatorMap.sourceController = sourceController;
((Object)animatorMap).hideFlags = (HideFlags)8;
FillMap(animatorMap, sourceController, val);
sourceController = null;
AssetDatabase.AddObjectToAsset((Object)(object)animatorMap, (Object)(object)val);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
public override void OnImportAsset(AssetImportContext ctx)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Expected O, but got Unknown
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Expected O, but got Unknown
if (string.IsNullOrEmpty(modifiedControllerGuid))
{
return;
}
Object obj = AssetDatabase.LoadMainAssetAtGUID(new GUID(modifiedControllerGuid));
AnimatorController val = (AnimatorController)(object)((obj is AnimatorController) ? obj : null);
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
AnimatorMap animatorMap = AssetDatabase.LoadAssetAtPath<AnimatorMap>(AssetDatabase.GetAssetPath((Object)(object)val));
if (!Object.op_Implicit((Object)(object)animatorMap))
{
ctx.LogImportError("Modified controller is missing AnimatorMap, you should use \"Copy AnimatorController for modification\" button to create modified controller from an AnimatorController", (Object)(object)val);
return;
}
AnimatorController val2 = animatorMap.sourceController;
if (!Object.op_Implicit((Object)(object)val2))
{
return;
}
Dictionary<Object, Object> stateParents = new Dictionary<Object, Object>();
AnimatorControllerLayer[] layers = val.layers;
foreach (AnimatorControllerLayer val3 in layers)
{
if (val3.syncedLayerIndex == -1)
{
WriteParents(val3.stateMachine, stateParents);
}
}
AnimatorDiff val4 = ScriptableObject.CreateInstance<AnimatorDiff>();
Dictionary<ScriptableObject, string> dictionary = new Dictionary<ScriptableObject, string>();
for (int j = 0; j < val.layers.Length; j++)
{
AnimatorControllerLayer modifiedLayer = val.layers[j];
AnimatorControllerLayer val5 = ((IEnumerable<AnimatorControllerLayer>)val2.layers).FirstOrDefault((Func<AnimatorControllerLayer, bool>)((AnimatorControllerLayer l) => l.name == modifiedLayer.name));
if (val5 != null)
{
ExistingStateMachine val6 = ((modifiedLayer.syncedLayerIndex != -1) ? null : ConvertExistingStateMachine(modifiedLayer.stateMachine, val5.stateMachine, animatorMap, dictionary, stateParents));
List<SyncedBehaviour> list = new List<SyncedBehaviour>();
StateBehavioursPair[] behaviours = modifiedLayer.m_Behaviours;
foreach (StateBehavioursPair behaviour in behaviours)
{
SyncedBehaviour val7 = ConvertSyncedBehaviour(behaviour, animatorMap, stateParents);
if (val7 != null)
{
list.Add(val7);
}
}
if ((Object)(object)val6 != (Object)null || list.Count > 0)
{
ExistingLayer val8 = new ExistingLayer
{
Name = modifiedLayer.name,
StateMachine = val6
};
val8.NewSyncedBehaviours.AddRangeNotNull(list);
val4.Layers.Add(val8);
}
}
else
{
string previousLayerName = ((j == 0) ? null : val.layers[j - 1].name);
val4.NewLayers.Add(ConvertLayer(modifiedLayer, val, animatorMap, dictionary, stateParents, previousLayerName));
}
}
AnimatorControllerParameter[] parameters = val.parameters;
foreach (AnimatorControllerParameter parameter in parameters)
{
if (!val2.parameters.Any((AnimatorControllerParameter p) => p.name != parameter.name))
{
List<Parameter> newParameters = val4.NewParameters;
Parameter val9 = new Parameter
{
Name = parameter.name,
Type = (ParameterType)parameter.type
};
ParameterValue value = default(ParameterValue);
((ParameterValue)(ref value)).IntValue = parameter.defaultInt;
((ParameterValue)(ref value)).BoolValue = parameter.defaultBool;
((ParameterValue)(ref value)).FloatValue = parameter.defaultFloat;
val9.Value = value;
newParameters.Add(val9);
}
}
string text = (((Object)val4).name = Path.GetFileNameWithoutExtension(ctx.assetPath));
ctx.AddObjectToAsset(text, (Object)(object)val4);
string text2 = default(string);
long num = default(long);
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)val2, ref text2, ref num))
{
ctx.DependsOnSourceAsset(new GUID(text2));
}
ctx.DependsOnSourceAsset(new GUID(modifiedControllerGuid));
foreach (var (val11, text4) in dictionary)
{
((Object)val11).hideFlags = (HideFlags)1;
ctx.AddObjectToAsset(text4, (Object)(object)val11);
}
}
private void WriteParents(AnimatorStateMachine stateMachine, Dictionary<Object, Object> stateParents)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
ChildAnimatorState[] states = stateMachine.states;
for (int i = 0; i < states.Length; i++)
{
ChildAnimatorState val = states[i];
stateParents[(Object)(object)((ChildAnimatorState)(ref val)).state] = (Object)(object)stateMachine;
}
ChildAnimatorStateMachine[] stateMachines = stateMachine.stateMachines;
for (int i = 0; i < stateMachines.Length; i++)
{
ChildAnimatorStateMachine val2 = stateMachines[i];
stateParents[(Object)(object)((ChildAnimatorStateMachine)(ref val2)).stateMachine] = (Object)(object)stateMachine;
WriteParents(((ChildAnimatorStateMachine)(ref val2)).stateMachine, stateParents);
}
}
private Layer ConvertLayer(AnimatorControllerLayer layer, AnimatorController controller, AnimatorMap map, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents, string previousLayerName)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
Layer val = new Layer
{
Name = layer.name,
PreviousLayerName = previousLayerName,
AvatarMask = layer.avatarMask,
BlendingMode = (AnimatorLayerBlendingMode)layer.blendingMode,
DefaultWeight = layer.defaultWeight,
IKPass = layer.iKPass,
SyncedLayerAffectsTiming = layer.syncedLayerAffectsTiming,
SyncedLayerName = ((layer.syncedLayerIndex != -1) ? controller.layers[layer.syncedLayerIndex].name : null),
StateMachine = ((layer.syncedLayerIndex == -1) ? ConvertStateMachine(layer.stateMachine, extraObjects, stateParents) : null)
};
StateMotionPair[] motions = layer.m_Motions;
foreach (StateMotionPair state in motions)
{
val.SyncedMotions.Add(ConvertSyncedMotion(state, extraObjects, stateParents));
}
StateBehavioursPair[] behaviours = layer.m_Behaviours;
foreach (StateBehavioursPair behaviour in behaviours)
{
SyncedBehaviour val2 = ConvertSyncedBehaviour(behaviour, map, stateParents);
if (val2 != null)
{
val.SyncedBehaviours.Add(val2);
}
}
return val;
}
private SyncedBehaviour ConvertSyncedBehaviour(StateBehavioursPair behaviour, AnimatorMap map, Dictionary<Object, Object> stateParents)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
List<StateMachineBehaviour> list = new List<StateMachineBehaviour>();
ScriptableObject[] behaviours = behaviour.m_Behaviours;
foreach (ScriptableObject val in behaviours)
{
StateMachineBehaviour val2 = (StateMachineBehaviour)(object)((val is StateMachineBehaviour) ? val : null);
if (val2 != null && !map.modifiedObjects.Contains((Object)(object)val))
{
list.Add(val2);
}
}
if (list.Count == 0)
{
return null;
}
SyncedBehaviour val3 = new SyncedBehaviour();
AnimatorState state = behaviour.m_State;
val3.StateName = ((state != null) ? ((Object)state).name : null);
val3.StateMachinePath = GetStateMachinePath(behaviour.m_State, null, stateParents);
val3.Behaviours.AddRangeNotNull(list);
return val3;
}
private SyncedMotion ConvertSyncedMotion(StateMotionPair state, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
SyncedMotion val = new SyncedMotion();
AnimatorState state2 = state.m_State;
val.StateName = ((state2 != null) ? ((Object)state2).name : null);
val.StateMachinePath = GetStateMachinePath(state.m_State, null, stateParents);
SyncedMotion val2 = val;
Motion motion = state.m_Motion;
AnimationClip val3 = (AnimationClip)(object)((motion is AnimationClip) ? motion : null);
if (val3 != null)
{
val2.Clip = val3;
}
else
{
Motion motion2 = state.m_Motion;
BlendTree val4 = (BlendTree)(object)((motion2 is BlendTree) ? motion2 : null);
if (val4 != null)
{
val2.BlendTree = ConvertBlendTree(val4, extraObjects);
}
}
return val2;
}
private ExistingStateMachine ConvertExistingStateMachine(AnimatorStateMachine stateMachine, AnimatorStateMachine sourceStateMachine, AnimatorMap map, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents)
{
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
List<State> list = new List<State>();
List<ExistingState> list2 = new List<ExistingState>();
List<Transition> list3 = new List<Transition>();
List<StateMachine> list4 = new List<StateMachine>();
List<EntryTransition> list5 = new List<EntryTransition>();
List<ExistingStateMachine> list6 = new List<ExistingStateMachine>();
List<StateMachineBehaviour> list7 = new List<StateMachineBehaviour>();
StateMachineBehaviour[] behaviours = stateMachine.behaviours;
foreach (StateMachineBehaviour val in behaviours)
{
if (!map.modifiedObjects.Contains((Object)(object)val))
{
list7.AddNotNull(ConvertBehaviour(val, extraObjects));
}
}
bool anySolo = stateMachine.anyStateTransitions.Any((AnimatorStateTransition t) => ((AnimatorTransitionBase)t).solo);
AnimatorStateTransition[] anyStateTransitions = stateMachine.anyStateTransitions;
foreach (AnimatorStateTransition val2 in anyStateTransitions)
{
if (!map.modifiedObjects.Contains((Object)(object)val2))
{
list3.AddNotNull(ConvertStateTransition(val2, stateParents, anySolo));
}
}
AnimatorTransition[] entryTransitions = stateMachine.entryTransitions;
foreach (AnimatorTransition val3 in entryTransitions)
{
if (!map.modifiedObjects.Contains((Object)(object)val3))
{
list5.AddNotNull(ConvertEntryTransition(val3, stateParents));
}
}
string arg = default(string);
long num = default(long);
foreach (AnimatorStateMachine subStateMachine in stateMachine.stateMachines.Select((ChildAnimatorStateMachine t) => ((ChildAnimatorStateMachine)(ref t)).stateMachine))
{
AnimatorStateMachine val4 = sourceStateMachine.stateMachines.Select((ChildAnimatorStateMachine t) => ((ChildAnimatorStateMachine)(ref t)).stateMachine).FirstOrDefault((Func<AnimatorStateMachine, bool>)((AnimatorStateMachine t) => ((Object)t).name == ((Object)subStateMachine).name));
if (Object.op_Implicit((Object)(object)val4))
{
ExistingStateMachine val5 = ConvertExistingStateMachine(subStateMachine, val4, map, extraObjects, stateParents);
if (Object.op_Implicit((Object)(object)val5))
{
((Object)val5).name = ((Object)subStateMachine).name;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)subStateMachine, ref arg, ref num);
extraObjects[(ScriptableObject)(object)val5] = $"{arg}_{num}";
list6.AddNotNull(val5);
}
}
else
{
list4.AddNotNull(ConvertStateMachine(subStateMachine, extraObjects, stateParents));
}
}
ChildAnimatorState[] states = stateMachine.states;
for (int i = 0; i < states.Length; i++)
{
ChildAnimatorState val6 = states[i];
AnimatorState state = ((ChildAnimatorState)(ref val6)).state;
ChildAnimatorState val7 = ((IEnumerable<ChildAnimatorState>)sourceStateMachine.states).FirstOrDefault((Func<ChildAnimatorState, bool>)((ChildAnimatorState s) => ((Object)((ChildAnimatorState)(ref s)).state).name == ((Object)state).name));
if (Object.op_Implicit((Object)(object)((ChildAnimatorState)(ref val7)).state))
{
ExistingState val8 = ConvertExistingState(state, map, extraObjects, stateParents);
if (val8 != null)
{
list2.Add(val8);
}
}
else
{
list.Add(ConvertState(state, extraObjects, stateParents));
}
}
if (list.Count > 0 || list2.Count > 0 || list5.Count > 0 || list3.Count > 0 || list6.Count > 0 || list4.Count > 0 || list7.Count > 0)
{
ExistingStateMachine val9 = ScriptableObject.CreateInstance<ExistingStateMachine>();
string arg2 = default(string);
long num2 = default(long);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)stateMachine, ref arg2, ref num2);
extraObjects[(ScriptableObject)(object)val9] = $"{arg2}_{num2}";
((Object)val9).name = ((Object)stateMachine).name;
val9.NewStates.AddRange(list);
val9.NewAnyStateTransitions.AddRange(list3);
val9.NewEntryTransitions.AddRange(list5);
val9.SubStateMachines.AddRange(list6);
val9.NewSubStateMachines.AddRange(list4);
val9.NewBehaviours.AddRange(list7);
val9.States.AddRange(list2);
return val9;
}
return null;
}
private StateMachineBehaviour ConvertBehaviour(StateMachineBehaviour behaviour, Dictionary<ScriptableObject, string> extraObjects)
{
StateMachineBehaviour val = Object.Instantiate<StateMachineBehaviour>(behaviour);
((Object)val).name = ((Object)behaviour).name;
string arg = default(string);
long num = default(long);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)behaviour, ref arg, ref num);
extraObjects[(ScriptableObject)(object)val] = $"{arg}_{num}";
return val;
}
private ExistingState ConvertExistingState(AnimatorState state, AnimatorMap map, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents)
{
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Expected O, but got Unknown
List<Transition> list = new List<Transition>();
List<StateMachineBehaviour> list2 = new List<StateMachineBehaviour>();
bool anySolo = state.transitions.Any((AnimatorStateTransition t) => ((AnimatorTransitionBase)t).solo);
AnimatorStateTransition[] transitions = state.transitions;
foreach (AnimatorStateTransition val in transitions)
{
if (!map.modifiedObjects.Contains((Object)(object)val))
{
list.AddNotNull(ConvertStateTransition(val, stateParents, anySolo));
}
}
StateMachineBehaviour[] behaviours = state.behaviours;
foreach (StateMachineBehaviour val2 in behaviours)
{
if (!map.modifiedObjects.Contains((Object)(object)val2))
{
list2.AddNotNull(ConvertBehaviour(val2, extraObjects));
}
}
if (list.Count > 0 || list2.Count > 0)
{
ExistingState val3 = new ExistingState
{
Name = ((Object)state).name
};
val3.NewTransitions.AddRange(list);
val3.NewBehaviours.AddRange(list2);
return val3;
}
return null;
}
private State ConvertState(AnimatorState state, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
State val = new State
{
Name = ((Object)state).name,
IKOnFeet = state.iKOnFeet,
Tag = state.tag,
WriteDefaultValues = state.writeDefaultValues
};
Motion motion = state.motion;
AnimationClip val2 = (AnimationClip)(object)((motion is AnimationClip) ? motion : null);
if (val2 != null)
{
val.Clip = val2;
val.Loop = ((Motion)val2).isLooping;
}
else
{
Motion motion2 = state.motion;
BlendTree val3 = (BlendTree)(object)((motion2 is BlendTree) ? motion2 : null);
if (val3 != null)
{
val.BlendTree = ConvertBlendTree(val3, extraObjects);
val.Loop = ((Motion)val3).isLooping;
}
else
{
val.Loop = true;
}
}
val.CycleOffset = state.cycleOffset;
if (state.cycleOffsetParameterActive)
{
val.CycleOffsetParam = state.cycleOffsetParameter;
}
val.Mirror = state.mirror;
if (state.mirrorParameterActive)
{
val.MirrorParam = state.mirrorParameter;
}
val.Speed = state.speed;
if (state.speedParameterActive)
{
val.SpeedParam = state.speedParameter;
}
if (state.timeParameterActive)
{
val.TimeParam = state.timeParameter;
}
bool anySolo = state.transitions.Any((AnimatorStateTransition t) => ((AnimatorTransitionBase)t).solo);
for (int i = 0; i < state.transitions.Length; i++)
{
AnimatorStateTransition transition = state.transitions[i];
val.Transitions.AddNotNull(ConvertStateTransition(transition, stateParents, anySolo));
}
for (int j = 0; j < state.behaviours.Length; j++)
{
StateMachineBehaviour behaviour = state.behaviours[j];
val.Behaviours.AddNotNull(ConvertBehaviour(behaviour, extraObjects));
}
return val;
}
private StateMachine ConvertStateMachine(AnimatorStateMachine stateMachine, Dictionary<ScriptableObject, string> extraObjects, Dictionary<Object, Object> stateParents)
{
Dictionary<ScriptableObject, string> extraObjects2 = extraObjects;
Dictionary<Object, Object> stateParents2 = stateParents;
StateMachine val = ScriptableObject.CreateInstance<StateMachine>();
((Object)val).name = ((Object)stateMachine).name;
string arg = default(string);
long num = default(long);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)stateMachine, ref arg, ref num);
extraObjects2[(ScriptableObject)(object)val] = $"{arg}_{num}";
AnimatorState defaultState = stateMachine.defaultState;
val.DefaultStateName = ((defaultState != null) ? ((Object)defaultState).name : null);
val.DefaultStateMachinePath = GetStateMachinePath(stateMachine.defaultState, null, stateParents2);
if (stateMachine.states != null)
{
val.States.AddRange(stateMachine.states.Select((ChildAnimatorState s) => ConvertState(((ChildAnimatorState)(ref s)).state, extraObjects2, stateParents2)));
}
if (stateMachine.stateMachines != null)
{
val.SubStateMachines.AddRange(stateMachine.stateMachines.Select((ChildAnimatorStateMachine s) => ConvertStateMachine(((ChildAnimatorStateMachine)(ref s)).stateMachine, extraObjects2, stateParents2)));
}
if (stateMachine.anyStateTransitions != null)
{
bool anySolo = stateMachine.anyStateTransitions.Any((AnimatorStateTransition t) => ((AnimatorTransitionBase)t).solo);
val.AnyStateTransitions.AddRangeNotNull(stateMachine.anyStateTransitions.Select((AnimatorStateTransition t) => ConvertStateTransition(t, stateParents2, anySolo)));
}
if (stateMachine.entryTransitions != null)
{
val.EntryTransitions.AddRangeNotNull(stateMachine.entryTransitions.Select((AnimatorTransition t) => ConvertEntryTransition(t, stateParents2)));
}
if (stateMachine.behaviours != null)
{
val.Behaviours.AddRangeNotNull(stateMachine.behaviours.Select((StateMachineBehaviour t) => ConvertBehaviour(t, extraObjects2)));
}
return val;
}
private EntryTransition ConvertEntryTransition(AnimatorTransition transition, Dictionary<Object, Object> stateParents)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
EntryTransition val = new EntryTransition();
AnimatorState destinationState = ((AnimatorTransitionBase)transition).destinationState;
val.DestinationStateName = ((destinationState != null) ? ((Object)destinationState).name : null);
EntryTransition val2 = val;
val2.DestinationStateMachinePath = GetStateMachinePath(((AnimatorTransitionBase)transition).destinationState, ((AnimatorTransitionBase)transition).destinationStateMachine, stateParents);
AnimatorCondition[] conditions = ((AnimatorTransitionBase)transition).conditions;
foreach (AnimatorCondition condition in conditions)
{
val2.Conditions.Add(ConvertCondition(condition));
}
return val2;
}
private BlendTree ConvertBlendTree(BlendTree blendTree, Dictionary<ScriptableObject, string> extraObjects)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
Dictionary<ScriptableObject, string> extraObjects2 = extraObjects;
BlendTree val = ScriptableObject.CreateInstance<BlendTree>();
((Object)val).name = ((Object)blendTree).name;
string arg = default(string);
long num = default(long);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)blendTree, ref arg, ref num);
extraObjects2[(ScriptableObject)(object)val] = $"{arg}_{num}";
val.BlendParameter = blendTree.blendParameter;
val.BlendParameterY = blendTree.blendParameterY;
val.BlendType = (BlendTreeType)blendTree.blendType;
if (blendTree.children != null)
{
val.Children.AddRangeNotNull(blendTree.children.Select((ChildMotion c) => ConvertChildMotion(c, extraObjects2)));
}
return val;
}
private ChildMotion ConvertChildMotion(ChildMotion childMotion, Dictionary<ScriptableObject, string> extraObjects)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
ChildMotion val = new ChildMotion
{
DirectBlendParameter = ((ChildMotion)(ref childMotion)).directBlendParameter,
Mirror = ((ChildMotion)(ref childMotion)).mirror,
Position = ((ChildMotion)(ref childMotion)).position,
Threshold = ((ChildMotion)(ref childMotion)).threshold,
TimeScale = ((ChildMotion)(ref childMotion)).timeScale
};
Motion motion = ((ChildMotion)(ref childMotion)).motion;
AnimationClip val2 = (AnimationClip)(object)((motion is AnimationClip) ? motion : null);
if (val2 != null)
{
val.Clip = val2;
}
else
{
Motion motion2 = ((ChildMotion)(ref childMotion)).motion;
BlendTree val3 = (BlendTree)(object)((motion2 is BlendTree) ? motion2 : null);
if (val3 != null)
{
val.BlendTree = ConvertBlendTree(val3, extraObjects);
}
}
return val;
}
private Transition ConvertStateTransition(AnimatorStateTransition transition, Dictionary<Object, Object> stateParents, bool anySolo)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
if (((AnimatorTransitionBase)transition).mute || (anySolo && !((AnimatorTransitionBase)transition).solo))
{
return null;
}
Transition val = new Transition();
AnimatorState destinationState = ((AnimatorTransitionBase)transition).destinationState;
val.DestinationStateName = ((destinationState != null) ? ((Object)destinationState).name : null);
val.ExitTime = transition.exitTime;
val.HasExitTime = transition.hasExitTime;
val.HasFixedDuration = transition.hasFixedDuration;
val.Offset = transition.offset;
val.TransitionDuration = transition.duration;
val.InterruptionSource = (InterruptionSource)transition.interruptionSource;
val.CanTransitionToSelf = transition.canTransitionToSelf;
val.OrderedInterruption = transition.orderedInterruption;
val.IsExit = ((AnimatorTransitionBase)transition).isExit;
Transition val2 = val;
val2.DestinationStateMachinePath = GetStateMachinePath(((AnimatorTransitionBase)transition).destinationState, ((AnimatorTransitionBase)transition).destinationStateMachine, stateParents);
AnimatorCondition[] conditions = ((AnimatorTransitionBase)transition).conditions;
foreach (AnimatorCondition condition in conditions)
{
val2.Conditions.Add(ConvertCondition(condition));
}
return val2;
}
private string GetStateMachinePath(AnimatorState state, AnimatorStateMachine stateMachine, Dictionary<Object, Object> stateParents)
{
Object val = null;
if (Object.op_Implicit((Object)(object)state))
{
val = stateParents[(Object)(object)state];
}
else if (Object.op_Implicit((Object)(object)stateMachine))
{
val = (Object)(object)stateMachine;
}
string result = null;
if (Object.op_Implicit(val))
{
List<Object> list = new List<Object>();
do
{
list.Add(val);
val = stateParents.GetValueOrDefault(val);
}
while (Object.op_Implicit(val));
list.Reverse();
result = string.Join(".", list.Select((Object p) => p.name));
}
return result;
}
private Condition ConvertCondition(AnimatorCondition condition)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
return new Condition
{
ConditionMode = (ConditionMode)((AnimatorCondition)(ref condition)).mode,
ParamName = ((AnimatorCondition)(ref condition)).parameter,
Value = ((AnimatorCondition)(ref condition)).threshold
};
}
}
[CustomEditor(typeof(AnimatorDiffImporter))]
public class AnimatorDiffImporterEditor : ScriptedImporterEditor
{
private SerializedProperty modifiedControllerProperty;
public override Type extraDataType => typeof(AnimatorDiffImporterExtra);
public override void InitializeExtraDataInstance(Object extraData, int targetIndex)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
AnimatorDiffImporterExtra animatorDiffImporterExtra = extraData as AnimatorDiffImporterExtra;
AnimatorDiffImporter animatorDiffImporter = ((Editor)this).targets[targetIndex] as AnimatorDiffImporter;
if (!string.IsNullOrEmpty(animatorDiffImporter.modifiedControllerGuid))
{
ref AnimatorController modifiedController = ref animatorDiffImporterExtra.modifiedController;
Object obj = AssetDatabase.LoadMainAssetAtGUID(new GUID(animatorDiffImporter.modifiedControllerGuid));
modifiedController = (AnimatorController)(object)((obj is AnimatorController) ? obj : null);
}
else
{
animatorDiffImporterExtra.modifiedController = null;
}
}
public override void OnEnable()
{
((AssetImporterEditor)this).OnEnable();
modifiedControllerProperty = ((SerializedObject)((AssetImporterEditor)this).extraDataSerializedObject).FindProperty("modifiedController");
}
public override bool CanOpenMultipleObjects()
{
return false;
}
public override void OnInspectorGUI()
{
((AssetImporterEditor)this).extraDataSerializedObject.Update();
EditorGUILayout.PropertyField(modifiedControllerProperty, Array.Empty<GUILayoutOption>());
((SerializedObject)((AssetImporterEditor)this).extraDataSerializedObject).ApplyModifiedPropertiesWithoutUndo();
((AssetImporterEditor)this).ApplyRevertGUI();
}
public override void Apply()
{
SerializedProperty val = ((Editor)this).serializedObject.FindProperty("modifiedControllerGuid");
string stringValue = default(string);
long num = default(long);
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier((Object)(object)(((AssetImporterEditor)this).extraDataTarget as AnimatorDiffImporterExtra).modifiedController, ref stringValue, ref num))
{
val.stringValue = stringValue;
}
else
{
val.stringValue = null;
}
((AssetImporterEditor)this).Apply();
}
}
public class AnimatorDiffImporterExtra : ScriptableObject
{
public AnimatorController modifiedController;
}
public class AnimatorMap : ScriptableObject
{
public AnimatorController sourceController;
public List<Object> sourceObjects = new List<Object>();
public List<Object> modifiedObjects = new List<Object>();
}
public static class Extensions
{
public static void AddNotNull<T>(this List<T> list, T value) where T : class
{
if (value != null)
{
list.Add(value);
}
}
public static void AddRangeNotNull<T>(this List<T> list, IEnumerable<T> values) where T : class
{
list.AddRange(values.Where((T v) => v != null));
}
}
}