Quantcast

Jump to content

» «
Photo

[SA]How to change the color of objects?

13 replies to this topic
KillerChainsaw
  • KillerChainsaw

    Player Hater

  • Members
  • Joined: 04 Nov 2013

#1

Posted 03 January 2014 - 06:10 AM

HI.
It is possible to change the color of objects?, I'm wanting to change the color of the models of weapons for my project, if possible, please help me??
 
Sorry for my bad english.
(。◕‿‿◕。)

ZAZ
  • ZAZ

    Kernlochbohrer

  • Members
  • Joined: 10 Jan 2005
  • European-Union

#2

Posted 03 January 2014 - 07:33 AM

Modify the object's texture, look in tutorial subforum for advice

__________________
moved to moddeling

KillerChainsaw
  • KillerChainsaw

    Player Hater

  • Members
  • Joined: 04 Nov 2013

#3

Posted 03 January 2014 - 07:46 AM Edited by KillerChainsaw, 03 January 2014 - 07:49 AM.

I want to change the color of objects per cleo, and not to change textures, I think there is an address change colors of objects, because it has some addresses that change the color of the environment, why not have an address change colors to objects ??


_DK
  • _DK

    Call me 'The Bald Guy"

  • Members
  • Joined: 12 Apr 2009
  • Ukraine

#4

Posted 03 January 2014 - 09:06 AM Edited by _DK, 03 January 2014 - 09:12 AM.

Wow I like his logic.
We have address for make vehicles driving on roads, why we can't make other things driving too?
  • LINK/2012 and SergeantSavidge like this

ZAZ
  • ZAZ

    Kernlochbohrer

  • Members
  • Joined: 10 Jan 2005
  • European-Union

#5

Posted 05 January 2014 - 03:41 PM

I want to change the color of objects per cleo, and not to change textures, I think there is an address change colors of objects, because it has some addresses that change the color of the environment, why not have an address change colors to objects ??

ok, moved back to coding


MasterHK
  • MasterHK

    کیان حامی

  • Members
  • Joined: 20 Mar 2013
  • Iran

#6

Posted 13 January 2014 - 03:40 PM

maybe this is useful : )


Manfred Von Karma
  • Manfred Von Karma

    Trick

  • Members
  • Joined: 16 Jun 2009
  • None

#7

Posted 04 March 2014 - 12:41 PM

sorry to bump this , but it is actually possible to change the RGBA of an object with cleo , I've just figured it out yesterday as i got the idea from this thread to investigate using RW Analyser, but it only works with non-textured objects .I'll post it later


_DK
  • _DK

    Call me 'The Bald Guy"

  • Members
  • Joined: 12 Apr 2009
  • Ukraine

#8

Posted 04 March 2014 - 08:36 PM

Yes you can do it by changing vertex colors in dff format.
But, while he posted this in Coding section, didn't he mean he wants to get it with CLEO/ASI?

Manfred Von Karma
  • Manfred Von Karma

    Trick

  • Members
  • Joined: 16 Jun 2009
  • None

#9

Posted 05 March 2014 - 04:40 PM

Yes you can do it by changing vertex colors in dff format.
But, while he posted this in Coding section, didn't he mean he wants to get it with CLEO/ASI?

It is possible to modify it with a CLEO script


_DK
  • _DK

    Call me 'The Bald Guy"

  • Members
  • Joined: 12 Apr 2009
  • Ukraine

#10

Posted 05 March 2014 - 06:40 PM

Yes if you know ASM and don't know how to code .asi plugins.

Manfred Von Karma
  • Manfred Von Karma

    Trick

  • Members
  • Joined: 16 Jun 2009
  • None

#11

Posted 05 March 2014 - 11:05 PM Edited by Manfred Von Karma, 05 March 2014 - 11:11 PM.

Code : 
Spoiler

 
 
SS:
 
Spoiler

 
 
 
Spoiler

 
 
 
Spoiler

 
 
 
 
There is no lighting in GTA:SA so the objects will appear dark if you dont create a small flashlight with 
09E5: create_flash_light_at 
 
 
Pretty useful for modders

_DK
  • _DK

    Call me 'The Bald Guy"

  • Members
  • Joined: 12 Apr 2009
  • Ukraine

#12

Posted 06 March 2014 - 03:07 AM

Okay, you deserved this code from me.
{$CLEO}

const
    in_MODEL_ID = 0@
    in_COLOR_R = 1@
    in_COLOR_G = 2@
    in_COLOR_B = 3@
    in_COLOR_A = 4@
    MODELINFO = 5@
    RWOBJECT = 6@
    GEOMETRY = 7@
    PRELIGHT = 8@
    NUM_VERTICES = 9@
    i = 10@
    OBJECT_TYPE = 11@
end

var
    9@ : Int
    10@ : Int
end

0000:

:main
while true
    wait 0
    if
        player.Defined(0)
    then
        // this code is not related to subject, let me use NO opcode here
        0D35: store_actor $PLAYER_ACTOR collided_entities_to 0@ -1 -1 -1 -1 -1
        if
            0@ <> 0
        then
            0@ += 0x22
            0A8D: 0@ = read_memory 0@ size 2 virtual_protect 0
            0AB1: call_scm_func @paintModel 5 _model 0@ _color 255 0 0 255
        end
    end
end

:paintModel
/*
  0AB1: call_scm_func @paintModel 5 _model 0@ _color 255 0 0 255
*/
// get model interface
0AA7: call_function 0x403DA0 num_params 1 pop 1 in_MODEL_ID : MODELINFO
if
    MODELINFO <> 0
then
    // get model rwObject
    0AA8: call_function_method 0x4C73A0 struct MODELINFO num_params 0 pop 0 : RWOBJECT
    if
        RWOBJECT <> 0
    then
        // get rwObject type
        0A8D: OBJECT_TYPE = read_memory RWOBJECT size 1 virtual_protect 0
        if
            OBJECT_TYPE == 2 // if clump object
        then
            // get clump atomic
            0AA7: call_function 0x734820 num_params 1 pop 1 RWOBJECT : RWOBJECT    
            if
                RWOBJECT == 0
            then
                0AD1: show_formatted_text_highpriority "Atomic error for this model %d" time 3000 in_MODEL_ID
                0AB2: ret 0
            end
        end
        // get atomic geometry
        0AA8: call_function_method 0x739B00 struct RWOBJECT num_params 0 pop 0 : GEOMETRY
        if
            GEOMETRY <> 0
        then
            // get geometry number of vertices
            0AA8: call_function_method 0x406E00 struct GEOMETRY num_params 0 pop 0 : NUM_VERTICES
            // get geometry prelit colors
            0AA8: call_function_method 0x404430 struct GEOMETRY num_params 0 pop 0 : PRELIGHT
            if
                PRELIGHT <> 0
            then
                // change color of each vertex
                0AA5: call 0x74C7D0 num_params 2 pop 2 1 GEOMETRY
                for i = 1 to NUM_VERTICES
                    0AA6: call_method 0x7170C0 struct PRELIGHT num_params 4 pop 0 in_COLOR_A in_COLOR_B in_COLOR_G in_COLOR_R
                    PRELIGHT += 4
                end
                0AA5: call 0x74C800 num_params 1 pop 1 GEOMETRY
            else
                0AD1: show_formatted_text_highpriority "No vertex colors for this model %d" time 3000 in_MODEL_ID
            end
        else
            0AD1: show_formatted_text_highpriority "Geometry error for this model %d" time 3000 in_MODEL_ID
        end
    else
        0AD1: show_formatted_text_highpriority "RwObject error for this model %d" time 3000 in_MODEL_ID
    end
end
0AB2: ret 0
  • Wesser likes this

Manfred Von Karma
  • Manfred Von Karma

    Trick

  • Members
  • Joined: 16 Jun 2009
  • None

#13

Posted 06 March 2014 - 06:41 PM Edited by Manfred Von Karma, 06 March 2014 - 06:41 PM.

Thanks mate , that was kind from you :) , but i've got a question : What is the function address that returns how much material an object has ?


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci Racing
  • Joined: 19 Aug 2006
  • Unknown

#14

Posted 07 March 2014 - 01:57 PM Edited by Wesser, 07 March 2014 - 02:48 PM.

_DK, your script explains the subject very well but the prelight part lacks of the optimization, as the script would make the game lagging for a while if the atomic vertices to process at a time are too much:
{$CLEO}

