Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

[ASI] SuperVars (featuring Objective-SCM)


Deji
 Share

Recommended Posts

Download

 

Please avoid "wotzit" questions, as the readme (available on the download page) explains just about everything. There are demo scripts provided with the download. SuperVars is heavily used in The Black Market Mod, which is why I'm releasing it now. I've had SuperVars for about a year now, so it's heavily tested, I just kept it to myself for a while... Selfish.

 

 

And, here is a bonus: https://pastebin.com/46ayUR24

 

I call this Objective-SCM (difficulty: Brainf*ck). Wotzit? It's a relatively low-level objective-oriented implementation for CLEO 4 (though it would only take replacing ALLOCATE_MEMORY to make it CLEO 3-friendly). Once you understand the example scripts given with SuperVars, this isn't too much to handle when using it but concentrate on the low-level source and your eyes may burn a bit. The source is pretty well commented, though. It's not included as part of the SuperVars example scripts as I consider it worthy of a bit more light, however this is a great example of SuperVars' power for this topic (its just best to see the example scripts with the download first).

 

Objective-SCM allows you to create your own virtual 'types' and create C++-like objects with them. For example:

 

CONSTCAnimal__SizeOf = 12CHuman__SizeOf = 4CDog__SizeOf = 0CCat__Sizeof = 0END:CAnimal // type()RET 3 @CAnimal_ctor 0 CAnimal__SizeOf:CHuman // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CHumanSizeOfRET 3 @CHuman_ctor 0 [email protected]:CDog // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CDogSizeOfRET 3 @CDog_ctor 0 [email protected]:CCat // (inherits CAnimal)0A8E: [email protected] = CAnimal__SizeOf + CCatSizeOfRET 3 @CCat_ctor 0 [email protected]

 

 

@CCat, for example, can now be passed to @new (just like the C++ new, see the Objective-SCM :new source for more info) which initialises a 12 byte structure, or an array of 12 byte structures:

 

 

CALL @new @CCat 1 [email protected]

 

 

@CCat_ctor is a constructor (0 is the destructor param, use 0 to not use a constructor/destructor), which will be automatically called by @new after allocation, or in the case of an array, will call the constructor for every object in the array after allocation:

 

 

CONSTthis = [email protected]_Type = [email protected]_NumLegs = [email protected]_HasTail = [email protected]_NumArms = [email protected]_TYPE_UNSPECIFIED = -1ANIMAL_TYPE_HUMAN = 0ANIMAL_TYPE_DOG = 1ANIMAL_TYPE_CAT = 2SuperVar = stringENDVARthis: array 4 of SuperVarEND:CAnimal_ctor{\__(obj*)__}0006: this[this] = @CAnimal_VTBL   // default VTBL for abstract class0006: this[this] = ANIMAL_TYPE_UNSPECIFIEDRET 0:CHuman_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[CAnimal_Type] = ANIMAL_TYPE_HUMAN0006: this[CAnimal_NumLegs] = 20006: this[CAnimal_HasTail] = FALSE0006: this[CHuman_NumArms] = 2RET 0:CDog_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[this] = @CDog_VTBL0006: this[CAnimal_Type] = ANIMAL_TYPE_DOG0006: this[CAnimal_NumLegs] = 40006: this[CAnimal_HasTail] = TRUERET 0:CCat_ctor{\__(obj*)__}CALL @CAnimal_ctor 1 this0006: this[this] = @CCat_VTBL0006: this[CAnimal_Type] = ANIMAL_TYPE_CAT0006: this[CAnimal_NumLegs] = 40006: this[CAnimal_HasTail] = TRUERET 0

 

 

Here we have a constructor setting the default (initial) values of a 'CDog', 'CCat' or 'CAnimal'. It also sets a 'virtual table', so lets have a look at them...

 

 

:[email protected][email protected][email protected]_SpeakEND:[email protected][email protected][email protected]_SpeakEND:[email protected][email protected][email protected]_SpeakEND

 

 

