CharlesVercetti Posted June 21, 2018 Share Posted June 21, 2018 I've been fiddling with .asi coding in recent times(using plugin-sdk or native asi) based on C++. I have two questions. 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) 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... Link to comment Share on other sites More sharing options...
DK22Pac Posted June 21, 2018 Share Posted June 21, 2018 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 CharlesVercetti 1 Link to comment Share on other sites More sharing options...
CharlesVercetti Posted June 21, 2018 Author Share Posted June 21, 2018 (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 June 22, 2018 by CharlesVercetti Link to comment Share on other sites More sharing options...
DK22Pac Posted June 23, 2018 Share Posted June 23, 2018 (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: 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 June 23, 2018 by DK22Pac CharlesVercetti 1 Link to comment Share on other sites More sharing options...
CharlesVercetti Posted June 23, 2018 Author Share Posted June 23, 2018 (edited) - Edited June 23, 2018 by CharlesVercetti Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now