.net console registering menu

User Tag List

Results 1 to 13 of 13
  1. #1
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .net console registering

    I'm using Apoc's library and have my module in and working fine, except for registering functions. I'm keeping a list<IntPtr> of all the function pointers that I create to prevent garbage collection, but it is still hanging when I type the command in the console. It's not invalid function pointer, I patched it. Here's how I'm registering.

    Code:
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            private delegate void ConsoleRegisterDelegate(IntPtr txt, IntPtr cb, uint unk, uint unk2);
    public delegate void ConsoleRegisterCallbackDelegate();
    ...
    private void ConsoleRegTest()
    {
                return;
    }
    ...
    _console.RegisterConsoleCommand("testreg", ConsoleRegTest);
    ...
    public void RegisterConsoleCommand(string name, ConsoleRegisterCallbackDelegate callback)
    {
                IntPtr _cb = Marshal.GetFunctionPointerForDelegate(callback);
                IntPtr _nm = Marshal.StringToHGlobalAnsi(name);
                _callbacks.Add(_cb);
                _callbackDels.Add(callback);
    
                dConsoleRegister(_nm, _cb, 0, 0);
    }
    Any ideas?

    .net console registering
  2. #2
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lanman92 View Post
    I'm using Apoc's library and have my module in and working fine, except for registering functions. I'm keeping a list<IntPtr> of all the function pointers that I create to prevent garbage collection, but it is still hanging when I type the command in the console. It's not invalid function pointer, I patched it. Here's how I'm registering.

    Code:
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            private delegate void ConsoleRegisterDelegate(IntPtr txt, IntPtr cb, uint unk, uint unk2);
    public delegate void ConsoleRegisterCallbackDelegate();
    ...
    private void ConsoleRegTest()
    {
                return;
    }
    ...
    _console.RegisterConsoleCommand("testreg", ConsoleRegTest);
    ...
    public void RegisterConsoleCommand(string name, ConsoleRegisterCallbackDelegate callback)
    {
                IntPtr _cb = Marshal.GetFunctionPointerForDelegate(callback);
                IntPtr _nm = Marshal.StringToHGlobalAnsi(name);
                _callbacks.Add(_cb);
                _callbackDels.Add(callback);
    
                dConsoleRegister(_nm, _cb, 0, 0);
    }
    Any ideas?
    Code:
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate int ConsoleRegisteredFuncDelegate(int a1, IntPtr a2);
    Try that one - just return 1.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  3. #3
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For what? The prototype for my functions or what?

    EDIT: I changed my callback function to that prototype and it's still not working.
    Last edited by lanman92; 11-16-2009 at 06:01 PM.

  4. #4
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for double-post, but anyway. How do you guys debug your .NET code when it's injected? Will VS do it? Olly doesn't, it shows random stuff for the IL code.

  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lanman92 View Post
    Sorry for double-post, but anyway. How do you guys debug your .NET code when it's injected? Will VS do it? Olly doesn't, it shows random stuff for the IL code.
    Visual Studio ftw?

  6. #6
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess I'll have to turn off the driver debugging thing then. We'll see how this works.

  7. #7
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oi; what's the current RegisterConsoleCmd addr? Cba to find it.

    Edit: Nevermind.

  8. #8
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    signed int __cdecl ConsoleCommandRegister(char *pszCommandName, int pCallback, int category, int unk)
    So; the actual register command would be:

    public delegate int ConsoleCommandRegisterDelegate(string commandName, IntPtr callback, int category, int unk);

    And the actual callback prototype:

    public delegate int ConsoleCommandCallbackDelegate();

    Though; the callback can take arguments as well. So you can do it the easier way and just make sure the callback returns an int, and takes an arbitrary number of params.

    public delegate int ConsoleCommandCallbackDelegate(int arg1, string arg2);

    Etc.

    Code:
            public static bool HasReturnType(Delegate d, Type returnType)
            {
                return d.Method.ReturnType == returnType;
            }
    Code:
    if (HasReturnType(callback, typeof(int))
        RegisterCommand(commandName, Marshal.GetFunctionPointerForDelegate(callback), category, 0);
    Last edited by Apoc; 11-17-2009 at 12:12 AM.

  9. #9
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Code:
    signed int __cdecl ConsoleCommandRegister(
       char *pszCommandName, 
       int pCallback, 
       int category, 
       char* pszHelpMessage)
    help MyCommand will then print that message if memory serves right (ty to nesox), haven't done anything wow related in a while.

  10. #10
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a simple console class I started writing for something. It still needs work and I can't remember if there are any known problems, but it should be a start:

    Code:
    // Preprocessor header guard to stop multiple includes
    #ifndef WOWNINJA__WOWCONSOLE_H
    #define WOWNINJA__WOWCONSOLE_H
    
    // C++ Standard Library
    #include <set>
    #include <string>
    #include <memory>
    
    // WoWConsole pointer type
    typedef std::tr1::shared_ptr<class WoWConsole> WoWConsolePtr;
    
    // Wrapper class for WoW's console
    class WoWConsole
    {
    public:
      // Get singleton
      static WoWConsolePtr Get()
      {
        static WoWConsolePtr pConsole;
        if (pConsole == 0)
          pConsole.reset(new WoWConsole());
        return pConsole;
      }
    
      // WoW engine console command groups
      enum ConsoleCmdGroup
      {
        Debug,
        Graphics,
        Console,
        Combat,
        Game,
        Default,
        Net,
        Sound,
        Gm
      };
    
      // WoW engine console callback function type
      typedef long (__cdecl* tCallback)(long Unknown, char const* Params);
    
      // Register a console command
      // Note: Neither 'Name' nor 'Help' are copied internally and hence the 
      // pointers must remain valid for the lifetime of the command.
      // Note: 'Help' is optional (null pointer is valid)
      long CommandRegister(char const* Name, tCallback Callback, 
        ConsoleCmdGroup Group, char const* Help)
      {
        m_CmdNames.insert(Name);
        return m_pCmdRegister(Name, Callback, Group, Help);
      }
    
      // Unregister a console command
      long CommandUnregister(std::string const& Name)
      {
        std::set<std::string>::iterator i = m_CmdNames.find(Name);
        if (i != m_CmdNames.end())
          m_CmdNames.erase(i);
        m_pCmdUnregister(Name.c_str());
      }
    
      // Output string to console
      void Output(std::string const& OutputStr)
      {
        m_pOutput(OutputStr.c_str(), 0);
      }
    
      // Destructor
      ~WoWConsole()
      {
        // Unregister all registered commands
        for (std::set<std::string>::const_iterator i = m_CmdNames.begin(); 
          i != m_CmdNames.end(); ++i)
        {
          m_pCmdUnregister(i->c_str());
        }
      }
    
    protected:
      // Constructor (protected to enforce singleton)
      WoWConsole() 
        // Initialize engine global/function pointers
        : m_pConsoleEnabled(reinterpret_cast<unsigned long*>(0x012A2408)), 
        m_pCmdRegister(reinterpret_cast<tCmdRegister>(0x006DD780)), 
        m_pCmdUnregister(reinterpret_cast<tCmdUnregister>(0x006DD060)), 
        m_pOutput(reinterpret_cast<tOutput>(0x006DB9E0)), 
        m_CmdNames()
      {
        // Enable console
        *m_pConsoleEnabled = 1;
      }
    
      // Disable copying and assignment
      WoWConsole(WoWConsole const&);
      WoWConsole& operator= (WoWConsole const&);
    
    private:
      // WoW engine flag to enable console 'on-the-fly'
      unsigned long* m_pConsoleEnabled;
    
      // WoW engine function to register a console callback
      typedef long (__cdecl* tCmdRegister)(char const* Name, tCallback Callback, 
        ConsoleCmdGroup Group, char const* Help);
      tCmdRegister m_pCmdRegister;
    
      // WoW engine function to unregister a console callback
      typedef long (__cdecl* tCmdUnregister)(char const* CmdName);
      tCmdUnregister m_pCmdUnregister;
    
      // WoW engine console output function
      typedef void (__cdecl* tOutput)(char const* Output, long Unknown);
      tOutput m_pOutput;
    
      // List of callbacks registered (needed so they can be unregistered 
      // in the destructor)
      std::set<std::string> m_CmdNames;
    };
    
    #endif // WOWNINJA__WOWCONSOLE_H

  11. #11
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by SKU View Post
    help MyCommand will then print that message if memory serves right (ty to nesox), haven't done anything wow related in a while.
    Correct. :P

    Though; I haven't seen any functions make use of the 4th param. May just be me however.

  12. #12
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Correct. :P

    Though; I haven't seen any functions make use of the 4th param. May just be me however.
    The fourth pram is indeed the help string.

    You fail.

  13. #13
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well. I have been able to make this work using same prototypes and etc in C++, it's just not working in C#.

    Code:
    IntPtr _cb = Marshal.GetFunctionPointerForDelegate(callback);
    IntPtr _nm = Marshal.StringToHGlobalAnsi(name);
    _callbacks.Add(_cb);
    _callbackDels.Add(callback);
    this.Write("Registering function: \"{0}\" at: 0x{1}", name, _cb.ToString("X"));
    
    dConsoleRegister(_nm, _cb, 5, 0);
    ...
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    private delegate void ConsoleRegisterDelegate(IntPtr txt, IntPtr cb, uint unk, uint unk2);
    This is right, correct?
    Last edited by lanman92; 11-17-2009 at 05:35 PM.

Similar Threads

  1. Battle.net Registered Name Change
    By Kaiser. in forum World of Warcraft General
    Replies: 2
    Last Post: 06-16-2015, 05:39 PM
  2. .NET CLR Hosting + Console woes
    By Shenlok in forum WoW Memory Editing
    Replies: 5
    Last Post: 10-21-2013, 03:55 AM
  3. Anyone playing Starcraft Broodwar battle net.?
    By Datonking in forum Gaming Chat
    Replies: 7
    Last Post: 09-13-2006, 08:18 AM
  4. Possible ideas to get users to register..
    By Matt in forum Suggestions
    Replies: 15
    Last Post: 08-22-2006, 09:36 AM
  5. Favourite Gaming Consoles!
    By janzi9 in forum Gaming Chat
    Replies: 30
    Last Post: 08-09-2006, 08:53 PM
All times are GMT -5. The time now is 05:50 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search