0000: NOP

const
    MODEL_WOODENBOX = 1224
end
const
    RWOBJECT_CLUMP  = 2
end
const
    _setGeometryVertexColor        = 0x005DD1E0
    _SAFE_setGeometryVertexColor   = 29@
    _atomicSetColorForAllVertices  = 28@
    _atomicSetColorForAllMaterials = 27@
    _setMaterialColorCB            = 26@
    _RpClumpForAllAtomics          = 25@
    _RpGeometryForAllMaterials     = 24@
end

0A9F: 31@ = current_thread_pointer
0A8E: 30@ = 31@ + 0x10 // CRunningScript_m_iBaseAddress
0A8D: 30@ = read_memory 30@ size 4 virtual_protect 0
0A8F: _SAFE_setGeometryVertexColor = 30@ - @_SAFE_setGeometryVertexColor
0A8F: _atomicSetColorForAllVertices = 30@ - @_atomicSetColorForAllVertices
0A8F: _atomicSetColorForAllMaterials = 30@ - @_atomicSetColorForAllMaterials
0A8F: _setMaterialColorCB = 30@ - @_setMaterialColorCB

0A8D: _RpClumpForAllAtomics = read_memory 0x00479143 size 4 virtual_protect 1
_RpClumpForAllAtomics += 0x00479147
0A8D: _RpGeometryForAllMaterials = read_memory 0x004C781E size 4 virtual_protect 1
_RpGeometryForAllMaterials += 0x004C7822

0A8E: 23@ = _SAFE_setGeometryVertexColor + 0x0B
0A8E: 22@ = 23@ + 4
0A8F: 21@ = _setGeometryVertexColor - 22@
0A8C: write_memory 23@ size 4 value 21@ virtual_protect 0

0A8E: 23@ = _atomicSetColorForAllVertices + 0x0E
0A8E: 22@ = 23@ + 4
0A8F: 21@ = _SAFE_setGeometryVertexColor - 22@
0A8C: write_memory 23@ size 4 value 21@ virtual_protect 0

0A8E: 23@ = _atomicSetColorForAllMaterials + 0x11
0A8C: write_memory 23@ size 4 value _setMaterialColorCB virtual_protect 0
0A8E: 23@ = _atomicSetColorForAllMaterials + 0x17
0A8E: 22@ = 23@ + 4
0A8F: 21@ = _RpGeometryForAllMaterials - 22@
0A8C: write_memory 23@ size 4 value 21@ virtual_protect 0

0247: load_model MODEL_WOODENBOX
while 8248:  not model MODEL_WOODENBOX available
    wait 0
end
0107: 0@ = create_object MODEL_WOODENBOX at 2488.562 -1666.865 12.8757
0249: release_model MODEL_WOODENBOX

while true
    wait 0
    //0A96: 1@ = actor $PLAYER_ACTOR struct
    0A98: 1@ = object 0@ struct
    0A8E: 2@ = 1@ + 0x18 // CEntity.m_pstRwObject
    0A8D: 2@ = read_memory 2@ size 4 virtual_protect 0
    if
        2@ <> 0
    then
        0A8D: 3@ = read_memory 2@ size 1 virtual_protect 0 // SRwObject.m_cType
        if
            3@ == RWOBJECT_CLUMP
        then
            //0AA5: call _RpClumpForAllAtomics num_params 3 pop 3 stColor 0xFF00A7E7 pcbAtomic _atomicSetColorForAllMaterials pstClump 2@
            0AA5: call _RpClumpForAllAtomics num_params 3 pop 3 stColor 0xFF00A7E7 pcbAtomic _atomicSetColorForAllVertices pstClump 2@
        else
            //0AA5: call _atomicSetColorForAllMaterials num_params 2 pop 2 stColor 0xFF00A7E7 pstAtomic 2@
            0AA7: call_function _atomicSetColorForAllVertices num_params 2 pop 2 stColor 0xFF00A7E7 pstAtomic 2@ bHasPrelit 4@
            if
            08B7:   test 4@ bit 0
            then
                // Atomic has prelight.
            else
                // Atomic doesn't have prelight.
            end
        end
    end
end

