private static void init() { if (Allocation != null) { return; } Allocation = Memory.Allocate(0x90); TempPoint1 = MemoryObject.FromAddress <NiPoint3>(Allocation.Address); TempPoint2 = MemoryObject.FromAddress <NiPoint3>(Allocation.Address + 0x10); TempNormal = MemoryObject.FromAddress <NiPoint3>(Allocation.Address + 0x20); TempSafety = MemoryObject.FromAddress <NiPoint3>(Allocation.Address + 0x30); TempTransform = MemoryObject.FromAddress <NiTransform>(Allocation.Address + 0x40); TempTransform.Scale = 1.0f; TempSafety.X = 0.0f; TempSafety.Y = 0.0f; TempSafety.Z = 0.0f; SetupRaycastMask(new[] { CollisionLayers.AnimStatic, CollisionLayers.Biped, CollisionLayers.CharController, //CollisionLayers.Clutter, CollisionLayers.DebrisLarge, CollisionLayers.Ground, //CollisionLayers.Props, CollisionLayers.Static, CollisionLayers.Terrain, CollisionLayers.Trap, CollisionLayers.Trees, CollisionLayers.Unidentified }); }
internal void Initialize() { var alloc = Memory.Allocate(0x110); alloc.Pin(); this.TargetMarkerPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address); this.TargetTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x10); this.AimVectorPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x20); this.SourceTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x30); this.CurrentTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x40); this.AimVectorPointDoubled = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x50); this.ThirdPersonTempTransform = MemoryObject.FromAddress <NiTransform>(alloc.Address + 0x60); this.SourceMovePoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x100); this.AimVectorPoint.X = 0.0f; this.AimVectorPoint.Z = 0.0f; this.AimVectorPoint.Y = Math.Max(100.0f, Math.Min(8000.0f, this.Plugin.Settings.MaxDistance)); this.AimVectorPointDoubled.X = 0.0f; this.AimVectorPointDoubled.Z = 0.0f; this.AimVectorPointDoubled.Y = 2000.0f + Math.Max(100.0f, Math.Min(8000.0f, this.Plugin.Settings.MaxDistance)); this.fn_Actor_SetPosition = NetScriptFramework.Main.GameInfo.GetAddressOf(36319); this.fn_BGSSoundDescriptor_PlaySound = NetScriptFramework.Main.GameInfo.GetAddressOf(32301); this.fn_TESImageSpaceModifier_Apply = NetScriptFramework.Main.GameInfo.GetAddressOf(18185); this.fn_FlashHudMeter = NetScriptFramework.Main.GameInfo.GetAddressOf(51907); this.fn_GetMagicFailedMessage = NetScriptFramework.Main.GameInfo.GetAddressOf(11295); /*var cost = this.Plugin.Settings.MagickaCost; * if (cost > 0.0f) * { * var spell = this.Plugin.Settings.SpellForm; * if (spell != null) * { * var effectItem = Memory.ReadPointer(spell.Address + 0x58); * if (effectItem != IntPtr.Zero) * { * effectItem = Memory.ReadPointer(effectItem); * if (effectItem != IntPtr.Zero) * { * var effect = MemoryObject.FromAddress<EffectSetting>(Memory.ReadPointer(effectItem + 0x10)); * if (effect != null) * Memory.WriteFloat(effect.Address + 0x6C, cost); * * Memory.WriteFloat(effectItem + 0x18, cost); * } * } * * Memory.WriteInt32(spell.Address + 0xC0, (int)(cost + 0.1f)); * } * }*/ }
protected override void Free() { if (Main.IsShutdown) { return; } Transform = null; if (Allocation != null) { Allocation.Dispose(); Allocation = null; } }
protected override void Free() { if (NetScriptFramework.Main.IsShutdown) { return; } this.Transform = null; if (this.Allocation != null) { this.Allocation.Dispose(); this.Allocation = null; } }
private void ApplyPositionOffset(NiTransform transform, float x, float y, float z, NiPoint3 result) { if (x == 0.0f && y == 0.0f && z == 0.0f) { var tpos = transform.Position; if (!result.Equals(tpos)) { result.CopyFrom(tpos); } return; } var pos = this.TempResult.Transform.Position; pos.X = x; pos.Y = y; pos.Z = z; transform.Translate(pos, result); }
internal bool Get(NiAVObject root, NiTransform result) { if (this.NeedRecalculate) { this.Recalculate(); this.NeedRecalculate = false; } if (this.LastCalculated == null) { return(false); } root.WorldTransform.Rotation.GetEulerAngles(this.TempPoint); float angle = this.TempPoint.Z; this.TempPoint.X = this.LastCalculated.Position[0]; this.TempPoint.Y = this.LastCalculated.Position[1]; this.TempPoint.Z = this.LastCalculated.Position[2]; float len = this.TempPoint.Length; if (len > 0.0f) { this.TempPoint.Normalize(this.TempPoint); } var tpos = this.TempTransform.Position; tpos.X = 0.0f; tpos.Y = 0.0f; tpos.Z = 0.0f; this.TempTransform.LookAt(this.TempPoint); this.TempTransform.Rotation.RotateZ(-angle, this.TempTransform.Rotation); this.TempPoint.X = 0.0f; this.TempPoint.Y = len; this.TempPoint.Z = 0.0f; this.TempTransform.Translate(this.TempPoint, this.TempPoint); var pos = result.Position; var spos = root.WorldTransform.Position; pos.X = spos.X + this.TempPoint.X; pos.Y = spos.Y + this.TempPoint.Y; pos.Z = spos.Z + this.TempPoint.Z; root.WorldTransform.Rotation.GetEulerAngles(this.TempPoint); float y = (float)Utility.ClampToPi(this.TempPoint.X + this.LastCalculated.OffsetY); float x = (float)Utility.ClampToPi(this.TempPoint.Z + this.LastCalculated.OffsetX); var rot = result.Rotation; rot.Identity(1.0f); if (y != 0.0f) { rot.RotateX(y, rot); } if (x != 0.0f) { rot.RotateZ(-x, rot); } return(true); }
internal void Initialize() { if (this.Marker == null && !this.TriedToLoadMarker) { this.TriedToLoadMarker = true; NiObject.LoadFromFileAsync(new NiObjectLoadParameters() { Callback = p => { if (p.Success) { var obj = p.Result[0].As <NiAVObject>(); if (obj != null) { this.Marker = obj; this.Marker.IncRef(); this.Marker.LocalTransform.Scale = this.Plugin.Settings.MarkerScale; } } }, Count = 1, FileName = this.Plugin.Settings.MarkerNif }); } var alloc = Memory.Allocate(0x110); alloc.Pin(); this.TargetMarkerPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address); this.TargetTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x10); this.AimVectorPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x20); this.SourceTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x30); this.CurrentTeleportPoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x40); this.AimVectorPointDoubled = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x50); this.ThirdPersonTempTransform = MemoryObject.FromAddress <NiTransform>(alloc.Address + 0x60); this.SourceMovePoint = MemoryObject.FromAddress <NiPoint3>(alloc.Address + 0x100); this.AimVectorPoint.X = 0.0f; this.AimVectorPoint.Z = 0.0f; this.AimVectorPoint.Y = Math.Max(100.0f, Math.Min(8000.0f, this.Plugin.Settings.MaxDistance)); this.AimVectorPointDoubled.X = 0.0f; this.AimVectorPointDoubled.Z = 0.0f; this.AimVectorPointDoubled.Y = 2000.0f + Math.Max(100.0f, Math.Min(8000.0f, this.Plugin.Settings.MaxDistance)); // Setup GameOffset - Updated PrepareFunction & InstallHook to take this value, I didn't update directly incase some use a different Offset. int GameOffset = 0x0; // Everything is based from 1_5_62 var GameVersion = NetScriptFramework.Main.Game.GameVersion; // Get the game version if (GameVersion[0] == 1 && GameVersion[1] == 5 && GameVersion[2] >= 73 && GameVersion[2] <= 97) { GameOffset = 0x1F0; // Check for game version 1_5_73 to 1_5_97, update GameOffset } var debug = CrashLog.Debug; DebugInfo.DebugFunctionInfo fn = null; if (debug == null || (fn = debug.GetFunctionInfo(36319)) == null) { throw new InvalidOperationException(this.Plugin.Name + " can't work without a debug library!"); } this.fn_Actor_SetPosition = new IntPtr(((long)(debug.BaseOffset + fn.Begin) - (uint)GameOffset)); fn = debug.GetFunctionInfo(32301); if (fn != null) { this.fn_BGSSoundDescriptor_PlaySound = new IntPtr(((long)(debug.BaseOffset + fn.Begin) - (uint)GameOffset)); } fn = debug.GetFunctionInfo(18185); if (fn != null) { this.fn_TESImageSpaceModifier_Apply = new IntPtr(((long)(debug.BaseOffset + fn.Begin) - (uint)GameOffset)); } fn = debug.GetFunctionInfo(51907); if (fn != null) { this.fn_FlashHudMeter = new IntPtr(((long)(debug.BaseOffset + fn.Begin) - (uint)GameOffset)); } fn = debug.GetFunctionInfo(11295); if (fn != null) { this.fn_GetMagicFailedMessage = new IntPtr(((long)(debug.BaseOffset + fn.Begin) - (uint)GameOffset)); } /*var cost = this.Plugin.Settings.MagickaCost; * if (cost > 0.0f) * { * var spell = this.Plugin.Settings.SpellForm; * if (spell != null) * { * var effectItem = Memory.ReadPointer(spell.Address + 0x58); * if (effectItem != IntPtr.Zero) * { * effectItem = Memory.ReadPointer(effectItem); * if (effectItem != IntPtr.Zero) * { * var effect = MemoryObject.FromAddress<EffectSetting>(Memory.ReadPointer(effectItem + 0x10)); * if (effect != null) * Memory.WriteFloat(effect.Address + 0x6C, cost); * * Memory.WriteFloat(effectItem + 0x18, cost); * } * } * * Memory.WriteInt32(spell.Address + 0xC0, (int)(cost + 0.1f)); * } * }*/ }
internal bool Get(NiAVObject root, NiTransform result) { if (NeedRecalculate) { Recalculate(); NeedRecalculate = false; } if (LastCalculated == null) { return(false); } root.WorldTransform.Rotation.GetEulerAngles(TempPoint); var angle = TempPoint.Z; TempPoint.X = LastCalculated.Position[0]; TempPoint.Y = LastCalculated.Position[1]; TempPoint.Z = LastCalculated.Position[2]; var len = TempPoint.Length; if (len > 0.0f) { TempPoint.Normalize(TempPoint); } var tpos = TempTransform.Position; tpos.X = 0.0f; tpos.Y = 0.0f; tpos.Z = 0.0f; TempTransform.LookAt(TempPoint); TempTransform.Rotation.RotateZ(-angle, TempTransform.Rotation); TempPoint.X = 0.0f; TempPoint.Y = len; TempPoint.Z = 0.0f; TempTransform.Translate(TempPoint, TempPoint); var pos = result.Position; var spos = root.WorldTransform.Position; pos.X = spos.X + TempPoint.X; pos.Y = spos.Y + TempPoint.Y; pos.Z = spos.Z + TempPoint.Z; root.WorldTransform.Rotation.GetEulerAngles(TempPoint); var y = (float)Utility.ClampToPi(TempPoint.X + LastCalculated.OffsetY); var x = (float)Utility.ClampToPi(TempPoint.Z + LastCalculated.OffsetX); var rot = result.Rotation; rot.Identity(1.0f); if (y != 0.0f) { rot.RotateX(y, rot); } if (x != 0.0f) { rot.RotateZ(-x, rot); } return(true); }
internal static void CopyFrom(this NiTransform pt, NiTransform other) { Memory.Copy(other.Address, pt.Address, 0x34); }
internal static bool Apply(CameraUpdate update, NiTransform transform, NiPoint3 result) { init(); if (update == null || transform == null || result == null) { return(false); } if (update.Values.CollisionEnabled.CurrentValue < 0.5) { return(false); } var actor = update.Target.Actor; if (actor == null) { return(false); } var cell = actor.ParentCell; if (cell == null) { return(false); } float safety = (float)(update.Values.NearClip.CurrentValue + 1.0); if (safety < 1.0f) { safety = 1.0f; } float safety2 = Math.Max(0.0f, Settings.Instance.CameraCollisionSafety); var tpos = transform.Position; TempPoint1.CopyFrom(actor.Position); TempPoint1.Z = tpos.Z; if (safety2 > 0.0f) { TempSafety.Y = -safety2 * 0.5f; TempTransform.CopyFrom(transform); TempTransform.Position.CopyFrom(TempPoint1); TempTransform.Translate(TempSafety, TempPoint1); } TempNormal.X = tpos.X - TempPoint1.X; TempNormal.Y = tpos.Y - TempPoint1.Y; TempNormal.Z = tpos.Z - TempPoint1.Z; float len = TempNormal.Length; if (len <= 0.0f) { return(false); } TempNormal.Normalize(TempNormal); TempNormal.Multiply(len + safety + safety2, TempNormal); TempPoint2.X = TempPoint1.X + TempNormal.X; TempPoint2.Y = TempPoint1.Y + TempNormal.Y; TempPoint2.Z = TempPoint1.Z + TempNormal.Z; var ls = TESObjectCELL.RayCast(new RayCastParameters() { Cell = cell, Begin = new float[] { TempPoint1.X, TempPoint1.Y, TempPoint1.Z }, End = new float[] { TempPoint2.X, TempPoint2.Y, TempPoint2.Z } }); if (ls == null || ls.Count == 0) { return(false); } RayCastResult best = null; float bestDist = 0.0f; List <NiAVObject> ignore = new List <NiAVObject>(3); { var sk = actor.GetSkeletonNode(true); if (sk != null) { ignore.Add(sk); } } { var sk = actor.GetSkeletonNode(false); if (sk != null) { ignore.Add(sk); } } if (update.CachedMounted) { var mount = actor.GetMount(); if (mount != null) { var sk = mount.GetSkeletonNode(false); if (sk != null) { ignore.Add(sk); } } } foreach (var r in ls) { if (!IsValid(r, ignore)) { continue; } float dist = r.Fraction; if (best == null) { best = r; bestDist = dist; } else if (dist < bestDist) { best = r; bestDist = dist; } } if (best == null) { return(false); } bestDist *= len + safety + safety2; bestDist -= safety + safety2; bestDist /= len + safety + safety2; // Negative is ok! result.X = (TempPoint2.X - TempPoint1.X) * bestDist + TempPoint1.X; result.Y = (TempPoint2.Y - TempPoint1.Y) * bestDist + TempPoint1.Y; result.Z = (TempPoint2.Z - TempPoint1.Z) * bestDist + TempPoint1.Z; return(true); }