Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Bad.boy!

cleo file structure

Recommended Posts

Bad.boy!

Does anyone know where I can find info about the structure of a cleo file. I want to know what globals and locals compiles in. And what jumps, gosubs, thread names etc. compile in to. Is there also some sort of documentation of opcode's hex values. I need to know this, for making a high end compiler that doesn't make double jumps and compiles better.

Share this post


Link to post
Share on other sites
Silent

Sanny compiles perfectly if your script is good enough.

Share this post


Link to post
Share on other sites
Bad.boy!

Can't find the file that had double jumps, anyway I still want to make my own compiler. So can someone share their knowledge about this.

 

And more specific:

If I compile "0000: NOP" where does it compile into (hex values)?

Share this post


Link to post
Share on other sites
fastman92

Some things are covered here:

http://www.mediafire.com/?xrq6v1z1l5zwr8b

 

What are labels: there are no registered labels in structure of SCM file. They are just negative INT offsets relative to beginning of script.

A jump to offset 800 would be jump to -800 as INT value, usually 4-byte number, but not limited to.

 

Bad.boy!, you need to have a strong knowledge of C++ or any other programming language, in other case you're not gonna success.

Edited by fastman92

Share this post


Link to post
Share on other sites
Bad.boy!

 

Some things are covered here:

http://www.mediafire.com/?xrq6v1z1l5zwr8b

 

What are labels: there are no registered labels in structure of SCM file. They are just negative INT offsets relative to beginning of script.

A jump to offset 800 would be jump to -800 as INT value, usually 4-byte number, but not limited to.

 

Bad.boy!, you need to have a strong knowledge of C++ or any other programming language, in other case you're not gonna success.

I know I probably won't succeed in making a full compiler. But I'll start small, I try to add ±10 opcodes and a simple struct. Then the most difficult part converting text into something that GTA can read.

 

About the labels, how does Sanny Builder know what number of a label should be. It has to be a higher number each time or does it need to have more then just a higher number. What are the requirements for a label?

 

EDIT: I've been quiet stupid about the opcodes, they are hex already (0A93 = 93 0A).

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
fastman92

Sanny Builder creates a binary code at first. It uses array to store references to labels.

Tha means, during compilation whole binary code is created at first, but labels are missing. It saves in array, for example that there is reference to @mylabel on 55. It has array to store label position of compiled file too. For example :mylabel is compiled on 30

It will put on 55 position, offset -30 (negative numbers are used).

 

Opcode numbers are WORD values (16 bits = 2 bytes) whereas oldest bit states whether conditional result from opcode should be negated and last 15 bits is number of opcode.

There are possibily 0x7FFF + 1 opcodes equal to 8192.

Edited by fastman92

Share this post


Link to post
Share on other sites
Bad.boy!

I have a question about the check if $PLAYER_CHAR ($2) is defined.

 

56 02 + Player (02 08 00?)

 

 

Why is $2 "02 08 00". 08 = $2 I guess but why?

 

 

Nevermind I found out that I have to divide the variable by 4.

56 02 + 02 (GLOBAL) + X (VARIABLE) For example $2 = 2*2 = 04 00 and $4 = 4*4 = 10 00

56 02 + 03 (LOCAL) + X (VARIABLE) For example [email protected] = 02 00 and [email protected] = 06 00

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
fastman92

http://www.mediafire.com/?xrq6v1z1l5zwr8b

Read it about SCM opcode parameter types.

 

Global variables use number of byte, for example $2 = 08 00, $3 = 0C 00. 0xC in hex is equal to 12.

Local variables use a variable number, for example [email protected] = 04 00, [email protected] = 07 00, [email protected] = 0E 10

270 = 0x10E

 

Edited by fastman92

Share this post


Link to post
Share on other sites
Wesser

 

What are labels: there are no registered labels in structure of SCM file. They are just negative INT offsets relative to beginning of script.

A jump to offset 800 would be jump to -800 as INT value, usually 4-byte number, but not limited to.

