Zeige Ergebnis 991 bis 1.020 von 10174
C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; ah ok srry i can't help...
-
09-24-2006, 08:20 PM #991QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Canada
- Beiträge
- 70
- Points
- 4.073
- Level
- 40
- Downloads
- 0
- Uploads
- 0
ah ok srry i can't help
-
09-24-2006, 08:21 PM #992Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Twin891
its k. ill figure some other way--------------------------------------------------------------------------------------
-
09-24-2006, 08:24 PM #993Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
As Twin891 already mentioned, the saveImage() functions from graphics.c is a good start.
I use this function to save as a PNG.
Code:void IMG_Screenshot(const char* filename) { u32* data = (u32*)0x04000000; png_structp png_ptr; png_infop info_ptr; FILE* fp; int i, x, y; u8* line; if ((fp = fopen(filename, "wb")) == NULL) return; png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) return; info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); return; } png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, 480, 272, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); line = (u8*) malloc(480 * 3); for (y = 0; y < 272; y++) { for (i = 0, x = 0; x < 480; x++) { u32 color = data[x + y * 512]; u8 r = color & 0xff; u8 g = (color >> 8) & 0xff; u8 b = (color >> 16) & 0xff; line[i++] = r; line[i++] = g; line[i++] = b; } png_write_row(png_ptr, line); } free(line); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, (png_infopp)NULL); fclose(fp); }
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
09-25-2006, 04:35 AM #994Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Insomniac197
well, i tried this:
but when i try to compile it, it gives an error:Code:void Controls() { //read pad// if (pad.Buttons & PSP_CTRL_SELECT) { saveImage("test1.png", getVramDisplayBuffer(), 480, 272, 480, 1); } }
how can i solve that?Code:undefined reference to 'getVramDisplayBuffer()' undefined reference to saveImage(const char*, unsigned int*, int, int, int, int);
--------------------------------------------------------------------------------------
-
09-25-2006, 05:44 AM #995Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
If you are using the graphics.c then you will need to #include graphics.h in your code, as well as add graphics.o and framebuffer.o to the OBJS in your makefile.

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
09-25-2006, 07:48 AM #996Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
where can i find a keyboard in c/c++ exemple
because i can find them only in lua:Argh:
-
09-25-2006, 01:17 PM #997Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Insomniac197
i did that, and it still gives the same errors. help--------------------------------------------------------------------------------------
-
09-25-2006, 05:39 PM #998QJ Gamer Blue
- Registriert seit
- Apr 2006
- Beiträge
- 146
- Points
- 4.464
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I am trying to execute another eboot from within my eboot. I read about sceKernelLoadExec, but that didn't work. I read somewhere that the eboot needed to be kxploited. When I enter 'make', it gives me a single eboot.pbp. I assume this is not kxploited and is meant for 1.0 (which works fine with custom firmware). 'Make Kxploit' causes it not to show up in the list. If I execute it from irshell, it won't load.
Currently, here is my test source code:
It is meant to execute the hello world app in the hello folder. This app isn't kxploited. When I run it, it gets past the printf statement, and then crashse (sends me back to the xmb).Code:#include <pspkernel.h> #include <pspdebug.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <pspdisplay.h> #include <pspctrl.h> #include <psploadexec.h> //I know I have a lot of #include, but I'm leaving them for later PSP_MODULE_INFO("Ebooy", 0x1000, 0, 1); #define printf pspDebugScreenPrintf /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main (void) { pspDebugScreenInit(); SetupCallbacks(); printf("Loading Eboot...\n"); sceKernelLoadExec("ms0:/PSP/GAME/hello/EBOOT.PBP", NULL); printf("Eboot loaded\n"); return 0; }
Please don't tell me to search. I've read every thread in this forum (as well as stuff found on google and ps2dev.org) that has anything to do with it. I think my problem has something to do with the hello world eboot (even though it runs fine by itself).
Thanks in advance.
-
09-25-2006, 11:16 PM #999AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
A kxploited eboot is basically an eboot without the param.sfo. I believe the sceKernelLoadExec file needs to be kxploited, or possibly in elf format I haven't really used it that much, so I'm not 100% sure.
-
09-26-2006, 05:42 AM #1000
ive had the same prob when i tried to make a mini shell and i asked every person and schearched every thread and i didnt find anything but you could try asking at pspdev.org (:
Zitat von Cheater
-
09-26-2006, 09:39 AM #1001QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Short question: are there dynamic arrays in C (not ++)? I mean can I declare an array like "myType myName[]" and later on add items like "myName[0] = 1; myName[1] = 2;" ?
-
09-26-2006, 10:51 AM #1002QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
No, unfortunately not. You have to do them yourself, or use a static array that holds the maximum number of elements you want to put into that array. Creating a dynamic array is not very hard though (using malloc/realloc).
Zitat von Lukeson
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
09-26-2006, 11:04 AM #1003QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thank you. What library do I need for malloc/realloc? Is there a <stdlib.h> in PSPSDK? And is that the correct way of using them:
type name = malloc(ArraySize);
array = realloc(array, NewSize);
?
-
09-26-2006, 12:03 PM #1004QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Yes, there is a stdlib.h, but you just need to include <malloc.h>, nothing more. And yes, that's the correct syntax to use.
Zitat von Lukeson
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
09-26-2006, 12:23 PM #1005QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Hm, I' getting errors:
Error:Code:typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; } MenuItem; typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; MenuItem subMenu[2]; } MainMenuItem; MainMenuItem mainMenu[5]; mainMenu[0].subMenu = realloc(mainMenu[0].subMenu, 5); // Line 139
main.c: In function 'main':
main.c:139: error: incompatible types in assignment
-
09-26-2006, 12:30 PM #1006AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
subMenu has to be a pointer if you want to malloc it (e.g. you can't allocate a struct/array with a static size).
-
09-26-2006, 03:30 PM #1007QJ Gamer Blue
- Registriert seit
- Apr 2006
- Beiträge
- 146
- Points
- 4.464
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I was hoping someone here would know
Zitat von PSP-Maniac
. I guess I'll try pspdev. If you find a way to do this PSP-Maniac, please let me know.
-
09-27-2006, 05:42 AM #1008Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
how do you port this (cout to printf)
i tested this , but it only prints text and dont execute x*ycout<<"schrijf 2 getallen voor te vermenigvuldigen: ";
cin>>x>>y;
cin.ignore();
cout<<"het produkt van de 2 getallen is ";
cout<<x*y<<"\n";
printf("schrijf 2 getallen voor te vermenigvuldigen: ",x,y);
printf("\n");
printf("het produkt van de 2 getallen is ",x*y);
-
09-27-2006, 05:48 AM #1009QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I don't quite get it. I tried various kinds of combinations between pointers and arrays. Eg.
Zitat von homer
But this doesn't only look wierd, it really don't works. Can you give me an example of how to declare an array in the mainMenuStruct later on set its size / how to create an array of MainMenuItems with SubmenuArrays of different sizes in it ?Code:typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; MenuItem subMenu; MenuItem *pSubMenu; } MainMenuItem; MainMenuItem mainMenu[5]; mainMenu[0].pSubMenu = &mainMenu[0].subMenu; mainMenu[0].subMenu = realloc(mainMenu[0].pSubMenu, 5);
-
09-27-2006, 07:09 AM #1010AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Here:
You then use it like this (example code):Code:typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; } MenuItem; typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; MenuItem *subMenu; } MainMenuItem; MainMenuItem mainMenu[5]; //Allocation (should be in a function) mainMenu[0].subMenu =(MenuItem *)malloc(5);
To reallocate it you simply do thisCode:strcpy(mainMenu[0].subMenu[0].label, "Test0"); mainMenu[0].subMenu[0].x = 0; mainMenu[0].subMenu[0].y = 0;
Code:mainMenu[0].subMenu = (MenuItem *)realloc(mainMenu[0].subMenu, 6*sizeof(MenuItem));
-
09-27-2006, 07:20 AM #1011QJ Gamer Blue
- Registriert seit
- Mar 2006
- Ort
- France
- Beiträge
- 239
- Points
- 7.538
- Level
- 57
- Downloads
- 0
- Uploads
- 0
Well I decided to left LUA for C...
So now I'm looking for a function that detects the color of a pixel (screen
ixel(x,y) in LUA) what's it in C??? Tx!
-
09-27-2006, 08:31 AM #1012QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thank you Homer!
Zitat von homer
-
09-27-2006, 08:38 AM #1013Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
if youre using the graphics lib you can use
Zitat von Maxime
Code:getPixelScreen(int x, int y)
-
09-27-2006, 08:43 AM #1014QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I don't wanna go on you guy's nerves, but I'm having a wierd error; Same code as above
The problem is that the picture's all messed up:Code:typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; } MenuItem; typedef struct { Image* iconHigh; Image* iconLow; char label[16]; int x,y; int imgOffsetX; int maxMenuItems; MenuItem *subMenu; } MainMenuItem; MainMenuItem mainMenu[5]; mainMenu[0].subMenu =(MenuItem *)malloc(5); mainMenu[0].subMenu[0].iconHigh = loadImage("./img/mainmenu/s_eq_high.png"); while(1) { if (mainMenu[0].subMenu[0].iconHigh) { blitAlphaImageToScreen(0 ,0 ,32 , 32, mainMenu[0].subMenu[0].iconHigh, 0, 0); } }
-
09-27-2006, 08:58 AM #1015AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You probably put the wrong width and height values. You should do
Code:blitAlphaImageToScreen(0 ,0 mainMenu[0].subMenu[0].iconHigh->imageWidth, mainMenu[0].subMenu[0].iconHigh->imageHeight, mainMenu[0].subMenu[0].iconHigh, 0, 0);
-
09-27-2006, 09:05 AM #1016QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
No, the width and height are definitely correct. Including the image directly (using a var Image *tmp for loadImage()) it works just fine
-
09-27-2006, 09:19 AM #1017
- Registriert seit
- Jul 2006
- Beiträge
- 6
- Points
- 3.885
- Level
- 39
- Downloads
- 0
- Uploads
- 0
I am trying to hook some firmware functions (in a devhook prx) so that I can draw my menu on the screen whenever the sceDisplayWaitVblankStart function is called so that everything is ALWAYS drawn on top of the current frame and I won't get flickering. I am also trying to hook the audio output functions (sample code below) to add a boost function like in PMP Mod AVC, except this would boost all output. I have tested the code for finding the offsets for the NIDS that I need to patch, and it does find the correct ones, but there is something wrong with either my patched functions or the actual patching of the functions. As soon as a sound is played the PSP freezes, indicating that the right NIDS are patched but that something causes it to freeze. In my original code I would patch the sound functions whenever I chose to in my menu, and in that way I found out that it patches the functions but whenever I would press a button on the D-pad to trigger the sound it would freeze. Can someone help me figure out what is wrong with my code? Below is a stripped down version of my code that simply patches the functions when it loads.
Code:#include <pspkernel.h> #include <pspsdk.h> #include <pspctrl.h> #include <string.h> PSP_MODULE_INFO("Api Hook", 0x1000, 1, 1); PSP_MAIN_THREAD_ATTR(0); #define J_OPCODE 0x08000000 #define NOP 0x00000000 typedef int (*SCE_AUDIO_OUTPUT)(int channel, int vol, void *buf); typedef int (*SCE_AUDIO_OUTPUT_PANNED)(int channel, int leftvol, int rightvol, void *buf); SCE_AUDIO_OUTPUT sceAudioOutput_Real, sceAudioOutputBlocking_Real; SCE_AUDIO_OUTPUT_PANNED sceAudioOutputPanned_Real, sceAudioOutputPannedBlocking_Real; void* libsFindExportAddrByNid(SceModule *pMod, u32 nid) { struct SceLibraryEntryTable *entry; u32 *addr = NULL; void *entTab; int entLen; if(pMod != NULL) { int i = 0; entTab = pMod->ent_top; entLen = pMod->ent_size; while(i < entLen) { int count; int total; unsigned int *vars; entry = (struct SceLibraryEntryTable *) (entTab + i); total = entry->stubcount + entry->vstubcount; vars = entry->entrytable; if(entry->stubcount > 0) { for(count = 0; count < entry->stubcount; count++) { if(vars[count] == nid) { return vars[count+total]; } } } i += (entry->len * 4); } } else { return 0; } return 0; } int sceAudioOutput_patched(int channel, int vol, void *buf) { return sceAudioOutput_Real(channel, 0, buf);; } int sceAudioOutputBlocking_patched(int channel, int vol, void *buf) { return sceAudioOutputBlocking_Real(channel, 0, buf); } int sceAudioOutputPanned_patched(int channel, int leftvol, int rightvol, void *buf) { return sceAudioOutputPanned_Real(channel, 0, 0, buf); } int sceAudioOutputPannedBlocking_patched(int channel, int leftvol, int rightvol, void *buf) { return sceAudioOutputPannedBlocking_Real(channel, 0, 0, buf); } //Keep our module running int main_thread(SceSize args, void *argp) { while(!sceKernelFindModuleByName("sceKernelLibrary")) sceKernelDelayThread(100000); sceKernelDelayThread(1000000); while(1) { sceKernelDelayThread(20000); } return 0; } int module_start(SceSize args, void *argp) __attribute__((alias("_start"))); int _start(SceSize args, void *argp) { int thread_count = 0, counter = 0; SceModule *mod_tmp, *audiomod; SceUID thread_temp[100]; //Get a list of modules from running threads. //For some reason I couldn't get a list of modules directly, maybe a problem with devhook? sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_temp, 100, &thread_count); for(counter=0; counter < thread_count; counter++) { SceKernelThreadInfo info; info.size = sizeof(SceKernelThreadInfo); sceKernelReferThreadStatus(thread_temp[counter], &info); mod_tmp = sceKernelFindModuleByAddress((u32)info.entry); //Find audio module based off of name, doesn't seem to work when I use the exact name =/ if(mod_tmp->modname[3] == 'A' && mod_tmp->modname[5] == 'd') { audiomod = mod_tmp; } } u32 offset; offset = (u32)libsFindExportAddrByNid(audiomod, 0x8C1009B2); sceAudioOutput_Real = (SCE_AUDIO_OUTPUT)_lw(offset); _sw((u32)sceAudioOutput_patched, offset); offset = (u32)libsFindExportAddrByNid(audiomod, 0x136CAF51); sceAudioOutputBlocking_Real = (SCE_AUDIO_OUTPUT)_lw(offset); _sw((u32)sceAudioOutputBlocking_patched, offset); offset = (u32)libsFindExportAddrByNid(audiomod, 0xE2D56B2D); sceAudioOutputPanned_Real = (SCE_AUDIO_OUTPUT_PANNED)_lw(offset); _sw((u32)sceAudioOutputPanned_patched, offset); offset = (u32)libsFindExportAddrByNid(audiomod, 0x13F592BC); sceAudioOutputPannedBlocking_Real = (SCE_AUDIO_OUTPUT_PANNED)_lw(offset); _sw((u32)sceAudioOutputPannedBlocking_patched, offset); sceKernelDcacheWritebackAll(); sceKernelCreateThread("hook_main_thread", main_thread, 100, 0x1000, 0, NULL); return 0; }
-
09-27-2006, 01:10 PM #1018Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Maxime
if you want to check how to use lua functions in C, check the LUA player soure code. it has everything--------------------------------------------------------------------------------------
-
09-28-2006, 02:43 AM #1019QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
That problem is, thanks to СУ&am solved now :)
Zitat von Lukeson
So I got time to come back to the transparency Issue.
It neither has a return value, nor does it affect the Image-pointer, so how do you use it? (sorry, I still am a noob)
Zitat von homer
-
09-28-2006, 04:22 AM #1020Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Zitat von Lukeson
Looks like it affects it to me mate.Code:*databuf = (*databuf & 0x00ffffff) | ((A(*databuf)-(A(*databuf)-alpha))<<24);
Follow the function through logically - it's pretty easy to understand.
What are you trying to achieve exactly? I feel there will be an easier and faster way to execute it. The above function will be quite slow.
-= Double Post =-
I can't believe I missed this the first time around. If you look at my function you will see that you only have to supply the filename and none of the other arguments.
Zitat von Grimfate126
Just do:
Code:IMG_Screenshot("myImage.png");Geändert von Insomniac197 (09-28-2006 um 04:22 AM Uhr) Grund: Automerged Doublepost

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum