Quantcast

Jump to content

» «
Photo

[REL|SA] Spooky-style SCM Hook

52 replies to this topic
JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#1

Posted 14 November 2007 - 05:58 PM Edited by Dutchy3010, 26 August 2009 - 09:05 AM.

I have created an SCM hook for GTA: San Andreas that works like Spooky's SCM hook for VC, with script classes and such. However, it runs next to the original SCM so the original missions will still be available. It is based on my SA Injector, so it has full CRT functionality. It also has an GXT hook for custom text entries. A lot of code is just robbed from either op9080's SA SCM hook, spooky's VC SCM Hook and my own injector, credits to them!

I think it is quite self-explanatory, just look at CustomScript.cpp and CustomGXT.h

If you're having trouble with hash_map, change #define USE_HASH_MAP in commonincs.h into #define USE_HASH_MAP_IN_STDEXT, or if that doesn't work, just delete that line. Performance will drop sligthly in that case.

Download link (current version: v3): http://www.pawfectfi...A_Injector3.zip

Changelog:

v1: initial version

v2: added an op9080-hook-like script class

v3: added support for using -1 instead of actor variable, fixed some issues in opcodes.h

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"

#2

Posted 15 November 2007 - 11:17 AM

Does it require the DirectX SDK to be compiled? If so, for what?

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#3

Posted 15 November 2007 - 04:10 PM

QUOTE (Seemann @ Nov 15 2007, 11:17)
Does it require the DirectX SDK to be compiled? If so, for what?

Nope, it doesn't need the DX SDK smile.gif .

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#4

Posted 15 November 2007 - 04:45 PM

This is truly "All that." Seriously.

CRT stuff, multiple threads, GXT goodies ,existing SCM untouched. Egads, it's almost too good to be true. happy.gif I'll provide my updated Opcodes.h here for those that use this hook.

Great job, JGuntherS@NL!!!

aad
  • aad

    3d artist

  • Feroci
  • Joined: 15 Mar 2004
  • None

#5

Posted 15 November 2007 - 07:01 PM

QUOTE (JGuntherS@NL @ Nov 14 2007, 17:58)
I have created an SCM hook for GTA: San Andreas that works like Spooky's SCM hook for VC, with script classes and such. However, it runs next to the original SCM so the original missions will still be available. It is based on my SA Injector, so it has full CRT functionality. It also has an GXT hook for custom text entries. A lot of code is just robbed from either op9080's SA SCM hook, spooky's VC SCM Hook and my own injector, credits to them!

I think it is quite self-explanatory, just look at CustomScript.cpp and CustomGXT.h

If you're having trouble with hash_map, change #define USE_HASH_MAP in commonincs.h into #define USE_HASH_MAP_IN_STDEXT, or if that doesn't work, just delete that line. Performance will drop sligthly in that case.

Download link: http://jesse.thorbit...ect/scmhook.zip

Hope it works with Visual Studio 6, if not then i really need to get an other version right away.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#6

Posted 15 November 2007 - 07:42 PM Edited by JGuntherS@NL, 15 November 2007 - 07:46 PM.

QUOTE (aad @ Nov 15 2007, 19:01)
QUOTE (JGuntherS@NL @ Nov 14 2007, 17:58)
I have created an SCM hook for GTA: San Andreas that works like Spooky's SCM hook for VC, with script classes and such. However, it runs next to the original SCM so the original missions will still be available. It is based on my SA Injector, so it has full CRT functionality. It also has an GXT hook for custom text entries. A lot of code is just robbed from either op9080's SA SCM hook, spooky's VC SCM Hook and my own injector, credits to them!

I think it is quite self-explanatory, just look at CustomScript.cpp and CustomGXT.h

If you're having trouble with hash_map, change #define USE_HASH_MAP in commonincs.h into #define USE_HASH_MAP_IN_STDEXT, or if that doesn't work, just delete that line. Performance will drop sligthly in that case.

Download link: http://jesse.thorbit...ect/scmhook.zip

Hope it works with Visual Studio 6, if not then i really need to get an other version right away.

Everything should work, except MSVC++ 6 doesn't have the hash_map by default. You could implement it yourself, find the correct files somewhere or just update to MSVC2003, which is what I'd advise you to do tounge.gif . If you want to use it with MSVC6 without hash_map, comment out or delete the line #define USE_HASH_MAP in commonincs.h.

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"

#7

Posted 16 November 2007 - 09:53 AM

OK, I can confirm that with some changes it works with Visual Studio 2005 (VS8). Good work! icon14.gif

However, CLEO 3 scripts seem to be more user-friendly even without object-oriented programming stuff, IMO.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#8

Posted 16 November 2007 - 04:18 PM

I've uploaded a new version, this version also supports to some extent the way op9080 uses to script in C++.

