Game crashes when calling lua function before loading screen menu

Shout-Out

User Tag List

Results 1 to 7 of 7
  1. #1
    avizer's Avatar Member
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    21
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Game crashes when calling lua function before loading screen

    Hi all! My problem is this: when I call a Lua function to be followed after the loading screen I get a crash.
    example:
    Code:
    Hook MyHook = new Hook((uint)wow.ProcessId);
    Lua.LuaDoString(MyHook, "EnterWorld()");
    LuaDoString code:
    Code:
    public static void LuaDoString(Hook MyHook, string command)
            {
                // Allocate memory
                uint DoStringArg_Codecave = MyHook.Memory.AllocateMemory(Encoding.UTF8.GetBytes(command).Length + 1);
                // offset:
                uint FrameScript__Execute = 0x00819210;
    
    
                // Write value:
                MyHook.Memory.WriteBytes(DoStringArg_Codecave, Encoding.UTF8.GetBytes(command));
    
                // Write the asm stuff for Lua_DoString
                String[] asm = new String[] 
                {
                    "mov eax, " + DoStringArg_Codecave,
                    "push 0",
                    "push eax",
                    "push eax",
                    "mov eax, " + (uint)FrameScript__Execute, // Lua_DoString
                    "call eax",
                    "add esp, 0xC",
                    "retn",    
                };
    
                // Inject
                MyHook.InjectAndExecute(asm);
                // Free memory allocated 
                MyHook.Memory.FreeMemory(DoStringArg_Codecave);
            }
    Hook code:
    Code:
    public class Hook
        {
            // Addresse Inection code:
            uint injected_code = 0;
            uint addresseInjection = 0;
            public bool threadHooked = false;
            uint retnInjectionAsm = 0;
            bool InjectionUsed = false;
            public BlackMagic Memory = new BlackMagic();
            public uint _processId = 0;
            public Hook(uint processId)
            {
                _processId = processId;
                Hooking();
            }
    
            public void Hooking()
            {
                // Offset:
                uint DX_DEVICE = 0xC5DF88;
                uint DX_DEVICE_IDX = 0x397C;
                uint ENDSCENE_IDX = 0xA8;
    
                // Process Connect:
                if (!Memory.IsProcessOpen)
                {
                    Memory.OpenProcessAndThread((int)_processId);
                }
    
                if (Memory.IsProcessOpen)
                {
                    // Get address of EndScene
                    uint pDevice = Memory.ReadUInt(DX_DEVICE);
                    uint pEnd = Memory.ReadUInt(pDevice + DX_DEVICE_IDX);
                    uint pScene = Memory.ReadUInt(pEnd);
                    uint pEndScene = Memory.ReadUInt(pScene + ENDSCENE_IDX);
    
                    if (Memory.ReadByte(pEndScene) == 0xE9 && (injected_code == 0 || addresseInjection == 0)) // check if wow is already hooked and dispose Hook
                    {
                        DisposeHooking();
                    }
    
                    if (Memory.ReadByte(pEndScene) != 0xE9) // check if wow is already hooked
                    {
                        try
                        {
                            threadHooked = false;
                            // allocate memory to store injected code:
                            injected_code = Memory.AllocateMemory(2048);
                            // allocate memory the new injection code pointer:
                            addresseInjection = Memory.AllocateMemory(0x4);
                            Memory.WriteInt(addresseInjection, 0);
                            // allocate memory the pointer return value:
                            retnInjectionAsm = Memory.AllocateMemory(0x4);
                            Memory.WriteInt(retnInjectionAsm, 0);
    
                            // Generate the STUB to be injected
                            Memory.Asm.Clear(); // $Asm
    
                            // save regs
                            Memory.Asm.AddLine("pushad");
                            Memory.Asm.AddLine("pushfd");
    
                            // Test if you need launch injected code:
                            Memory.Asm.AddLine("mov eax, [" + addresseInjection + "]");
                            Memory.Asm.AddLine("test eax, eax");
                            Memory.Asm.AddLine("je @out");
    
                            // Launch Fonction:
                            Memory.Asm.AddLine("mov eax, [" + addresseInjection + "]");
                            Memory.Asm.AddLine("call eax");
    
                            // Copie pointer return value:
                            Memory.Asm.AddLine("mov [" + retnInjectionAsm + "], eax");
    
                            // Enter value 0 of addresse func inject
                            Memory.Asm.AddLine("mov edx, " + addresseInjection);
                            Memory.Asm.AddLine("mov ecx, 0");
                            Memory.Asm.AddLine("mov [edx], ecx");
    
                            // Close func
                            Memory.Asm.AddLine("@out:");
    
                            // load reg
                            Memory.Asm.AddLine("popfd");
                            Memory.Asm.AddLine("popad");
    
    
                            // injected code
                            uint sizeAsm = (uint)(Memory.Asm.Assemble().Length);
                            Memory.Asm.Inject(injected_code);
    
                            // Size asm jumpback
                            int sizeJumpBack = 5;
    
                            // copy and save original instructions
                            Memory.Asm.Clear();
                            Memory.Asm.AddLine("mov edi, edi");
                            Memory.Asm.AddLine("push ebp");
                            Memory.Asm.AddLine("mov ebp, esp");
                            Memory.Asm.Inject(injected_code + sizeAsm);
    
                            // create jump back stub
                            Memory.Asm.Clear();
                            Memory.Asm.AddLine("jmp " + (pEndScene + sizeJumpBack));
                            Memory.Asm.Inject(injected_code + sizeAsm + (uint)sizeJumpBack);
    
                            // create hook jump
                            Memory.Asm.Clear(); // $jmpto
                            Memory.Asm.AddLine("jmp " + (injected_code));
                            Memory.Asm.Inject(pEndScene);
                        }
                        catch { threadHooked = false; return; }
                    }
                    threadHooked = true;
                }
    
            }
    
            public void DisposeHooking()
            {
                try
                {
                    // Offset:
                    uint DX_DEVICE = 0xC5DF88;
                    uint DX_DEVICE_IDX = 0x397C;
                    uint ENDSCENE_IDX = 0xA8;
    
                    // Get address of EndScene:
                    uint pDevice = Memory.ReadUInt(DX_DEVICE);
                    uint pEnd = Memory.ReadUInt(pDevice + DX_DEVICE_IDX);
                    uint pScene = Memory.ReadUInt(pEnd);
                    uint pEndScene = Memory.ReadUInt(pScene + ENDSCENE_IDX);
    
                    if (Memory.ReadByte(pEndScene) == 0xE9) // check if wow is already hooked and dispose Hook
                    {
                        // Restore origine endscene:
                        Memory.Asm.Clear();
                        Memory.Asm.AddLine("mov edi, edi");
                        Memory.Asm.AddLine("push ebp");
                        Memory.Asm.AddLine("mov ebp, esp");
                        Memory.Asm.Inject(pEndScene);
                    }
    
                    // free memory:
                    Memory.FreeMemory(injected_code);
                    Memory.FreeMemory(addresseInjection);
                    Memory.FreeMemory(retnInjectionAsm);
    
                }
                catch { }
            }
    
            public byte[] InjectAndExecute(string[] asm, int returnLength = 0)
            {
                while (InjectionUsed)
                { Thread.Sleep(5); }
                InjectionUsed = true;
    
                // Hook Wow:
                Hooking();
    
                byte[] tempsByte = new byte[0];
    
                // reset return value pointer
                Memory.WriteInt(retnInjectionAsm, 0);
    
                if (Memory.IsProcessOpen && threadHooked)
                {
                    // Write the asm stuff
                    Memory.Asm.Clear();
                    foreach (string tempLineAsm in asm)
                    {
                        Memory.Asm.AddLine(tempLineAsm);
                    }
    
                    // Allocation Memory
                    uint injectionAsm_Codecave = Memory.AllocateMemory(Memory.Asm.Assemble().Length);
    
    
                    try
                    {
                        // Inject
                        Memory.Asm.Inject(injectionAsm_Codecave);
                        Memory.WriteInt(addresseInjection, (int)injectionAsm_Codecave);
                        while (Memory.ReadInt(addresseInjection) > 0) { Thread.Sleep(5); } // Wait to launch code
    
    
                        if (returnLength > 0)
                        {
                            tempsByte = Memory.ReadBytes(Memory.ReadUInt(retnInjectionAsm), returnLength);
                        }
                        else
                        {
                            byte Buf = new Byte();
                            List<byte> retnByte = new List<byte>();
                            uint dwAddress = Memory.ReadUInt(retnInjectionAsm);
                            Buf = Memory.ReadByte(dwAddress);
                            while (Buf != 0)
                            {
                                retnByte.Add(Buf);
                                dwAddress = dwAddress + 1;
                                Buf = Memory.ReadByte(dwAddress);
                            }
                            tempsByte = retnByte.ToArray();
                        }
                    }
                    catch { }
    
                    // Free memory allocated 
                    Memory.FreeMemory(injectionAsm_Codecave);
                }
                InjectionUsed = false;
                // return
                return tempsByte;
            }
    
        }
    Please, help.

    Game crashes when calling lua function before loading screen
  2. #2
    RivaLfr's Avatar Contributor CoreCoins Purchaser Authenticator enabled
    Reputation
    221
    Join Date
    Sep 2010
    Posts
    258
    Thanks G/R
    2/25
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You have forget to add wow module address at FrameScript__Execute

    Edit: If you use my old code ( http://www.ownedcore.com/forums/worl...lackmagic.html ([Sample Code] EndScene Hook with ASM and blackmagic) ) check if endscene have same opcode ("mov edi, edi", "push ebp", "mov ebp, esp")
    Last edited by RivaLfr; 04-03-2013 at 07:53 AM.

  3. #3
    avizer's Avatar Member
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    21
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I'm using your code. Do not quite understand what you mean.

  4. #4
    dashja's Avatar Private
    Reputation
    1
    Join Date
    Feb 2013
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by avizer View Post
    Yes, I'm using your code. Do not quite understand what you mean.
    don't copy paste then.

  5. #5
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    avizer's Avatar Member
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    21
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm sorry, but can anyone help?

  7. #7
    Natrist's Avatar Member
    Reputation
    11
    Join Date
    Mar 2013
    Posts
    146
    Thanks G/R
    9/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's quite a constructive response, Jadd. Once again, I have to tip my hat to you.

Similar Threads

  1. Calling lua functions requiering an hardware event
    By Frosttall in forum WoW Memory Editing
    Replies: 10
    Last Post: 12-22-2012, 11:19 AM
  2. Calling Lua Functions from DLL
    By Viano in forum WoW Memory Editing
    Replies: 19
    Last Post: 07-28-2009, 07:56 PM
  3. Calling LUA Functions
    By cloud_wizard in forum WoW Memory Editing
    Replies: 7
    Last Post: 01-04-2009, 08:24 AM
  4. Call lua function and get result
    By starfish99 in forum WoW Memory Editing
    Replies: 4
    Last Post: 12-26-2008, 05:15 AM
  5. Game crashes when I log into world
    By kimaster in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 01-30-2008, 10:28 PM
All times are GMT -5. The time now is 08:23 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search