Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper for opcodes is missing #34

Closed
goodidea82 opened this issue Jun 29, 2017 · 4 comments
Closed

Wrapper for opcodes is missing #34

goodidea82 opened this issue Jun 29, 2017 · 4 comments
Labels

Comments

@goodidea82
Copy link

goodidea82 commented Jun 29, 2017

Some earlier version had a wrapper (SCMWrapper) for opcodes (developed by fastman92), but now the API is missing:
https://github.com/DK22Pac/plugin-sdk/blob/master/src/sdk/plugin/script/wrapper.h
This API is important for because I already have a lot of custom code that depend on it.

(Some background: http://gtaforums.com/topic/838490-cleo-plugin-how-to-call-an-opcode-within-a-cleo-plugin/?p=1068513051)

@DK22Pac
Copy link
Owner

DK22Pac commented Jun 29, 2017

It's possible to "call" an opcode in this way:

#include "extensions\ScriptCommands.h"
using namespace plugin::test;
// ...
ScriptCommand<PRINT_NOW>("FEC_INC", 150, 1);
#include "plugin_III.h"
#include "extensions\ScriptCommands.h"

using namespace plugin;
using namespace plugin::test;

class Gta3ScriptCommandsTest {
public:
    Gta3ScriptCommandsTest() {
        Events::processScriptsEvent += [] {

            int PlayerChar, PlayerCar;
            float CoordX, CoordY, CoordZ;

            if (ScriptCommand<IS_PLAYER_PLAYING>(0))
            {
                ScriptCommand<GET_PLAYER_CHAR>(0, &PlayerChar);
                if (ScriptCommand<IS_CHAR_IN_ANY_CAR>(PlayerChar))
                {
                    ScriptCommand<STORE_CAR_CHAR_IS_IN_NO_SAVE>(PlayerChar, &PlayerCar);
                    ScriptCommand<GET_CAR_COORDINATES>(PlayerCar, &CoordX, &CoordY, &CoordZ);
                    ScriptCommand<DRAW_SHADOW>(3, CoordX, CoordY, CoordZ, 0.0f, 3.0f, 150, 255, 0, 0);
                    ScriptCommand<PRINT_NOW>("FEC_INC", 150, 1);
                }
            }
        };
    }
} test;

@goodidea82
Copy link
Author

goodidea82 commented Jun 30, 2017

Thanks for the quick reply.
I have a special use case where wrapper functions are automatically generated for opcodes.

Can I use hex-numbers instead of opcode names? E.g.
ScriptCommand< 0x00AA >(PlayerCar, &CoordX, &CoordY, &CoordZ);

Do I need the "Events::processScriptsEvent += [] {...}" to call an opcode and what does it mean?

I want the called opcode have the same effect on the current thread as a normal opcode would have. How do I pass the thread-pointer to the ScriptCommand? (or obtain a thread pointer if it has its own thread) In my code I have a function "copyThreadAttrToWrapper" that translates the state from the current thread to the fastman's SCMwrapper's thread and "copyWrapperToThread" to translate it back.

Here is an example of what I mean:

void op00A0(DWORD actHandle1, float& varX2, float& varY3, float& varZ4){
SCMwrapper.PushInt(actHandle1, true);
SCMwrapper.PushFloat(varX2, true);
SCMwrapper.PushFloat(varY3, true);
SCMwrapper.PushFloat(varZ4, true);
copyThreadAttrToWrapper(curThread, SCMwrapper, (curThread->notFlag? 0x80A0: 0x00A0));
cmdResult = SCMwrapper.CallCommand(curThread->notFlag? 0x80A0: 0x00A0);
copyWrapperToThread(SCMwrapper, curThread);
SCMwrapper.SaveReturnedValues(retVal);
varX2 = varX(retVal.returnedValues[1].Float);
varY3 = varY(retVal.returnedValues[2].Float);
varZ4 = varZ(retVal.returnedValues[3].Float);
}

The easiest for me would be if fastman's SCMwrapper API would be added back.

@DK22Pac
Copy link
Owner

DK22Pac commented Jul 3, 2017

Can I use hex-numbers instead of opcode names?

Yes.

Do I need the "Events::processScriptsEvent += [] {...}" to call an opcode and what does it mean?

It's recommended to 'call' opcodes when scripts are 'processed' (i.e. executed). That's why processScriptsEvent event is used in this example.

How do I pass the thread-pointer to the ScriptCommand?

Not possible yet.

@goodidea82
Copy link
Author

goodidea82 commented Jul 20, 2017

I have copied this thread here: http://gtaforums.com/topic/838490-cleo-plugin-how-to-call-an-opcode-within-a-cleo-plugin/?p=1069733231
because I don't know where to find again it when the issue is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants