Hacking __os_snprintf code

dimanmonster

New Member
Newbie
Joined
May 19, 2016
Messages
3
Reaction score
0
Trophies
0
Age
29
XP
71
Country
Serbia, Republic of
Hello! Please give an example of the code that displays the value of the variable on the screen __os_snprintf
 
__os_snprintf doesn't display a variable on the screen, it simply allows you to create a string with the variable in it which you can then print using another method.

Code:
char buffer[255];
__os_snprintf(buffer, 255, "format string", variable1, variable2, etc);
somehow_print_string(buffer);

"format string" is the same kind of format string that most C functions use. An example of this is could be "number is %d, letter is %c, hex is %X, string is %s". If I put in the data 1, g, 0x4F and "apple", this would create the string "number is 1, letter is g, hex is 4F, string is apple", ready for printing, but I cannot stress enough that it does not actually print. You'll need to do this another way (OSScreen for instance).
You can find a full list of things you can put in a format string here.
 
It's pretty much exactly the same thing as snprintf, and in fact, you can use snprintf instead, as long as you include <stdio.h> in your project.
 
This is an old topic but I'll post a reply anyway. Here is a full example code:
Code:
#define SERVER_VERSION "01/14/2017"
#define ERROR_BUFFER_SIZE 100
#define COMMAND_BYTE 0xFF
void reportIllegalCommandByte() {
    char errorBuffer[ERROR_BUFFER_SIZE];
    __os_snprintf(errorBuffer, ERROR_BUFFER_SIZE, "Illegal command byte received: %i\nServer Version: %s", COMMAND_BYTE, SERVER_VERSION);
    OSFatal(errorBuffer);
}
This can be used when the TCP Gecko Installer receives an unknown command byte for example. It will format the string by inserting the command byte and the server version. It works the same as the standard snprintf.

Result:
Code:
Illegal command byte received: 255
Server Version: 01/14/2017
 

Site & Scene News

Popular threads in this forum