Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    2. News

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
    1. GTA Online

      1. After Hours
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

CharlesVercetti

[VC] Rendering textures in .txd and process writing through .asi

Recommended Posts

CharlesVercetti

 I've been fiddling with .asi coding in recent times(using plugin-sdk or native asi) based on C++.

I have two questions.

  1. How do I render textures in a.txd file through .asi ?If there is a method,then what is the syntax for it? Does it require DX SDK (If it requires,then I have it)
  2. How do I write a memory address to the game process through .asi? What is the syntax for it?

And if the above two things can be done with plugin sdk,you can explain based on that too...

Share this post


Link to post
Share on other sites
DK22Pac
2 hours ago, CharlesVercetti said:

How do I render textures in a.txd file through .asi ?If there is a method,then what is the syntax for it? Does it require DX SDK (If it requires,then I have it)

There are different ways to load and draw textures.

For example, you can load RwTexDictionary with CFileLoader::LoadTexDictionary and then save the texture pointer to CSprite2d object.

#include "plugin.h"
#include "CFileLoader.h"
#include "CSprite2d.h"

using namespace plugin;

class TextureExample {
public:
    TextureExample() {
        static RwTexDictionary *pMyTxd = nullptr;
        static CSprite2d mySprite;

        Events::initRwEvent += [] { // we can load textures only after RenderWare was initialised
            pMyTxd = CFileLoader::LoadTexDictionary(PLUGIN_PATH("myTxd.txd"));
            mySprite.m_pTexture = RwTexDictionaryFindNamedTexture(pMyTxd, "texture");
        };

        Events::drawingEvent += [] { // drawing callback
            mySprite.Draw(SCREEN_RECT(100.0, 100.0, 400.0, 400.0), CRGBA(255, 255, 255, 255));
        };

        Events::shutdownRwEvent += [] { // unload txd when RenderWare is closing
            RwTexDictionaryDestroy(pMyTxd);
            mySprite.m_pTexture = nullptr;
        };
    }
} textureExample;

 

2 hours ago, CharlesVercetti said:

How do I write a memory address to the game process through .asi? What is the syntax for it?

https://gtaforums.com/topic/708885-q-dk22pac-plugin-sdk/?tab=comments#comment-1069859971

Share this post


Link to post
Share on other sites
CharlesVercetti
Posted (edited)
21 hours ago, DK22Pac said:

https://gtaforums.com/topic/708885-q-dk22pac-plugin-sdk/?tab=comments#comment-1069859971

Thank you very much.

One more question...how do I hook a random texture to a pre-existing 2d sprite on game screen?

Ex: Weapon icon,radarring(the ring above hud rounded radar map)

 

EDIT:

   Events::drawingEvent += [] { // drawing callback
            mySprite.Draw(SCREEN_RECT(100.0, 100.0, 400.0, 400.0), CRGBA(255, 255, 255, 255));
        };

In the above code snippet...I included a key-press condition(using if) with the KeyPressed() function present in plugin sdk for a the key "p".However that doesn't work...I'm confused about the syntax for it...

KeyPressed(int KeyCode)

In above syntax what does keycode refer to?Is it virtual keycode or any other?Below is my code snippet for reference.

if(KeyPressed(80)){   //80 is virtual keycode for "p"  
 Events::drawingEvent += [] { // drawing callback
            mySprite.Draw(SCREEN_RECT(100.0, 100.0, 400.0, 400.0), CRGBA(255, 255, 255, 255));
        }; }
Edited by CharlesVercetti

Share this post


Link to post
Share on other sites
DK22Pac
Posted (edited)
Events::drawingEvent += [] { // drawing callback
    if (KeyPressed('P')
        mySprite.Draw(SCREEN_RECT(100.0, 100.0, 400.0, 400.0), CRGBA(255, 255, 255, 255));
};

 

On 6/21/2018 at 6:54 PM, CharlesVercetti said:

One more question...how do I hook a random texture to a pre-existing 2d sprite on game screen?

Ex: Weapon icon,radarring(the ring above hud rounded radar map)

Find a function which you need to hook and replace its call with patch::ReplaceFunctionCall. The new function must have same calling convention and same parameters (but not always) with the original function.

A function which draws the radarring texture (CSprite2d::Draw(CRect const&,CRGBA const&,CRGBA const&,CRGBA const&,CRGBA const&)) is called at 0x55AB13:

 

DvcK8K7.png

 

It has __thiscall calling conventiion (first parameter (pointer to object, this) is passed in ecx register, all other parameters are passed through the stack), and following parameters:

CSprite2d *  - sprite pointer (this)
CRect const& - sprite rectangle
CRGBA const& - corner1 color
CRGBA const& - corner2 color
CRGBA const& - corner3 color
CRGBA const& - corner4 color

It's not possible to explicitly set __thiscall calling convention for a function, so we use __stdcall calling convention, which is similar to __thiscall (the only difference is that __stdcall doesn't have this parameter).

The only paramerer that we need to use in the new function is sprite rectangle, all other can be skipped (but not removed).

So that's how the new function looks like:

//                                    rectangle
//                                    |            // unused colors
//                                    |            |
static void __stdcall DrawMyRadarDisc(CRect& rect, CRGBA&, CRGBA&, CRGBA&, CRGBA&) {
    mySprite.Draw(rect, CRGBA(255, 255, 255, 255)); // draw our sprite here
};

And here's our injection:

patch::ReplaceFunctionCall(0x55AB13, DrawMyRadarDisc);

Full code

Spoiler
#include "plugin.h"
#include "CFileLoader.h"
#include "CSprite2d.h"

using namespace plugin;

class TextureExample {
public:
    inline static RwTexDictionary *pMyTxd = nullptr;
    inline static CSprite2d mySprite;

    // replacement function
    static void __stdcall DrawMyRadarDisc(CRect& rect, CRGBA&, CRGBA&, CRGBA&, CRGBA&) {
        mySprite.Draw(rect, CRGBA(255, 255, 255, 255));
    };

    TextureExample() {
        Events::initRwEvent += [] { // we can load textures only after RenderWare was initialised
            pMyTxd = CFileLoader::LoadTexDictionary(PLUGIN_PATH("myTxd.txd"));
            mySprite.m_pTexture = RwTexDictionaryFindNamedTexture(pMyTxd, "texture");
        };

        Events::shutdownRwEvent += [] { // unload txd when RenderWare is closing
            RwTexDictionaryDestroy(pMyTxd);
            mySprite.m_pTexture = nullptr;
        };

        patch::ReplaceFunctionCall(0x55AB13, DrawMyRadarDisc);
    }
} textureExample;

 

Related:

 

Edited by DK22Pac

Share this post


Link to post
Share on other sites
CharlesVercetti
Posted (edited)

-

Edited by CharlesVercetti

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 1 User Currently Viewing
    0 Members, 0 Anonymous, 1 Guest

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.