Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
Added OnEchanting Event
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed May 17, 2020
1 parent 336b62f commit 18a3bf1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
15 changes: 10 additions & 5 deletions UtilityLibrary.Test/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ protected override bool Initialize(bool loadedAny)
if (!utilityLibrary.IsInitialized) return false;
if (!loadedAny) return false;

Events.OnCrafting.Register(e =>
{
Utils.Log($"Crafting an item: {e.TemperForm.CreatedItem.Name}, getting {e.XP} XP");
});

Events.OnTempering.Register(e =>
{
Utils.Log(
$"Tempering {e.Item.Name}, old quality: {e.OldQuality}, new quality: {e.NewQuality}, getting {e.XP} XP");
});

Events.OnEnchanting.Register(e =>
{
Utils.Log($"Enchanting {e.Item.Name}, soul gem: {e.SoulGem.Name}, xp: {e.XP}");
});

/*Events.OnCrafting.Register(e =>
{
Utils.Log($"Crafting an item: {e.TemperForm.CreatedItem.Name}, getting {e.XP} XP");
});*/

return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion UtilityLibrary.Test/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class Utils
static Utils()
{
//optional to also use LogFileFlags.IncludeTimestampInFileName
LogFile = new LogFile(global::UtilityLibrary.Plugin.PluginName, LogFileFlags.AppendFile | LogFileFlags.AutoFlush | LogFileFlags.IncludeTimestampInLine);
LogFile = new LogFile(Plugin.PluginName, LogFileFlags.AppendFile | LogFileFlags.AutoFlush | LogFileFlags.IncludeTimestampInLine);
}

internal static void Log(string s)
Expand Down
2 changes: 2 additions & 0 deletions UtilityLibrary/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public static partial class Events
public static Event<TemperingEventArgs> OnTempering { get; internal set; }

public static Event<CraftingEventArgs> OnCrafting { get; internal set; }

public static Event<EnchantingEventArgs> OnEnchanting { get; internal set; }
}
}
32 changes: 32 additions & 0 deletions UtilityLibrary/Events/OnEnchantingEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NetScriptFramework;
using NetScriptFramework.SkyrimSE;

namespace UtilityLibrary
{
public static partial class Events
{
public class EnchantingEventArgs : HookedEventArgs
{
public TESForm Item { get; internal set; }
public TESForm SoulGem { get; internal set; }
public float XP { get; set; }
}

internal static EventHookParameters<EnchantingEventArgs> EnchantingEventHookParameters =>
new EventHookParameters<EnchantingEventArgs>(AddressLibrary.Enchanting, 6, 6, "FF 90 B8 07 00 00", ctx =>
{
var args = new EnchantingEventArgs
{
Item = MemoryObject.FromAddress<TESForm>(Memory.ReadPointer(ctx.R15)),
SoulGem = MemoryObject.FromAddress<TESForm>(
Memory.ReadPointer(Memory.ReadPointer(ctx.BX + 0x18))),
XP = ctx.XMM2f
};
return args;
}, (ctx, args) =>
{
ctx.XMM2f = args.XP;
});
}
}
3 changes: 2 additions & 1 deletion UtilityLibrary/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected override bool Initialize(bool loadedAny)
AddressLibrary.Alchemy = Main.GameInfo.GetAddressOf(50449, 0x207, 6);

Events.OnTempering = new EventHook<Events.TemperingEventArgs>(EventHookFlags.None, "utility-library.events.tempering", Events.TemperingEventHookParameters);
Events.OnCrafting = new EventHook<Events.CraftingEventArgs>(EventHookFlags.None, "utility-library.events.crafting", Events.CraftingEventHookParameters);
//Events.OnCrafting = new EventHook<Events.CraftingEventArgs>(EventHookFlags.None, "utility-library.events.crafting", Events.CraftingEventHookParameters);
Events.OnEnchanting = new EventHook<Events.EnchantingEventArgs>(EventHookFlags.None, "utility-library.events.enchanting", Events.EnchantingEventHookParameters);

NetScriptFramework.SkyrimSE.Events.OnMainMenu.Register(e =>
{
Expand Down
1 change: 1 addition & 0 deletions UtilityLibrary/UtilityLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="AddressLibrary.cs" />
<Compile Include="Events.cs" />
<Compile Include="Events\OnCraftingEvent.cs" />
<Compile Include="Events\OnEnchantingEvent.cs" />
<Compile Include="Events\OnTemperingEvent.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 18a3bf1

Please sign in to comment.