Example code:
CODE
theScript << interior_access << "PDOMES" << 1 << EXEC;


A bit of a 'best of both worlds' idea smile.gif .

PS: more examples are inside the box wink.gif .

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#9

Posted 16 November 2007 - 11:06 PM Edited by ceedj, 17 November 2007 - 02:02 AM.

CODE
DEFINE_OPCODE(put_player, 0x0055, "vfff");
DEFINE_OPCODE(create_coordinate, 0x0400, "vfffvvv");


No longer supported in SA. There are a few others; I'll weed 'em out as I go. smile.gif

EDIT: Just a reminder: with multiple threads now, make sure your "waits" are distributed properly; this impacts which threads get higher priority. Not new info by any stretch, but after using one thread with the C++ hooks for so long, you tend to forget. wink.gif

EDIT 2:
CODE
DEFINE_OPCODE(get_car_color, 0x03F3, "vii");   // var_car col1 col2


Change the "vii" to "vvv", or your game will crash if you try to get colors from cars.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#10

Posted 24 November 2007 - 01:43 PM Edited by JGuntherS@NL, 24 November 2007 - 01:54 PM.

I've uploaded a new version that supports the substitution of an actor variable with -1, which is used in defining actor animation sequences. Things like
CODE
CallOpcode(&AT_look_around, -1);
should work now smile.gif .

I also used ceedj's suggestions to modify opcodes.h, thanks for that smile.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#11

Posted 27 November 2007 - 01:45 AM Edited by ceedj, 27 November 2007 - 01:48 AM.

QUOTE (JGuntherS@NL @ Nov 24 2007, 08:43)
I've uploaded a new version that supports the substitution of an actor variable with -1, which is used in defining actor animation sequences. Things like
CODE
CallOpcode(&AT_look_around, -1);
should work now smile.gif .

I also used ceedj's suggestions to modify opcodes.h, thanks for that smile.gif

Just to clarify, it's not just for actors; this fix works with any opcode that takes either a handle or -1 as a parameter. smile.gif When setting up opcodes in Opcodes.h, just make the parameter in question a v.

Hey JGS, how can we add NOT to opcodes? Doing CallOpcode(!&blapcode); throws a compilation error. I'm just creating a second opcode for now:

(blahpcode, "0x0684", "")

(nblahpcode, "0x8684", "")

Any ideas?

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#12

Posted 30 November 2007 - 05:28 PM Edited by JGuntherS@NL, 30 November 2007 - 05:34 PM.

QUOTE (ceedj @ Nov 27 2007, 01:45)
QUOTE (JGuntherS@NL @ Nov 24 2007, 08:43)
I've uploaded a new version that supports the substitution of an actor variable with -1, which is used in defining actor animation sequences. Things like
CODE
CallOpcode(&AT_look_around, -1);
should work now smile.gif .

I also used ceedj's suggestions to modify opcodes.h, thanks for that smile.gif

Just to clarify, it's not just for actors; this fix works with any opcode that takes either a handle or -1 as a parameter. smile.gif When setting up opcodes in Opcodes.h, just make the parameter in question a v.

Hey JGS, how can we add NOT to opcodes? Doing CallOpcode(!&blapcode); throws a compilation error. I'm just creating a second opcode for now:

(blahpcode, "0x0684", "")

(nblahpcode, "0x8684", "")

Any ideas?

You could use
CODE
if (!CallOpcode(&..., ...))
That'll work, as it's just a C not wink.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#13

Posted 01 December 2007 - 01:20 PM

You know, I hate it when you make it look SO easy. Jerk. tounge.gif

Thanks buddy. smile.gif

Oh yeah, can I use readSCMvar(blah) anywhere I need to? Would be useful for scm mods like Space's All in One, etc.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#14

Posted 01 December 2007 - 02:00 PM

QUOTE (ceedj @ Dec 1 2007, 13:20)
You know, I hate it when you make it look SO easy. Jerk. tounge.gif

Thanks buddy. smile.gif

Oh yeah, can I use readSCMvar(blah) anywhere I need to? Would be useful for scm mods like Space's All in One, etc.

Yes, you can smile.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#15

Posted 04 December 2007 - 05:48 PM

Sorry if this seems goofy, but I'm having a problem with this:

CODE
float* pfGravity = (float*)0x863984;
*pfGravity = 0.008f


Is crashing the game. Actually, it's just the second line. I tested it further by doing this:

CODE
CallOpcode(&toggle_hud, 0);
CallOpcode(&toggle_radar, 0);
SCRIPT_WAIT(5000);
*pfGravity = 0.008f;


Sure enough, crash after a 5 second wait. I know the addy is ok, but this is the same way I did it in Spookie's VC hook for LC. Is there something I'm missing?

