mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-03 04:34:26 -07:00
update MeatKit (9a1a68ab68cd0650227af944ffa30d1166b9e056)
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: c7e21420a1d84ca5947b2fd9eb9db6d8
|
||||
timeCreated: 1628213934
|
||||
timeCreated: 1649523855
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MeatKit
|
||||
{
|
||||
[CreateAssetMenu(menuName = "MeatKit/Assembly Editors/Path Replacer", fileName = "New Path Replacer")]
|
||||
public class CreatePathModifier : AssemblyModifier
|
||||
{
|
||||
[Tooltip("The new path replacements")]
|
||||
public ReplacementPath[] ReplacementPaths = new ReplacementPath[0];
|
||||
|
||||
public override void ApplyModification(AssemblyDefinition assembly)
|
||||
{
|
||||
TypeReference stringRef = assembly.MainModule.TypeSystem.String;
|
||||
TypeReference intRef = assembly.MainModule.TypeSystem.Int32;
|
||||
if (stringRef == null || intRef == null) return;
|
||||
|
||||
foreach (ReplacementPath replacementPath in ReplacementPaths)
|
||||
{
|
||||
TypeReference type = assembly.MainModule.GetType(replacementPath.ScriptableObjectName);
|
||||
if (type == null) continue;
|
||||
|
||||
TypeDefinition definition = type.Resolve();
|
||||
CustomAttribute createMenuAttribute = GetCreateAssetMenuAttribute(definition);
|
||||
|
||||
if (createMenuAttribute == null)
|
||||
{
|
||||
Debug.LogWarning("Could not get CreateAssetMenuAttribute for scriptable object: " + replacementPath.ScriptableObjectName);
|
||||
continue;
|
||||
}
|
||||
|
||||
CustomAttributeArgument pathArgumentValue = new CustomAttributeArgument(stringRef, replacementPath.NewPath);
|
||||
CustomAttributeArgument fileNameArgumentValue = new CustomAttributeArgument(stringRef, replacementPath.NewDefaultName);
|
||||
CustomAttributeArgument orderArgumentValue = new CustomAttributeArgument(intRef, replacementPath.NewOrder);
|
||||
|
||||
CustomAttributeNamedArgument pathArgument = new CustomAttributeNamedArgument("menuName", pathArgumentValue);
|
||||
CustomAttributeNamedArgument fileNameArgument = new CustomAttributeNamedArgument("fileName", fileNameArgumentValue);
|
||||
CustomAttributeNamedArgument orderArgument = new CustomAttributeNamedArgument("order", orderArgumentValue);
|
||||
|
||||
createMenuAttribute.Properties.Clear();
|
||||
createMenuAttribute.Properties.Add(pathArgument);
|
||||
createMenuAttribute.Properties.Add(fileNameArgument);
|
||||
createMenuAttribute.Properties.Add(orderArgument);
|
||||
}
|
||||
|
||||
Applied = true;
|
||||
}
|
||||
|
||||
private CustomAttribute GetCreateAssetMenuAttribute(TypeDefinition definition)
|
||||
{
|
||||
CustomAttribute[] foundAttributes = definition.CustomAttributes.Where(ca => ca.AttributeType.FullName.Contains("CreateAssetMenuAttribute")).ToArray();
|
||||
|
||||
if(foundAttributes.Length > 0)
|
||||
{
|
||||
return foundAttributes[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public struct ReplacementPath
|
||||
{
|
||||
[Tooltip("Specify the FULL NAME of the scriptable object you wish to modify. e.g. Sub.Namespace.Type")]
|
||||
public string ScriptableObjectName;
|
||||
|
||||
[Tooltip("The new create asset path of the scriptable object")]
|
||||
public string NewPath;
|
||||
|
||||
[Tooltip("The new default name of the scriptable object when created")]
|
||||
public string NewDefaultName;
|
||||
|
||||
[Tooltip("The new ordering of the scriptable object in menu")]
|
||||
public int NewOrder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6389bd26f6b33074ba8afe182d11c33d
|
||||
timeCreated: 1649523850
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -18,8 +19,28 @@ namespace MeatKit
|
||||
|
||||
public override void ApplyModification(AssemblyDefinition assembly)
|
||||
{
|
||||
// Try to get this type from the assembly. If it doesn't exist, we can just skip.
|
||||
TypeReference type = assembly.MainModule.GetType(EnumName);
|
||||
// Try to get the enum type. If it contains a '+' in the name, it's nested and we have to do a bit of extra stuff
|
||||
TypeDefinition type;
|
||||
if (EnumName.Contains("+"))
|
||||
{
|
||||
|
||||
string[] parts = EnumName.Split('+');
|
||||
type = assembly.MainModule.GetType(parts[0]);
|
||||
if (type != null)
|
||||
{
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
Debug.Log(type);
|
||||
type = type.NestedTypes.FirstOrDefault(x => x.Name == parts[i]);
|
||||
if (type == null) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise we can just grab it directly if it isn't nested
|
||||
else type = assembly.MainModule.GetType(EnumName);
|
||||
|
||||
// If we can't find the type, skip.
|
||||
if (type == null) return;
|
||||
|
||||
var definition = type.Resolve();
|
||||
|
||||
+11
-2
@@ -1,3 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: 486e27304e8449efb6c6136482952c4d
|
||||
timeCreated: 1628213734
|
||||
timeCreated: 1649523858
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -12,8 +12,10 @@ namespace MeatKit
|
||||
"FistVR.FireArmRoundType",
|
||||
"FistVR.FireArmRoundClass",
|
||||
"FistVR.FireArmMagazineType",
|
||||
"FistVR.ItemSpawnerObjectDefinition.ItemSpawnerCategory",
|
||||
"FistVR.SosigEnemyID"
|
||||
"FistVR.ItemSpawnerObjectDefinition+ItemSpawnerCategory",
|
||||
"FistVR.SosigEnemyID",
|
||||
"FistVR.FVRFireArmAttachementMountType",
|
||||
"FistVR.FireArmClipType"
|
||||
};
|
||||
|
||||
private SerializedProperty _addedValues;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: 4980597d341c4eed913ae30680f3f9f3
|
||||
timeCreated: 1628218472
|
||||
timeCreated: 1649523860
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
Reference in New Issue
Block a user