That's not exactly. Jump offsets are relative to the each thread base address and those of the MAIN thread aren't negative at all.

 

Why don't you link some articles of the forum wiki (such as this and this)? They provides a lot more information. dozingoff.gif

 

However, I stopped working on my own HL decompiler because of VB.NET inefficiency and now I'm moving the code to C++. Be patient. smile.gif

Share this post


Link to post
Share on other sites
Bad.boy!

Thanks wesser. I'm making my compiler in c# and I don't make a decompiler because that will take to much time.

 

About the jumps I came up with this:

 

0002	GOTO    02 00 + 01 + Place in file? + FF FF FF004D	JUMP_IF_FALSE  	4D 00 + 01 + Place in file? + FF FF FF 

 

Is the place in file the 200th binary number for example?

 

I can make some progress if I know that, because now I can't go further than this (which is atleast something):

 

Source:SCRIPT_NAME "TEST"Decompiled:{$CLEO .cs}//-------------MAIN---------------thread "TEST" 

 

 

I'm trying to make this:

 

SCRIPT_NAME "TEST":TESTWHILE NOT IS_PLAYER_PLAYING playerWAIT 0ENDWHILEEND_CUSTOM_THREAD

 

Share this post


Link to post
Share on other sites
fastman92

 

Place in file? + FF FF FF

What?

 

Read docx

01 4 Static number: (Long) Integer – 32 bits

 

It's negative integer value that takes 4 bytes. Do you know that numbers may be longer than one byte?

 

Share this post


Link to post
Share on other sites
LINK/2012

 

0002 GOTO    02 00 + 01 + Place in file? + FF FF FF

004D JUMP_IF_FALSE  4D 00 + 01 + Place in file? + FF FF FF

 

Those FF's is part of the place in file...

 

But for example, a CLEO Script has local offsets, so the offset is negative, so for example, the offset 2 should be compiled as -2, Main.scm Missions and Externals too.

-1 in hex is 0xFFFFFFFF

-2 is 0xFFFFFFFE

and so on.

 

So

 

0000: // This prevent a jump 0 adding 2 bytes at the header, because 0 has no negative value, so if you do a jump 0 you're jumping to main.scm:Labeljump @Label

 

 

Compiled is

 

00 00{Here is offset 2}02 00 // Opcode  000201 // Datatype Int32FFFFFE // -2, jump to offset 2 relative to this thread base.

 

 

 

Share this post


Link to post
Share on other sites
Wesser

 

Thanks Wesser. I'm making my compiler in C# and I don't make a decompiler because that will take to much time.

It's useless. I have good plannings for the future compiling process like including functions, implement classes such as all OOP languages have and give support for ASM code pieces. Everything is done theorically, I still need some more time to write the main code.

Share this post


Link to post
Share on other sites
Bad.boy!

I'm having problems with the immediate 32 bit float.

1.25 = 00 00 A0 3F

 

How to calculate it, or how did you do it Wesser?

 

06	4	Float IEEE 754 – 32 bits

 

Share this post


Link to post
Share on other sites
fastman92

There's no reason for you to write another coprocessor

 

In programming language when for example if you are using scanf function and came with "1.25" string as input string with format "%f", then you'll easily get "1.25" converted to 4-byte floating point (float).

 

To display float you can use something like this:

 

 

// C++ code/* scanf example */#include <stdio.h>int main (){ float f = 1.25; printf ("Your float: %.3f", f);  return 0;}

 

Edited by fastman92

Share this post


Link to post
Share on other sites
Bad.boy!

I need to do it the other way around.

How to get from 1.25 to 00 00 A0 3F?

Share this post


Link to post
Share on other sites
fastman92

 

I need to do it the other way around.

How to get from 1.25 to 00 00 A0 3F?

Man, "1.25" will be automatically converted to 00 00 A0 3F using any C++ that lets you perform this task.

 