Peter
  • Peter

    Secretly Heroic

  • Members
  • Joined: 21 Sep 2006
  • United-Kingdom

#16

Posted 04 December 2007 - 06:21 PM

Check out VirtualProtect, the memory address you're trying to write to is write-protected, you need to get access first smile.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#17

Posted 04 December 2007 - 06:28 PM Edited by ceedj, 04 December 2007 - 08:21 PM.

I had a feeling, but wasn't sure how to do it with floats. I'll look into it some more. Thanks very much for the help. smile.gif

EDIT: Ok, I got it to work. A bit inelegant though. Sacky gave me this for my custom loading screens:

CODE
void Patch_DEF ( DWORD dwAddress,  BYTE *bRawData, int iSize )
{
DWORD dw[2];
VirtualProtect ( (PVOID) dwAddress, iSize, PAGE_EXECUTE_READWRITE, &dw[0] );
memcpy ( (PVOID) dwAddress, bRawData, iSize );
VirtualProtect ( (PVOID) dwAddress, iSize, dw[0], &dw[1] );
}


My code for gravity:
CODE

BYTE bGravity[] = { 0x6F, 0x12, 0x83, 0x3B };
Patch_DEF(0x863984, bGravity, 4);


That translates to 0.004, (3B83126F) or half-gravity. My question: can anyone suggest a way to use the float value instead? Not a huge deal, but I want to add gravity values to my config file; I think 1 float is easier to deal with than hex combos. Thanks. smile.gif

UZI-I
  • UZI-I

    WPL Manager...

  • Members
  • Joined: 23 Aug 2006

#18

Posted 04 December 2007 - 09:42 PM

CODE
DWORD dw[2];
VirtualProtect ( (PVOID) 0x863984 , 4, PAGE_EXECUTE_READWRITE, &dw[0] );
*(float*)0x863984 = 0.004f;
VirtualProtect ( (PVOID) 0x863984 , 4, dw[0], &dw[1] );


biggrin.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#19

Posted 04 December 2007 - 09:55 PM Edited by ceedj, 04 December 2007 - 09:57 PM.

Thanks for that; there's not nearly enough examples on how to best use SA memory stuff with C++. smile.gif

UZI-I
  • UZI-I

    WPL Manager...

  • Members
  • Joined: 23 Aug 2006

#20

Posted 04 December 2007 - 10:09 PM Edited by UZI-I, 04 December 2007 - 10:11 PM.

np

In-process its better to use Pointer stuff biggrin.gif

Peter
  • Peter

    Secretly Heroic

  • Members
  • Joined: 21 Sep 2006
  • United-Kingdom

#21

Posted 05 December 2007 - 07:34 AM

Just wait until you figure out what you can do with hooking full functions, you'll be amazed smile.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#22

Posted 05 December 2007 - 08:17 AM Edited by ceedj, 05 December 2007 - 01:00 PM.

QUOTE (.Peter @ Dec 5 2007, 02:34)
Just wait until you figure out what you can do with hooking full functions, you'll be amazed smile.gif

That is the absolute nicest way I've ever been called a complete idiot. Thanks. lol.gif

Sacky
  • Sacky

    IV's Limit Adjuster

  • Members
  • Joined: 10 Nov 2006

#23

Posted 05 December 2007 - 12:25 PM

If you want a nice little float patch function try this:

CODE
void Patch_Float(DWORD dwAddress,float fltData)
{
char* cTmp = (char*)&fltData;
BYTE bTmp[] = { cTmp[0], cTmp[1], cTmp[2], cTmp[3] };
Patch(dwAddress,bTmp);
}


Use:

CODE
Patch_Float(0x863984,0.008f);

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#24

Posted 10 December 2007 - 06:54 PM

Bee-u-ti-fal! biggrin.gif Thanks Sacky.

CODE
DEFINE_OPCODE(set_car_speed_now, 0x04AB, "vf");


Switch to 04BA.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#25

Posted 10 December 2007 - 08:50 PM

QUOTE (ceedj @ Dec 10 2007, 18:54)
Bee-u-ti-fal! biggrin.gif Thanks Sacky.

CODE
DEFINE_OPCODE(set_car_speed_now, 0x04AB, "vf");


Switch to 04BA.

Fixed smile.gif

Furthermore:
CODE
void Patch_Float(DWORD dwAddress,float fltData)
{
   Patch(dwAddress,*((DWORD *)&fltData));
}

This might be a little bit neater, but it doesn't matter much smile.gif .

DexX
  • DexX

    Black Hat

  • Feroci
  • Joined: 16 May 2002

#26

Posted 12 December 2007 - 11:08 AM

QUOTE (Seemann @ Nov 16 2007, 03:53)
OK, I can confirm that with some changes it works with Visual Studio 2005 (VS8). Good work!  icon14.gif