{
    bool __cdecl SAFE_setGeometryVertexColor(RpGeometry *pstGeometry, RwRGBA stColor) (
        __asm (
            push    esi
            mov     eax, [esp+4+stColor]
            push    eax
            mov     esi, [esp+8+pstGeometry]
            call    setGeometryVertexColor
            add     esp, 4
            pop     esi
            ret
        )
    )
}
:_SAFE_setGeometryVertexColor
hex
    56              // 00000000 push    esi
    8B4424 0C       // 00000001 mov     eax, [esp+4+stColor]
    50              // 00000005 push    eax
    8B7424 0C       // 00000006 mov     esi, [esp+8+pstGeometry]
    E8 00000000     // 0000000A call    setGeometryVertexColor
    83C4 04         // 0000000F add     esp, 4
    5E              // 00000012 pop     esi
    C3              // 00000013 ret
//  90              // 00000014 nop
//  90              // 00000015 nop
//  90              // 00000016 nop
//  90              // 00000017 nop
//  90              // 00000018 nop
//  90              // 00000019 nop
//  90              // 0000001A nop
//  90              // 0000001B nop
//  90              // 0000001C nop
//  90              // 0000001D nop
//  90              // 0000001E nop
//  90              // 0000001F nop
end

{
    bool atomicSetColorForAllVertices(SRpAtomic *pstAtomic, SRwRGBA stColor) (
        return setGeometryVertexColor(pstGeometry, stColor);
    )
}
:_atomicSetColorForAllVertices
hex
    8B4424 08       // 00000000 mov     eax, [esp+stColor]
    50              // 00000004 push    eax
    8B4C24 08       // 00000005 mov     ecx, [esp+4+pstAtomic]
    8B51 18         // 00000009 mov     edx, [ecx+SRpAtomic.m_pstGeometry]
    52              // 0000000C push    edx
    E8 00000000     // 0000000D call    SAFE_setGeometryVertexColor
    83C4 08         // 00000012 add     esp, 8
    C3              // 00000015 ret
//  90              // 00000016 nop
//  90              // 00000017 nop
//  90              // 00000018 nop
//  90              // 00000019 nop
//  90              // 0000001A nop
//  90              // 0000001B nop
//  90              // 0000001C nop
//  90              // 0000001D nop
//  90              // 0000001E nop
//  90              // 0000001F nop
end

{
    SRpGeometry *atomicSetColorForAllMaterials(SRpAtomic *pstAtomic, SRwRGBA stColor) (
        SRpGeometry *pstGeometry;

        pstGeometry = pstAtomic->m_pstGeometry;
        pstGeometry->m_uiFlags |= 0x40;

        return RpGeometryForAllMaterials(pstGeometry, setMaterialColorCB, stColor);
    )
}
:_atomicSetColorForAllMaterials
hex
    8B4424 04       // 00000000 mov     eax, [esp+pstAtomic]
    8B40 18         // 00000004 mov     eax, [eax+SRpAtomic.m_pstGeometry]
    804808 40       // 00000007 or      [eax+SRpGeometry.m_uiFlags], 40h
    8B4C24 08       // 0000000B mov     ecx, [esp+stColor]
    51              // 0000000F push    ecx
    68 00000000     // 00000010 push    offset setMaterialColorCB
    50              // 00000015 push    eax
    E8 00000000     // 00000016 call    RpGeometryForAllMaterials
    83C4 0C         // 0000001B add     esp, 0Ch
    C3              // 0000001E retn
//  90              // 0000001F nop
end

{
    SRpMaterial *setMaterialColorCB(SRpMaterial *pstMaterial, SRwRGBA stColor) (
        pstMaterial->m_stColor = stColor;

        return pstMaterial;
    )
}
:_setMaterialColorCB
hex
    8B4424 04       // 00000000 mov     eax, [esp+pstMaterial]
    8B4C24 08       // 00000004 mov     ecx, [esp+stColor]
    8948 04         // 00000008 mov     [eax+SRpMaterial.m_stColor], ecx
    C3              // 0000000B ret
//  90              // 0000000C nop
//  90              // 0000000D nop
//  90              // 0000000E nop
//  90              // 0000000F nop
end
It also contains helper functions (those which have been commented out) for easily changing the color of all atomic materials.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users