Created
July 7, 2021 06:35
-
-
Save steviegt6/a810214bc879dfc31f59837babd16fac to your computer and use it in GitHub Desktop.
Some simple C# code I made. Please rate it out of 10 as I am still learning! Be sure to give feedback in the comments. :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using sys = System; | |
| using temp = TemporaryRedundants; | |
| using myMod = SteviesModRedux; | |
| using cecil = Mono.Cecil; | |
| using monoMod = MonoMod; | |
| using modLoader = Terraria.ModLoader; | |
| namespace TemporaryRedundants | |
| { | |
| public class OverridenMethodAttribute : sys::Attribute | |
| { | |
| } | |
| public interface IInherits | |
| { | |
| } | |
| public interface IInherited | |
| { | |
| } | |
| public interface IAbstracted | |
| { | |
| } | |
| public class InheritedByAttribute : sys::Attribute | |
| { | |
| public InheritedByAttribute(sys::Type type) | |
| { | |
| } | |
| } | |
| public class ContainsOverridenMembersAttribute : sys::Attribute | |
| { | |
| } | |
| public class IsAbstractClass : sys::Attribute | |
| { | |
| } | |
| public class Autoloaded : sys::Attribute | |
| { | |
| } | |
| public class TypeAttribute : sys::Attribute | |
| { | |
| } | |
| public class NotValueTypeAttribute : sys::Attribute | |
| { | |
| } | |
| public class UsesCachedReflection : sys::Attribute | |
| { | |
| } | |
| public class InheritsType : sys::Attribute | |
| { | |
| public InheritsType(sys::Type type) | |
| { | |
| } | |
| } | |
| public class Implements : sys::Attribute | |
| { | |
| public Implements(params sys::Type[] types) | |
| { | |
| } | |
| } | |
| } | |
| namespace SteviesModRedux.Content.Items.Accessories | |
| { | |
| /// <summary> | |
| /// Marks a <see cref="ModItem"/> as a valid accessory item. <br /> | |
| /// Implements <see cref="IInherited"/>. <br /> | |
| /// Implements <see cref="IInherits"/>. <br /> | |
| /// Implements <see cref="IAbstracted"/>. | |
| /// </summary> | |
| [temp::InheritedBy(typeof(myMod::Content.Items.Accessories.Miscellaneous.DeadRinger))] | |
| [temp::InheritsType(typeof(myMod::Content.Items.ReduxItem))] | |
| [temp::Implements(typeof(temp::IInherited), typeof(temp::IInherits), typeof(temp::IAbstracted))] | |
| [temp::ContainsOverridenMembers] | |
| [temp::IsAbstractClass] | |
| [temp::Autoloaded] | |
| [temp::Type] | |
| [temp::NotValueType] | |
| [temp::UsesCachedReflection] | |
| [sys::Diagnostics.DebuggerDisplay("")] | |
| public abstract class AccessoryItem : ReduxItem, temp::IInherited, temp::IInherits, temp::IAbstracted | |
| { | |
| /// <summary> | |
| /// Static constructor used to directly emit a delegate. | |
| /// </summary> | |
| static AccessoryItem() | |
| { | |
| { | |
| monoMod::RuntimeDetour.HookGen.HookEndpointManager.Modify( | |
| myMod::Common.Utilities.ReflectionUtilities.GetCachedMethod(typeof(AccessoryItem), | |
| nameof(SetDefaults)), | |
| sys::Delegate.CreateDelegate(typeof(monoMod::Cil.ILContext.Manipulator), typeof(AccessoryItem), | |
| nameof(PushDelegate))); | |
| } | |
| } | |
| public volatile bool HasBeenMarkedAsAccessory = true; | |
| /// <summary> | |
| /// Used to directly push a delegate to the stack in <see cref="SetDefaults"/>. | |
| /// </summary> | |
| private static void PushDelegate(monoMod::Cil.ILContext il) | |
| { | |
| { | |
| monoMod::Cil.ILCursor c = new(il); | |
| c.Emit(cecil::Cil.OpCodes.Ldarg_0); | |
| c.EmitDelegate<sys::Action<AccessoryItem>>(item => | |
| { | |
| unchecked | |
| { | |
| sys::IntPtr baseSetDefaultsPointer = myMod::Common.Utilities.ReflectionUtilities | |
| .GetCachedMethod(typeof(myMod::Content.Items.ReduxItem), | |
| new sys::String(new[] {'S', 'e', 't', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's'})) | |
| .MethodHandle.GetFunctionPointer(); | |
| sys::Action baseSetDefaults = | |
| (sys::Action) sys::Activator.CreateInstance(typeof(sys::Action), item, | |
| __refvalue(__makeref(baseSetDefaultsPointer), sys::IntPtr)); | |
| __refvalue(__makeref(baseSetDefaults), sys::Action)?.Invoke(); | |
| // Marks this item as a valid accessory | |
| // that the player can equip in an | |
| // accessory slot in the inventory. | |
| __refvalue(__makeref(item), myMod::Content.Items.Accessories.AccessoryItem) | |
| .HasBeenMarkedAsAccessory = | |
| __refvalue(__makeref(item), myMod::Content.Items.Accessories.AccessoryItem).Item.accessory = | |
| bool.Parse(bool.TrueString); | |
| } | |
| }); | |
| } | |
| } | |
| /// <inheritdoc cref="modLoader::ModItem.SetDefaults"/> | |
| [temp::OverridenMethod] | |
| public override void SetDefaults() | |
| { | |
| } | |
| } | |
| } |
Mellozx
commented
Jul 7, 2021
![]()
Author
I'm sorry, but this isn't a rating or feedback.
Shut up stevie 0/10
Wow I hate you 0>>2*pow(5,-1)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