Look for C++ functions to convert in Google: C++ string to float

Share this post


Link to post
Share on other sites
Bad.boy!

I'm making my compiler in C# not C++. Anyway I just found out that it didn't work. Because the value was inverted, I got (3FA00000).

Share this post


Link to post
Share on other sites
fastman92

00 00 A0 3F is 0x3FA00000 when read as 4-byte DWORD.

It's 1.25 when read as float.

Share this post


Link to post
Share on other sites
Bad.boy!

Does anyone know why the compiler ignores a "0" on purpose?

 

public static string Bit32Float(double Value) // 06       {           float Waarde = (float)Value;           byte[] bytes = System.BitConverter.GetBytes(Waarde);           int i = System.BitConverter.ToInt32(bytes, 0);           string Hex = i.ToString("X8");           Debug.Print(Hex);           string[] Waardes = Regex.Split(Hex, "");           string[] Paar = new string[5];           int Getal = 0;           foreach (string nummer in Waardes)           {               Getal++;               switch (Getal)               {                   case 1:                       Paar[1] = nummer;                       break;                   case 2:                       Paar[1] += nummer;                       break;                   case 3:                       Paar[2] = nummer;                       break;                   case 4:                       Paar[2] += nummer;                       break;                   case 5:                       Paar[3] = nummer;                       break;                   case 6:                       Paar[3] += nummer;                       break;                   case 7:                       Paar[4] = nummer;                       break;                   case 8:                       Paar[4] += nummer;                       break;               }           }           Hex = Paar[4] + Paar[3] + Paar[2] + Paar[1];           Debug.Print(Hex);           return Hex;       }DEBUG:3FA000000000FA3

 

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
fastman92

3F A0 00 00

 

You put value being read as 0x0000A03F = 0xA03F when integer.

00 00 A0 3F isn't equal to 3F A0 00 00.

Share this post


Link to post
Share on other sites
Wesser

Seriously, leave it. You're asking help for basic things. confused.gif

Share this post


Link to post
Share on other sites
Bad.boy!

I am quiet stubborn*, and continue working on this compiler.

 

Does anyone know how high a number must be to use 8bit, 16bit or 32bit ints? What is the highest value 8, 16 and 32bit can handle?

 

*Google translate, don't know if it's the word I mean

Share this post


Link to post
Share on other sites
fastman92

 

I am quiet stubborn*, and continue working on this compiler.

 

Does anyone know how high a number must be to use 8bit, 16bit or 32bit ints? What is the highest value 8, 16 and 32bit can handle?

 

*Google translate, don't know if it's the word I mean

Calculate it yourself

2^8 - 1 = ?

2^16 -1 = ?

2^32 -1 = ?

 

^ is power sign. For example 2 ^ 3 = 2*2*2 = 8

 

Look in Google what is binary system 10101011111010101010110100101

 

Seriously, leave it.

Share this post


Link to post
Share on other sites
Deji

Well, personally I like to encourage all attempts to gain a greater understanding of something through practical work. Bad.boy could just do with learning to do more of his own research. But in fairness, this stuff should be pretty well documented by now, but it isn't.

 

As Wesser said, though, this article has enough information to get you well on your way (though parts are pretty badly written and demonstrated, but I guess most of it was written years ago).

Share this post


Link to post
Share on other sites
Bad.boy!

I continued working on the compiler (with no decompiling functions). And I made some progress.

 

From this:

EDIT: This didn't really work

 

Ohh and I aint that bad in C# (not good either), it's just that I never done anything with hex and binary's.

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
Wesser

You must analyze the source code first. You cannot create any scripts without a theorical face. For example, R* didn't implement a REPEAT-UNTIL statement, which is what you've done now (they probably found either some conflicts with FOR loop composition or its futility). My decompiler (which follows R*'s standards) won't decompile your code correctly then.

Share this post


Link to post
Share on other sites
Bad.boy!

They made a repeat until loop, but R* code jumps to an other label and jumps back (I think):

 

  	WHILE NOT HAS_MODEL_LOADED counter_create_car      WAIT 0      PRINT_NOW LOADCAR 100 1 //"Loading vehicle, press pad2 leftshoulder1 to cancel"      IF IS_BUTTON_PRESSED PAD2 LEFTSHOULDER1   	//++ counter_create_car   	GOTO next_carzzz   ENDIF 	 	ENDWHILE

 

 

So I should make an other label and then jump back?

 

EDIT: New Code

 

public static void OpcodeWhile(string lijn, int index, bool flag)       {           if (flag == false)           {               Main.index--;               index--;               int index5 = 0;               for (int i = index; i > 0; i--)               {                   if (Main.Script[i] != null)                   {                       int Temp = Main.Script[i].Length;                       Temp /= 2;                       index5 += Temp;                   }               }               index5 *= -1;               string Hex3 = "4D00" + Variables.Signed32BitInt(index5);               bool isNot = false;               int index2 = 0;               string Opcode = "";               string[] opcode = lijn.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);               if (!lijn.Contains("NOT"))               {                   foreach (string woord in opcode)                   {                       index2++;                       if (index2 == 2)                       {                           Opcode += woord;                       }                       if (index2 == 3)                       {                           Opcode += " " + woord;                       }                   }               }               else               {                   isNot = true;                   foreach (string woord in opcode)                   {                       index2++;                       if (index2 == 3)                       {                           Opcode += woord;                       }                       if (index2 == 4)                       {                           Opcode += " " + woord;                       }                   }               }               int index4 = 0;               foreach (string ding in Main.While)               {                   if (ding != null)                   {                       if (ding.Length > 1)                       {                           index4++;                       }                   }               }               Main.FindOpcode(Opcode, index, true);                string Hex = "";                              if (isNot == true)               {                   int index3 = 0;                   string[] Tempvar = Regex.Split(Main.While[index4], "");                   foreach (string nummer in Tempvar)                   {                       index3++;                       if (index3 == 4)                       {                           Hex += "8";                       }                       else                       {                           Hex += nummer;                       }                   }               }               else               {                   Hex = Main.While[index4];               }               Main.While[index4] = Hex + Hex3;               Main.CurrentWhile[index4] = "Huidige";           }           else           {               Main.Error = true;           }       }                  public static void OpcodeEndWhile(string lijn, int index, bool flag)       {           if (flag == false)           {               int i = -1;               foreach (string line in Main.CurrentWhile)               {                   if (line != null)                   {                       if (line == "Huidige")                       {                           i++;                       }                   }               }               string Hex = Main.While[i];               Main.CurrentWhile[i] = null;               Main.Script[index] = Hex;               Main.index++;           }           else           {               Main.Error = true;           }       } 

 

 

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
Wesser

Listen, I have good knowledges about the source code, so it'd be useless for you to understand by yourself what another user already knows. Wait some time till my documentation will come up. smile.gif

Share this post


Link to post
Share on other sites
Bad.boy!

If anyone is interested: I've finished the while loop, and added an if loop.

 

THREAD "HIGH" // <-- BugIF IS_PLAYER_PLAYING PLAYER   IF IS_PLAYER_PLAYING PLAYER2<155>       WAIT 100   ELSE       WAIT 200 // <-- Bug   ENDIF   WAIT 300ENDIFEND_CUSTOM_THREAD

 

 

{$CLEO .cs}//-------------MAIN---------------if   Player.Defined($PLAYER_CHAR)else_jump @NONAME_52 if   Player.Defined($SECOND_PLAYER)else_jump @NONAME_43 wait 100 jump @NONAME_47 :NONAME_43wait -56 // Bug:NONAME_47wait 300 :NONAME_520A93: end_custom_thread 

 

 

The if with while doesn't seem to compile good, but I'm sure that it is fixable.

 

This is a generated code, it's not programmed to compile only that combination

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 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.