Note that the first field of the VTBL must be a pointer to the object base VTBL. Actually, you could also have the first field point to another virtual table, and have that point to the object base VTBL, and so on...

 

 

:CAnimal_SpeakPRINTSTRING "Hello"RET 0:CCat_SpeakPRINTSTRING "Miaow"RET 0:CDog_SpeakPRINTSTRING "Woof"RET 0:CAnimal_GetNumLegsRET 1 this[CAnimal_NumLegs]

 

 

So calling GetNumLegs with a cat would return 4, for a dog it would also return 4, but for a human it would return 2.

 

But for 'Speak', different animal classes have to use different methods, as they all speak differently. If we knew our object type was definitely a CDog, we could just do:

 

CALL @CDog_Speak 1 [email protected]   // [email protected] was returned from @new

 

 

However, the idea of a virtual table is that we could also have a different VTBL for a similar object, but we could still call the same method:

 

CONSTCAnimal_Speak = [email protected]   // index of the Speak method for each CAnimal object's VTBLENDCALL [email protected](CAnimal_Speak,4s) [email protected]

 

 

If [email protected] is a CCat, it will print "Miaow", if it's a CDog, it will print "Woof" and the default method is "Hello", which will cover a CHuman and any other CAnimal-based type which is created without it's own unique VTBL.

 

 

 

Don't worry, lots of confusion and questions are expected, unless you are both a CLEO and C++ pro, so fire away.

 

Cheerio.

 

Download

Edited by Deji
  • Like 1
Link to comment
Share on other sites

Awesome work, Deji. I was planning something similar as a feature of a new SCR compiler.

 

Basically, you enhanced your CLEO's technique for adding new local variables and took advantage of it to make a C-like class, by passing negative local variables as array index. A tricky and cleaver method. Again, great job. icon14.gif

Edited by Wesser

012          345
678   9A   BCD
EFG HIJK LMN
OPQR  STUV
WX    YZ

Link to comment
Share on other sites

You did it well.

Unsigned 32768 to 65536 index wouldn't be used in regular scripts, while it may be used in old local additional variable access method, which will still work, if flag of SuperVars is disabled.

Link to comment
Share on other sites

Thanks, I was planning on taking over the 'v' string array vars, too (they're a bit more commonly used, but SuperVars will still work with naturally with em) but I'm really wondering what the most important new ability would be. Call-time pass by pointer would be kinda nice, but CLEO 4's GET_VAR_POINTER handles that fine... But more important would have to be the ability to read the number of bytes specified as the array size paramter (which would be great since the array size parameter is never even used by the game). That way we'd have full access of SA object classes using SuperVars as well as being able to make less space consuming classes with Objective-SCM. Having to rethink the offset according to the size you want to read may be a little annoying though...

 

Another tip, for SCM functions, I like to store my important SuperVar indexes to a label of script memory and make a GOSUB which will read it, accessible by any SCM function. Saves having to pass the SuperVar as the first param for every SCM func, you just gotta make sure you store any params passed before reading the SuperVar index (if the SuperVar variable is [email protected]):

 

:Push{\__(Val)__}0085: [email protected] = [email protected] @GetGlobalVarIndex0085: [email protected] = gStackPointer0085: [email protected]([email protected],4s) = [email protected]: gStackPointer += 4RET 0:Pop{\__[Val]__}GOSUB @GetGlobalVarIndex000E: gStackPointer -= 40085: [email protected] = gStackPointerRET 1 [email protected]([email protected],4s):GetGlobalVarIndexSET_BIT_L [email protected] 8SVar = @GLOBAL_VARIABLES_INDEX0085: SVar = SVar(SVar,4s)RETURN:GLOBAL_VARIABLES_INDEXHEX00000000END

 

 

p.s. thank Silent for the idea of SuperVars installation checking and Objective-SCM name tounge.gif

Edited by Deji
Link to comment
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
 Share

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

×
×
  • Create New...

Important Information

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