private IEnumerator PlayOrder() { //if we have gone through whole order then bail out of function if (m_GameOrderIndex >= m_GameOrder.Length) { m_GameOrderIndex = 0; StopCoroutine(PlayOrder()); m_OrderIsBeingShown = false; yield break; } //player is able to see object MemoryObject currentMem = GetMemoryObject(m_GameOrderIndex); SetLitObject(currentMem, true); yield return(new WaitForSeconds(m_TimeToSeeMemory)); //player not able to see memory SetLitObject(currentMem, false); yield return(new WaitForSeconds(m_TimeBetweenMemory)); //increment to next object in order m_GameOrderIndex++; StartCoroutine(PlayOrder()); }
/// <summary> /// Reads the specified memory object associated with this command queue. /// </summary> /// <param name="memoryObject">The memory object that is to be read.</param> /// <param name="outputSize">The number of array elements that are to be returned.</param> /// <typeparam name="T">The type of the array that is to be returned.</typeparam> /// <returns>Returns the value of the memory object.</param> public void EnqueueWriteBuffer <T>(MemoryObject memoryObject, T[] value) where T : struct { // Tries to read the memory object GCHandle h = GCHandle.Alloc(value, GCHandleType.Pinned); IntPtr resultValuePointer = h.AddrOfPinnedObject(); try { // Allocates enough memory for the result value int size = Marshal.SizeOf <T>() * value.Length; // Reads the memory object, by enqueuing the read operation to the command queue IntPtr waitEventPointer; Result result = EnqueuedCommandsNativeApi.EnqueueWriteBuffer(Handle, memoryObject.Handle, 1, UIntPtr.Zero, new UIntPtr((uint)size), resultValuePointer, 0, null, out waitEventPointer); // Checks if the read operation was queued successfuly, if not, an exception is thrown if (result != Result.Success) { throw new OpenClException("The memory object could not be written to.", result); } } finally { // Finally the allocated memory has to be freed if (resultValuePointer != IntPtr.Zero) { h.Free(); } } }
internal CameraStabilize(CameraMain cameraMain, CameraTarget target) { if (cameraMain == null) { throw new ArgumentNullException("cameraMain"); } if (target == null) { throw new ArgumentNullException("target"); } this.CameraMain = cameraMain; if (Allocation == null) { Allocation = Memory.Allocate(0x60); } this.TempPoint = MemoryObject.FromAddress <NiPoint3>(Allocation.Address); this.TempTransform = MemoryObject.FromAddress <NiTransform>(Allocation.Address + 0x10); this.TempTransform.Scale = 1.0f; this.TweenPoint = MemoryObject.FromAddress <NiPoint3>(Allocation.Address + 0x50); this.ForTarget = this.GetFromTarget(target); }
/// <summary> /// Attempt to perform a dynamic cast on an object. This will throw an exception if source or target type is unsupported /// or if the RTTI cast function has not been set up! /// </summary> /// <param name="obj">The object.</param> /// <param name="target">Type of object to cast to.</param> /// <returns></returns> internal static IVirtualObject DynamicCast(IVirtualObject obj, Type target) { if (obj == null || obj.Address == IntPtr.Zero) { return(null); } if (target == typeof(IVirtualObject)) { return(obj); } // Get target RTTI. There may be more than one if we combined types. Tuple <Type, uint[], IntPtr> targetInfo; { if (!MapInterface.TryGetValue(target, out targetInfo)) { throw new NotSupportedException("Missing RTTI type descriptor for target \"" + target.Name + "\"!"); } } // Try multiple RTTI addresses. foreach (var ip in targetInfo.Item2) { var result = Custom_RTTI_Cast(obj.Address, ip, targetInfo.Item3); if (result != IntPtr.Zero) { return((IVirtualObject)MemoryObject.FromAddress(target, result)); } } // None matched or didn't have any in the list. return(null); }
private static void _Hook_Disenchanting(CPURegisters ctx) { var item = MemoryObject.FromAddress <TESForm>(Memory.ReadPointer(ctx.R14)); var enchantment = MemoryObject.FromAddress <EffectSetting>(ctx.SI); float skill = 5.0f; var plr = PlayerCharacter.Instance; if (plr != null) { skill = plr.GetActorValue(ActorValueIndices.Enchanting); } float enchantmentValue = Memory.InvokeCdeclF(fn_Disenchant, enchantment.Address, 0); float xp = Formula_Disenchanting(Math.Max(0, item.GoldValue), enchantmentValue, skill); if (xp < 0.0f) { xp = 0.0f; } if (Settings.DebugMode > 0) { WriteToDebugFile("Disenchanting: original XP was " + ctx.XMM2f.ToString(System.Globalization.CultureInfo.InvariantCulture) + " and we replaced it with " + xp.ToString(System.Globalization.CultureInfo.InvariantCulture)); } ctx.XMM2f = xp; }
/// <summary> /// Calculate size of type. /// </summary> /// <typeparam name="T">Type of value.</typeparam> /// <param name="forceStruct">If set to <c>true</c> then force handling type as structure instead of pointer, otherwise decide based on type.</param> /// <returns></returns> public static int SizeOf <T>(bool forceStruct) { var t = typeof(T); var a = t; // Enum is special case, get underlying type instead. if (t.IsEnum) { a = t.UnderlyingSystemType; } // Have registered handler. { Func <bool, int> func = null; if (SizeOfType.TryGetValue(a, out func)) { return(func(forceStruct)); } } // Maybe it's memory type. if (typeof(IMemoryObject).IsAssignableFrom(t)) { // Memory types are always by pointer unless we specifically ask otherwise. if (!forceStruct) { return(Main.Is64Bit ? 8 : 4); } return(MemoryObject.SizeOf(t)); } // Type does not have a handler. throw new ArgumentException("Specified type does not have a generic handler!", "T"); }
/// <summary> /// Sets the specified argument to the specified value. /// </summary> /// <param name="index">The index of the parameter.</param> /// <param name="memoryObject">The memory object that contains the value to which the kernel argument is to be set.</param> public void SetKernelArgument(int index, MemoryObject memoryObject) { // Checks if the index is positive, if not, then an exception is thrown if (index < 0) { throw new IndexOutOfRangeException($"The specified index {index} is invalid. The index of the argument must always be greater or equal to 0."); } // The set kernel argument method needs a pointer to the pointer, therefore the pointer is pinned, so that the garbage collector can not move it in memory GCHandle garbageCollectorHandle = GCHandle.Alloc(memoryObject.Handle, GCHandleType.Pinned); try { // Sets the kernel argument and checks if it was successful, if not, then an exception is thrown Result result = KernelsNativeApi.SetKernelArgument(this.Handle, (uint)index, new UIntPtr((uint)Marshal.SizeOf(memoryObject.Handle)), garbageCollectorHandle.AddrOfPinnedObject()); if (result != Result.Success) { throw new OpenClException($"The kernel argument with the index {index} could not be set.", result); } } finally { garbageCollectorHandle.Free(); } }
private bool Begin() { IntPtr cellPtr; Memory.InvokeCdecl(GidFileGenerationTask.addr_EnterLock); try { cellPtr = Memory.InvokeCdecl(GidFileGenerationTask.addr_WSLoadCellByCoordinates, this.Parent.WorldSpace.Cast <NetScriptFramework.SkyrimSE.TESWorldSpace>(), this.X, this.Y); } catch { GidFileGenerationTask.KillProcess(); return(false); } finally { Memory.InvokeCdecl(GidFileGenerationTask.addr_ExitLock); } if (cellPtr == IntPtr.Zero) { return(false); } this.Cell = MemoryObject.FromAddress <NetScriptFramework.SkyrimSE.TESObjectCELL>(cellPtr); if (this.Cell == null) { throw new NullReferenceException("this.Cell"); } return(true); }
private void LoadSystemInformation() { MemoryObject sysInfoMo = this._mfs.RootObject.GetChild("SystemInformation"); if (sysInfoMo == null) { PhUtils.ShowWarning("The dump file does not contain system information. This most likely " + "means the file is corrupt."); return; } IDictionary <string, string> dict = Dump.GetDictionary(sysInfoMo); sysInfoMo.Dispose(); _phVersion = dict["ProcessHackerVersion"]; _osVersion = dict["OSVersion"]; _architecture = (OSArch)Dump.ParseInt32(dict["Architecture"]); _userName = dict["UserName"]; treeProcesses.DumpUserName = _userName; this.Text = "Process Hacker " + _phVersion + " [" + _userName + "] (" + _osVersion + ", " + (_architecture == OSArch.I386 ? "32-bit" : "64-bit") + ")"; }
public void EnqueueWriteBuffer <T>(MemoryObject memoryObject, T[] buffer, int length) { #if UNSAFE switch (buffer) { case long[] longArray: unsafe { fixed(long *longPtr = longArray) { Result result = EnqueuedCommandsNativeApi.EnqueueWriteBuffer(this.Handle, memoryObject.Handle, 1, new UIntPtr(0), new UIntPtr((uint)(length * Marshal.SizeOf <T>())), (IntPtr)((void *)longPtr), 0, null, out IntPtr waitEventPointer); // Checks if the read operation was queued successfuly, if not, an exception is thrown if (result != Result.Success) { throw new OpenClException("The memory object could not be read.", result); } } } break; default: byte[] tempBuffer = new byte[length * Marshal.SizeOf <T>()]; Buffer.BlockCopy(buffer, 0, tempBuffer, 0, tempBuffer.Length); IntPtr bufferPtr = Marshal.AllocHGlobal(tempBuffer.Length); try { Marshal.Copy(tempBuffer, 0, bufferPtr, tempBuffer.Length); Result result = EnqueuedCommandsNativeApi.EnqueueWriteBuffer(this.Handle, memoryObject.Handle, 1, new UIntPtr(0), new UIntPtr((uint)tempBuffer.Length), bufferPtr, 0, null, out IntPtr waitEventPointer); // Checks if the read operation was queued successfuly, if not, an exception is thrown if (result != Result.Success) { throw new OpenClException("The memory object could not be read.", result); } } finally { Marshal.FreeHGlobal(bufferPtr); } break; } #else byte[] tempBuffer = new byte[length * Marshal.SizeOf <T>()]; Buffer.BlockCopy(buffer, 0, tempBuffer, 0, tempBuffer.Length); IntPtr bufferPtr = Marshal.AllocHGlobal(tempBuffer.Length); try { Marshal.Copy(tempBuffer, 0, bufferPtr, tempBuffer.Length); Result result = EnqueuedCommandsNativeApi.EnqueueWriteBuffer(this.Handle, memoryObject.Handle, 1, new UIntPtr(0), new UIntPtr((uint)tempBuffer.Length), bufferPtr, 0, null, out IntPtr waitEventPointer); // Checks if the read operation was queued successfuly, if not, an exception is thrown if (result != Result.Success) { throw new OpenClException("The memory object could not be read.", result); } } #endif }
public override void acceptMemoryObject(MemoryObject memObj) { if (memObj.found) { lightTorch(); } }
public override void acceptMemoryObject(MemoryObject memObj) { if (memObj.found) { previouslyDiscovered(); } }
public override void acceptMemoryObject(MemoryObject memObj) { if (memObj.found) { activate(); } }
private static void DumpProcessModule(MemoryObject modulesMo, ILoadedModule module) { using (var child = modulesMo.CreateChild(module.BaseAddress.ToString("x"))) { BinaryWriter bw = new BinaryWriter(child.GetWriteStream()); bw.Write("Name", module.BaseName); bw.Write("FileName", module.FileName); bw.Write("Size", module.Size); bw.Write("BaseAddress", module.BaseAddress); bw.Write("Flags", (int)module.Flags); try { var info = System.Diagnostics.FileVersionInfo.GetVersionInfo(module.FileName); bw.Write("FileDescription", info.FileDescription); bw.Write("FileCompanyName", info.CompanyName); bw.Write("FileVersion", info.FileVersion); } catch { } bw.Close(); } }
private void LoadHandles(MemoryObject mo) { var dict = Dump.GetDictionary(mo); HandleItem item = new HandleItem(); if (!dict.ContainsKey("Handle")) { return; } item.Handle.ProcessId = _item.Pid; item.Handle.Flags = (HandleFlags)Dump.ParseInt32(dict["Flags"]); item.Handle.Handle = (short)Dump.ParseInt32(dict["Handle"]); // Not really needed, just fill it in ignoring 32-bit vs 64-bit // differences. item.Handle.Object = (Dump.ParseInt64(dict["Object"]) & 0xffffffff).ToIntPtr(); item.Handle.GrantedAccess = Dump.ParseInt32(dict["GrantedAccess"]); if (dict.ContainsKey("TypeName")) { item.ObjectInfo.TypeName = dict["TypeName"]; item.ObjectInfo.BestName = dict["ObjectName"]; } if (Settings.Instance.HideHandlesWithNoName) { if (string.IsNullOrEmpty(item.ObjectInfo.BestName)) { return; } } listHandles.AddItem(item); }
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[] { CollisionLayers.AnimStatic, CollisionLayers.Biped, CollisionLayers.CharController, //CollisionLayers.Clutter, CollisionLayers.DebrisLarge, CollisionLayers.Ground, //CollisionLayers.Props, CollisionLayers.Static, CollisionLayers.Terrain, CollisionLayers.Trap, CollisionLayers.Trees, CollisionLayers.Unidentified, }); }
private static void _Hook_Enchanting(CPURegisters ctx) { var item = MemoryObject.FromAddress <TESForm>(Memory.ReadPointer(ctx.R15)); var soul = MemoryObject.FromAddress <TESForm>(Memory.ReadPointer(Memory.ReadPointer(ctx.BX + 0x18))); float skill = 5.0f; var plr = PlayerCharacter.Instance; if (plr != null) { skill = plr.GetActorValue(ActorValueIndices.Enchanting); } float xp = Formula_Enchanting(Math.Max(0, item.GoldValue), Math.Max(0, soul.GoldValue), skill); if (xp < 0.0f) { xp = 0.0f; } if (Settings.DebugMode > 0) { WriteToDebugFile("Enchanting: original XP was " + ctx.XMM2f.ToString(System.Globalization.CultureInfo.InvariantCulture) + " and we replaced it with " + xp.ToString(System.Globalization.CultureInfo.InvariantCulture)); } ctx.XMM2f = xp; }
public override object Read(ES2Reader reader) { MemoryObject data = new MemoryObject(); Read(reader, data); return(data); }
private static void DumpProcessHistory <T>(MemoryObject processMo, CircularBuffer <T> buffer, string name) { using (var child = processMo.CreateChild(name + "History")) { using (var s = child.GetWriteStream()) buffer.Save(s); } }
/// <summary> /// Sets the buffer as argument /// </summary> /// <param name="index">The index of the argument</param> /// <param name="obj">The buffer to be set</param> public void SetBuffer(int index, MemoryObject obj) { #if NO_CL Logger.Log("Setting Kernel Argument " + index, DebugChannel.Warning); #else Kernel.SetKernelArgument(index, obj); #endif }
public static void AppendStruct <T>(MemoryObject mo, int size, T s) where T : struct { using (MemoryAlloc data = new MemoryAlloc(size)) { data.WriteStruct(s); mo.AppendData(data.ReadBytes(data.Size)); } }
public override void acceptMemoryObject(MemoryObject memObj) { if (memObj.found) { used = true; activate(false); } }
public static void AppendStruct <T>(MemoryObject mo, T s) where T : struct { using (var data = new MemoryAlloc(Marshal.SizeOf(typeof(T)))) { data.WriteStruct <T>(s); mo.AppendData(data.ReadBytes(data.Size)); } }
public override void Read(ES2Reader reader, object c) { MemoryObject data = (MemoryObject)c; // Add your reader.Read calls here to read the data into the object. data.found = reader.Read <System.Boolean>(); data.objectName = reader.Read <System.String>(); data.sceneName = reader.Read <System.String>(); }
public override void acceptMemoryObject(MemoryObject memObj) { if (memObj.found) { triggered = true; GameManager.saveMemory(this); Destroy(gameObject); } }
public void CountNotAllocatedMemory() { //arrange var mo = new MemoryObject(); //act //assert mo.Count(1).ShouldBe(0); }
public override void Write(object obj, ES2Writer writer) { MemoryObject data = (MemoryObject)obj; // Add your writer.Write calls here. writer.Write(data.found); writer.Write(data.objectName); writer.Write(data.sceneName); }
internal CameraResult() { Allocation = Memory.Allocate(0x34); Transform = MemoryObject.FromAddress <NiTransform>(Allocation.Address); Transform.Position.X = 0.0f; Transform.Position.Y = 0.0f; Transform.Position.Z = 0.0f; Transform.Rotation.Identity(1.0f); Transform.Scale = 1.0f; }
public void CountAllocatedMemory() { //arrange var mo = new MemoryObject(); //act mo.SetData(1, new byte[4]); //assert mo.Count(1).ShouldBe(4); }
public void ReadMoreThanAllocatedMemory() { //arrange var mo = new MemoryObject(); //act mo.SetData(1, new byte[4]); //assert mo.GetData(1, 0, 40).ShouldBe(new byte[] { 0, 0, 0, 0 }); }
// Get memory /// <summary> /// Gets general memory information such as total memory and all ram slots /// </summary> /// <returns>A MemoryObject</returns> public MemoryObject GetMemory() { MemoryObject Memory = new MemoryObject(); List<MemorySlotObject> MemorySlots = new List<MemorySlotObject>(); Memory.slots = MemorySlots; // Get used memory slots ManagementObjectSearcher Query = new ManagementObjectSearcher("SELECT * FROM Win32_MemoryDevice"); ManagementObjectCollection Collection = Query.Get(); foreach (ManagementObject MO in Collection) { MemorySlotObject MemorySlot = new MemorySlotObject(); Try(() => MemorySlot.device_identifier = MO["DeviceID"].ToString().Replace("Memory Device ", "")); Try(() => MemorySlot.capacity = Math.Round((Convert.ToDouble(MO["EndingAddress"].ToString()) - Convert.ToDouble(MO["StartingAddress"].ToString())) / 1024).ToString()); if (Convert.ToDouble(MemorySlot.capacity) == 0) { MemorySlot.empty = true; } else { MemorySlot.empty = false; } MemorySlots.Add(MemorySlot); } Query = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); Collection = Query.Get(); foreach (ManagementObject MO in Collection) { try { var Identifier = MO["Tag"].ToString().Replace("Physical Memory ", ""); foreach (MemorySlotObject MemorySlot in MemorySlots) { if (MemorySlot.device_identifier == Identifier) { Try(() => MemorySlot.part_number = MO["PartNumber"].ToString().Trim()); Try(() => MemorySlot.serial = MO["Serial"].ToString()); Try(() => MemorySlot.speed = MO["Speed"].ToString()); Try(() => MemorySlot.manufacturer.detection_string = MO["Manufacturer"].ToString()); } } } catch { } } // Get total physical memory Query = new ManagementObjectSearcher("Select * From Win32_ComputerSystem"); Collection = Query.Get(); double RamBytes = 0; foreach (ManagementObject MO in Collection) { Try(() => RamBytes = (Convert.ToDouble(MO["TotalPhysicalMemory"]))); } Memory.total_physical_memory = Math.Round(RamBytes / 1048576).ToString(); return Memory; }