However, CLEO 3 scripts seem to be more user-friendly even without object-oriented programming stuff, IMO.

care to list those changes? i tried building the project in VS 2005 Express, and get a hefty 39 errors, 20 warnings.

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"

#27

Posted 12 December 2007 - 03:07 PM

Well, I have VS2008 Pro, so you might have problems with the Platform SDK, do you have one?

I just checked the latest version and all I was need to do is to comment out the line '#define USE_HASH_MAP' in the commonincs.h to get the project compiled successfully.

It's strange as I remember I replaced all occurences of the 'strcpy' function with the 'strcpy_s' one in one of the previous releases.

What errors do you get?

DexX
  • DexX

    Black Hat

  • Feroci
  • Joined: 16 May 2002

#28

Posted 12 December 2007 - 03:24 PM

QUOTE (Seemann @ Dec 12 2007, 09:07)
Well, I have VS2008 Pro, so you might have problems with the Platform SDK, do you have one?

due to the size of the PSDK, i don't update it very often (i'm on 56k), so i have the same version i installed about a year ago. and to say i have "problems" with it, is to describe my entire experience with it!

as for the errors, here's my buildlog before i comment out the hash map line...
www.3dhole.com/gtafiles/BuildLog_prehash.htm
and after...
www.3dhole.com/gtafiles/BuildLog_posthash.htm
After i comment it out, i get a mere 3 errors.

JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#29

Posted 12 December 2007 - 05:14 PM Edited by JGuntherS@NL, 12 December 2007 - 05:23 PM.

QUOTE (DexX @ Dec 12 2007, 15:24)
QUOTE (Seemann @ Dec 12 2007, 09:07)
Well, I have VS2008 Pro, so you might have problems with the Platform SDK, do you have one?

due to the size of the PSDK, i don't update it very often (i'm on 56k), so i have the same version i installed about a year ago. and to say i have "problems" with it, is to describe my entire experience with it!

as for the errors, here's my buildlog before i comment out the hash map line...
www.3dhole.com/gtafiles/BuildLog_prehash.htm
and after...
www.3dhole.com/gtafiles/BuildLog_posthash.htm
After i comment it out, i get a mere 3 errors.

It seems that your advapi32.lib is too old. The functions RegQueryValueEx and RegOpenKey have been introduced in Windows 2000, and I think your platform SDK is pre-2000. I uploaded the my advapi32.lib here: http://jesse.thorbit...oi/AdvAPI32.Lib

Edit: or do you actually have a pre-2000 Windows version?

Edit edit: it may be that these functions already existed prior to Windows 2000, I don't really get the MSDN sometimes tounge.gif

Edit edit edit: after you've downloaded advapi32.lib, you have to link your application against it of course

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • None

#30

Posted 20 December 2007 - 11:05 PM Edited by ceedj, 21 December 2007 - 12:18 AM.

Greetings. smile.gif

Having a small problem; I have a function that works in one thread but seems to be ignored in others. Any ideas on why this might be? Could this be similar to a problem I have with a set of action sequences (SA code) I have that all work in the main animation thread, but not the secondary one?

EDIT: Ok, it loads at the beginning of the thread I want, just not at the point in the thread that I want... confused.gif


Sigh. Any way I can just take the post back? No? Ok, might as well complete the embarrassment...

CODE
StoreMainCheck13:
if (TrailerCheck4 == 1)
{pTrailer4->GetCarCoord(&fT4X, &fT4Y, &fT4Z);
pTrailer4->GetCarZ(&fT4Zangle);
//if (FileStore == 1)
pGame->TextNow("STORE", 5000, 1);
FileSavePosition();
StoreAll = 1;
goto CreatePed1;
} else {
 StoreAll = 1;
 pGame->TextNow("STORE", 5000, 1);
 goto CreatePed1;}}


Yeah, that's right. I need to put FileSavePosition(); after the ELSE as well. What annoys me is that I spent several hours trying to figure this out, and I KNEW it would be something stupid. Gah. Sorry for the trouble. lol.gif

EDIT: In case anyone's interested, this is my resulting output file (go me!):

CODE
################################
#San An Studios 4 Save File
#EDIT AT YOUR OWN RISK!!!
#REMEMBER, IF YOU BREAK IT, I'LL LAUGH! :p
################################
#
#Ped1
#Ped Number, Special Actor/Model ID, Special Switch
1 9 0
#Coords (X, Y, Z, Z Angle)
2030.196 996.363 10.813 84.121
#
#Ped2
#Ped Number, Special Actor/Model ID, Special Switch
2 BBTHIN 1
#Coords (X, Y, Z, Z Angle)
2030.503 994.693 10.813 66.205
#




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users