cleolibrary / CLEO4

CLEO 4 for GTA San Andreas
https://cleo.li
MIT License
245 stars 33 forks source link

ReadMemory and WriteMemory should handle exceptions #30

Closed x87 closed 2 years ago

x87 commented 4 years ago

Reading and writing memory should happen in isolated and controlled manner and never cause the game to crash. Instead the error should be logged and the script shut down, while letting other scripts continue working.

thelink2012 commented 4 years ago

My observations in this regard:

  1. That could possibility leave the game in an invalid or unspecified state. If we halt a script mid-execution it could leave a task incomplete, dangling handles, corrupted memory, and other things that could make the game state unreliable, but since the game didn't crash, one wouldn't notice until things start to break (possibly some of this invalid state could infect save games).
  2. I have no data to support this claim, but SEH could make these commands slower, and these are commands that are expected to be fast as they compose a high percentage of the lines in complex scripts.
  3. Scripts can incorrectly manipulate memory in other manners. Be that with DMA, or by passing weird parameters to non-memory commands. That is, the unsandboxed problem goes way over these two commands, and is inherent to the original scripting environment.

Generalizing this a bit, since almost every command can produce problematic memory manipulation, the SEH could encapsulate the script execution tick itself, instead of only these two commands. But the first problem would become even stronger in this method.

In my opinion this is a lost cause. Manipulating memory either goes well, or it doesn't. If it doesn't, you might want to provide a recovery mechanism, but that recovery mechanism varies from case to case. As such, instead, there could be a similar command that returns a boolean indicating failure [PS: CLEO would need to handle the memset case, or even not support it]. But again, would that be useful? Would it be cost-effective for scripters to stop and think about failure recovery?

I think what I mean is, corrupting user data is worse than crashing, and this feature would go in that direction.

GoKuDead commented 4 years ago

Reading and writing memory should happen in isolated and controlled manner and never cause the game to crash. Instead the error should be logged and the script shut down, while letting other scripts continue working.

Good afternoon seeman I hope you are well, seeman I know that this part is not about questions related to cleo android and sanny builder, but due to the bad collaboration that exists in android and questions from sanny I should ask you please .....

HELP ME.

I have several questions but I will only ask 3 of them.

  1. seeman, how does the sanny builder compiler work, what do the opcodes do?

  2. seeman, one day I was on the cleo android gtasaforums forum and alenxander blade had mounted a cleo android guide file in a ZIP, it was called dev-cleo, and unfortunately I couldn't find it, it was to ask if you have it from chance?

  3. Regarding the new opcodes for android cleo, and for gta pc I have a question, how are opcodes created, what is needed to create them? I am currently newbie to java and c ++, I understand only a little bit of asmx86, and ARMV7.

Seeman teacher please just answer these questions, since in gtasaforums for asking this they rejected me, please just ask for a good information base, and what better from the creator of the best SANNY BUILDER tool, thank you and I hope your country is well of the covid19 and your family :)

x87 commented 4 years ago

@GoKuDead please don't post your questions in random tickets. Use public boards like gtaforums or scripting-related discord channels.

If you want to know how scripts work you should start from learning the information this is already available out there. I would suggest to read these articles: https://gtamods.com/wiki/SCM_language https://gtamods.com/wiki/SCM_Instruction

for more in-depth overview of GTA script internals: https://github.com/thelink2012/gta3sc - gta3 script compiler https://github.com/GTAmodding/re3/blob/master/src/control/Script.cpp - gta3 re-implementation

Then if you need details on how new opcodes are created, take a look into CLEO plugins implementation https://github.com/JuniorDjjr/CLEOPlus https://github.com/cleolibrary/opcodes-restoration-project

I can't provide you information on Android script, you should reach out to Alexander Blade who was working on that.