Coding practices? menu

User Tag List

Results 1 to 5 of 5
  1. #1
    lolp1's Avatar Site Donator CoreCoins Purchaser
    Reputation
    190
    Join Date
    Feb 2013
    Posts
    210
    Thanks G/R
    43/77
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Coding practices?

    *New to developing stuff, sorry if the question is too general/noobish.
    A little general of a question/discussion for this section but I have found it to be one of the best resources for game 'hacking' related coding so I hope no one minds.

    Anyways, does anyone have any advice/links to share that relate to good/solid coding practices in relation to developing game hacks/bots? For example, one habit I picked up is to name classes/enums/etc to the actual names the game uses for those structures or what ever.

    A lot of people including myself tend to just make up their own random names for no reason, and it only seems to serve to confuse anyone who works on your code or even your self.

    I'm also still unsure about enums(C#). I feel like I should really not be using them for integer offsets, but most do. Is there anything wrong with just a good old fashion static Offsets class with the offsets as readonly or const ints, and saving enums for actual types/etc?

    So, I'm not really referring to general coding patterns - but more so what kind of habits should I be getting into related to developing game tools in general. Thanks ahead of time. : )
    Last edited by lolp1; 08-14-2015 at 09:48 AM.

    Coding practices?
  2. #2
    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)
    Enums are not a great choice for offsets. Seeing as they're constant, you'll need to rebase them every time you use them. They're even worse to use in C# because of the way enum types work. IntPtr is your best option and you should rebase them once. Example:

    Code:
    private static bool _initialized;
    
    internal static IntPtr
        Offset1     = (IntPtr) 0x11223344,
        Offset2     = (IntPtr) 0x55667788;
    
    internal static void Initialize() {
        if (_initialized)
            return;
    
        var mainModule = ...;
        Rebase(mainModule, ref Offset1);
        Rebase(mainModule, ref Offset2);
    
        _initialized = true;
    }
    
    private static void Rebase(IntPtr baseAddress, ref IntPtr address) {
        address = (IntPtr)(baseAddress + address.ToInt64());
    }
    Also viable:

    Code:
    internal static readonly IntPtr
        Offset1,
        Offset2;
    
    static Offsets() {
        var mainModule = ...;
        Offset1 = mainModule + 0x11223344;
        Offset2 = mainModule + 0x55667788;
    }
    I use the former because the base address is not necessarily ready before the static constructor is called. Whichever works best for you, you should use.
    Last edited by Jadd; 08-14-2015 at 11:26 AM.

  3. #3
    Confucius's Avatar Super Moderator Don't Look Back in Anger

    CoreCoins Purchaser Authenticator enabled
    Reputation
    1418
    Join Date
    Oct 2007
    Posts
    2,805
    Thanks G/R
    301/311
    Trade Feedback
    7 (100%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As far as naming goes, just remember to comment your code if you are having trouble remembering what each name is for.

  4. #4
    lolp1's Avatar Site Donator CoreCoins Purchaser
    Reputation
    190
    Join Date
    Feb 2013
    Posts
    210
    Thanks G/R
    43/77
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Confucius View Post
    As far as naming goes, just remember to comment your code if you are having trouble remembering what each name is for.
    I'm referring more so to naming of things that should not need comments. For example, lets say there is a game structure called "GameDataElements", which contains mostly or all elements of the games in-game UI. It is tempting to just name your class "Ingameuielements". The issue is, for me anyways, as I did this more and more the general layout of the way the actual game structs work got confusing fast.

    Thanks for the advice so far. Another thing I'm trying to work on is not over-using properties. I started out seeing and using them a lot, but as time goes by I see how they can be kind of confusing. Example:

    Code:
    var entityList =  GameExample.EntityList; // Bad?
    var entityList =  GameExample.EntityListOld; // Bad?
    vs
    Code:
    var freshEntityList =  GameExample.GetEntityList(); // Better?
    var cachedEntityList =  GameExample.EntityListCache; // Better?
    
    // Perhaps even better:
    :
    var freshEntityList =  GameExample.GetEntityList(true); // Bool to return fresh list
    var cachedEntityList =  GameExample.GetEntityList(false);    // Bool to return cached

  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)
    IMO create a wrapper for the internal stuff. Then you can call the functions whatever you want.

    As for caching:

    Code:
    var entitiesCached = Manager.EntityList;
    
    Manager.Invalidate();
    var entities = Manager.EntityList;

Similar Threads

  1. Codes for CE Mountain climb and No damage fall =D
    By FoRbIdDeN in forum World of Warcraft Bots and Programs
    Replies: 23
    Last Post: 10-28-2006, 09:21 AM
  2. I need Current PTR Mountain climbing code-Because of error
    By Wildslayer in forum World of Warcraft General
    Replies: 0
    Last Post: 08-16-2006, 08:24 AM
  3. LOTS of WPE codes
    By Örpheus in forum World of Warcraft Bots and Programs
    Replies: 16
    Last Post: 08-04-2006, 01:19 PM
  4. [Bot:Source] Acidic Bot Source Code
    By =sinister= in forum World of Warcraft Bots and Programs
    Replies: 10
    Last Post: 07-03-2006, 05:38 PM
  5. Error in checking WoW.exe CRC code hack?
    By Trichelieu in forum World of Warcraft General
    Replies: 0
    Last Post: 06-11-2006, 02:24 PM
All times are GMT -5. The time now is 10:52 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