· 6 years ago · Apr 21, 2019, 06:56 PM
1Help getting started with making plugins :d
2https://playstationhax.xyz/forums/topic/1382-help-getting-started-with-making-plugins-d/
3
4
5Help getting started with making plugins :d
6Asked by Lucif3r
7noob
8
9ambitious
10
11rubbish
12
13gtfo
14Question
15Lucif3r
16Sarcasmaclysmic
17Lucif3r
18Super Admin
19
20Founding Member
21 2,459
222,945 posts
23Location: Far away, in a dark cave ,,^..^,,
24Posted February 17, 2015
25So, I fell and hit my head and thought it would be a BRILLIANT idea to learn a bit about plugins, prx ones specifically.
26
27After a few days frustration and reading I finally got my environment set up and got it to build shit. Yay.
28
29
30
31However, I am at a loss now... While the sprx builds just fine, it freezes the console either during load, or shortly after returning to XMB(I load it with PRXLoader). Even sony's own rubbish examples freezes.
32
33Target Manager shits out a constant spam of "System Warning: Busy loop detected", and this is were I get confused... My sprx doesnt contain a loop anywhere. :/
34
35I am obviously missing something here, probably simple as hell...
36
37
38
39So, heres the code that freezes during load:
40
41#include <sys/prx.h>
42
43SYS_MODULE_INFO( shityPRX, 0, 1, 0 );
44SYS_MODULE_START( _start );
45SYS_MODULE_STOP( _stop );
46
47int _start(void);
48int _stop(void);
49
50int _start(void)
51{
52 return SYS_PRX_RESIDENT;
53}
54
55int _stop(void)
56{
57 return SYS_PRX_STOP_OK;
58}
59And by blatantly stealing Mysis' ppu_thread_create function from his recording plugin, and adding the following;
60
61void thread_entry(uint64_t arg)
62{
63 sys_timer_sleep(10);
64}
65the plugin loads fine, but freezes shortly after returning to xmb(I assume just about when sleep(x) runs out).
66
67This leads me to believe the plugin freezes the console when it has nothing to do? However, I am no where near knowledgeable enough to actually understand why it does that or how to fix it.
68
69Mysis got a while(true) loop inside his thread_entry, which confuses me even more.. Ive been taught that a while(true) loop is the best way to crash or freeze your program lol. Im sure its theres a reason for it to be there, but I fail to see it :(
70
71
72
73Ive never claimed to be a good coder, quite the opposite in fact. Ive only coded in C# before, so not only am I switching from winblows programs to ps3 plugins, I am also switching from C# to C++ lol...
74
75Unfortunately C#/windows does a lot automatically, such as handling the 'idling' of a program, which doesnt really help me fixing this issue...
76
77
78
79Could it be as easy as just adding an empty while(true) loop within the thread_entry with a small delay(sys_timer_sleep(1) or something) to keep the plugin from freezing the PS3?
80
81
82
83
84
85If someone could spare 10sec of their life to laugh at me and point out the obvious I'd appreciate it :) Kinda embarrassing to get stuck this early... :(
86
87Upvote 2
88TheDarkprogramer and 3141card reacted to this
89
90SORT BY VOTES
91SORT BY DATE
921 2 3 NEXT Page 1 of 3
930
943141card
95Member
963141card
97Founding Member
98
99V.I.P
100 172
101112 posts
102Location: Germany
103Posted February 17, 2015 (edited)
104#include <sys/prx.h>
105#include <sys/ppu_thread.h>
106#include <sys/syscall.h> // for syscall usage
107
108
109#include <stdio.h>
110#include <stdlib.h>
111#include <string.h>
112
113
114
115SYS_MODULE_INFO(TESTPLUGIN, 0, 1, 0); // plugin info
116SYS_MODULE_START(testplugin_start); // plugin start function
117SYS_MODULE_STOP(testplugin_stop); // plugin stop function
118
119// thread names, optional and here over macros, names are usefull for debug
120#define THREAD_NAME "testplugin_thread"
121#define STOP_THREAD_NAME "testplugin_stop_thread"
122
123// global variables
124static sys_ppu_thread_t thread_id = -1;
125
126// functions prototypes
127int testplugin_start(uint64_t arg);
128int testplugin_stop(void);
129
130
131// exit over syscall or crash
132static inline void _sys_ppu_thread_exit(uint64_t val)
133{
134 system_call_1(41, val);
135}
136
137static inline sys_prx_id_t prx_get_module_id_by_address(void *addr)
138{
139 system_call_1(461, (uint64_t)(uint32_t)addr);
140 return (int)p1;
141}
142
143
144// plugin main ppu thread, like main in normal c prog
145static void testplugin_thread(uint64_t arg)
146{
147
148 // do work...
149
150 sys_ppu_thread_exit(0); // here ends the plugin. like return(0); on main end in c
151}
152
153// plugin start function, start our main ppu thread...
154int testplugin_start(uint64_t arg)
155{
156 sys_ppu_thread_create(&thread_id, testplugin_thread, 0, 3000, 0x2000, SYS_PPU_THREAD_CREATE_JOINABLE, THREAD_NAME);
157
158 // Exit thread using directly the syscall and not the user mode library or we will crash
159 _sys_ppu_thread_exit(0);
160 return SYS_PRX_RESIDENT;
161}
162
163// plugin exit function, proper stop our plugin
164static void testplugin_stop_thread(uint64_t arg)
165{
166 done = 1;
167
168 if (thread_id != (sys_ppu_thread_t)-1)
169 {
170 uint64_t exit_code;
171 sys_ppu_thread_join(thread_id, &exit_code);
172 }
173
174 sys_ppu_thread_exit(0);
175}
176
177static void finalize_module(void)
178{
179 uint64_t meminfo[5];
180
181 sys_prx_id_t prx = prx_get_module_id_by_address(finalize_module);
182
183 meminfo[0] = 0x28;
184 meminfo[1] = 2;
185 meminfo[3] = 0;
186
187 system_call_3(482, prx, 0, (uint64_t)(uint32_t)meminfo);
188}
189
190int testplugin_stop(void)
191{
192 sys_ppu_thread_t t;
193 uint64_t exit_code;
194
195 sys_ppu_thread_create(&t, testplugin_stop_thread, 0, 0, 0x2000, SYS_PPU_THREAD_CREATE_JOINABLE, STOP_THREAD_NAME);
196 sys_ppu_thread_join(t, &exit_code);
197
198 finalize_module();
199 _sys_ppu_thread_exit(0);
200 return SYS_PRX_STOP_OK;
201}
202Based on the cobra test plugin.
203
204
205
206EDIT: this is for C, (I like smal plugins).
207
208
209
210Use User's test plugin(into PRXLoader download) for VS and C++.
211
212#include <cellstatus.h>
213#include <sys/prx.h>
214#include <stdio.h>
215#include <stdlib.h>
216#include <string.h>
217
218SYS_MODULE_INFO( test_prx, 0, 1, 1);
219SYS_MODULE_START( _test_prx_prx_entry );
220
221SYS_LIB_DECLARE( cellPrx_test_prx, SYS_LIB_AUTO_EXPORT );
222SYS_LIB_EXPORT( _test_prx_export_function, cellPrx_test_prx );
223
224void ppu_thread_exit()
225{
226 system_call_1(41, 0); //ppu_thread_exit
227}
228
229
230// An exported function is needed to generate the project's PRX stub export library
231extern "C" int _test_prx_export_function(void)
232{
233 return CELL_OK;
234}
235
236extern "C" int _test_prx_prx_entry(void)
237{
238 char test[] = "Hello VSH\n";
239 uint32_t len;
240 system_call_4(403, 0, (uint64_t) test, strlen(test), (uint64_t) &len); //tty write
241 ppu_thread_exit();
242 return SYS_PRX_RESIDENT;
243}
244Edited February 18, 2015 by 3141card
245Upvote 2
246TheDarkprogramer and mysis reacted to this
2470
248TheDarkprogramer
249PlayStationHaX Guru
250TheDarkprogramer
251Developer
252
253Founding Member
254V.I.P
255 848
2561,215 posts
257Location: Somewhere In South Africa
258Posted February 18, 2015
259Nice read means I can learn alot too as im also stuggeling switching to object c /c++
260
261As u said windows c# handels alot and I mean alot of the heavy work so working with this would help me a lot ... alao did you setup with linex or did you use visual studios with sony sdk ? This saved me alot of time a while back when I was playing around
262
2630
2643141card
265Member
2663141card
267Founding Member
268
269V.I.P
270 172
271112 posts
272Location: Germany
273Posted February 18, 2015 (edited)
274I use mostly cygwin under win7, here I have my old psl1ght. The "other SDK" cell dir is copyed to
275
276cygwin/usr/local.
277
278
279psl1ght and "other SDK" together without trouble.
280
281
282
283I code only in C and compile in cygwin console, my editor for writing source code is Geany.
284
285
286
287I have VS2010 too(some samples need VS, not many), but don't like it.
288
289Edited February 18, 2015 by 3141card
2900
291Lucif3r
292Sarcasmaclysmic
293Lucif3r
294Super Admin
295
296Founding Member
297 2,459
2982,945 posts
299Location: Far away, in a dark cave ,,^..^,,
300Posted February 18, 2015
301 On 2/17/2015 at 11:37 PM, 3141card said:
302Based on the cobra test plugin.
303
304
305
306EDIT: this is for C, (I like smal plugins).
307
308
309
310Use User's test plugin(into PRXLoader download) for VS and C++.
311
312
313
314
315
316
317
318Are those 2 examples supposed to compile properly on their own? Because...
319
320
321
322First example:
323
3241>------ Rebuild All started: Project: mooo, Configuration: Debug PS3 ------
3251> cobra.cpp
3261>cobra.cpp(21,36): warning 68: integer conversion resulted in a change of sign
3271>
3281>cobra.cpp(79,49): warning 1628: argument of type "void (*)()" is incompatible with parameter (1 of prx_get_module_id_by_address) of type "void *"
3291>
3301>cobra.cpp(22,11): warning 552: variable "done" was set but never used <--- what? It is used!
3311>
3321> ppu-lv2-prx-libgen.exe: "module_start(=testplugin_start)" is undefine symbol. can't export.
3331> ps3ppuld 370.1.4467.0 (rel,TR,1.3_995_370,src @112234 #451087 ) "F:\SCE\370\host-win32\sn\bin\ps3ppuld.exe"
3341>Command line : error : L0303: error generating PRX (prx-libgen failed)
3351>Command line : error : L0064: Linking aborted
336========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
337second:
338
3391>------ Rebuild All started: Project: mooo, Configuration: Debug PS3 ------
3401> cobra.cpp
3411> undefined reference to `memcpy'
3421> undefined reference to `strlen'
3431> ps3ppuld 370.1.4467.0 (rel,TR,1.3_995_370,src @112234 #451087 ) "F:\SCE\370\host-win32\sn\bin\ps3ppuld.exe"
3441>Command line : error : L0303: error generating PRX (prx-fixup failed)
3451>Command line : error : L0064: Linking aborted
346========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
347:(
348
349
350
351Im using VSC2010 with the sony 3.70(because the 4.0 refuses to work) SDK and VS plugin.
352
3530
3543141card
355Member
3563141card
357Founding Member
358
359V.I.P
360 172
361112 posts
362Location: Germany
363Posted February 18, 2015
3641. is not for VS, you need a makefile...
365
366
367
3682. you need the full project, look for the test_prx folder in PRXLoader download.
369
370open the test_prx.sln with VS. Here are e.g. libc.c missing for `memcpy' and `strlen'.
371
372
373
374
375
376Upvote 1
377Lucif3r reacted to this
3780
379Frankie
380Member
381Frankie
382Regular Member
383
384 2
38514 posts
386Posted February 18, 2015
387 On 2/17/2015 at 11:37 PM, 3141card said:
388#include <sys/prx.h>
389#include <sys/ppu_thread.h>
390#include <sys/syscall.h> // for syscall usage
391
392
393#include <stdio.h>
394#include <stdlib.h>
395#include <string.h>
396
397
398
399SYS_MODULE_INFO(TESTPLUGIN, 0, 1, 0); // plugin info
400SYS_MODULE_START(testplugin_start); // plugin start function
401SYS_MODULE_STOP(testplugin_stop); // plugin stop function
402
403// thread names, optional and here over macros, names are usefull for debug
404#define THREAD_NAME "testplugin_thread"
405#define STOP_THREAD_NAME "testplugin_stop_thread"
406
407// global variables
408static sys_ppu_thread_t thread_id = -1;
409
410// functions prototypes
411int testplugin_start(uint64_t arg);
412int testplugin_stop(void);
413
414
415// exit over syscall or crash
416static inline void _sys_ppu_thread_exit(uint64_t val)
417{
418 system_call_1(41, val);
419}
420
421static inline sys_prx_id_t prx_get_module_id_by_address(void *addr)
422{
423 system_call_1(461, (uint64_t)(uint32_t)addr);
424 return (int)p1;
425}
426
427
428// plugin main ppu thread, like main in normal c prog
429static void testplugin_thread(uint64_t arg)
430{
431
432 // do work...
433
434 sys_ppu_thread_exit(0); // here ends the plugin. like return(0); on main end in c
435}
436
437// plugin start function, start our main ppu thread...
438int testplugin_start(uint64_t arg)
439{
440 sys_ppu_thread_create(&thread_id, testplugin_thread, 0, 3000, 0x2000, SYS_PPU_THREAD_CREATE_JOINABLE, THREAD_NAME);
441
442 // Exit thread using directly the syscall and not the user mode library or we will crash
443 _sys_ppu_thread_exit(0);
444 return SYS_PRX_RESIDENT;
445}
446
447// plugin exit function, proper stop our plugin
448static void testplugin_stop_thread(uint64_t arg)
449{
450 done = 1;
451
452 if (thread_id != (sys_ppu_thread_t)-1)
453 {
454 uint64_t exit_code;
455 sys_ppu_thread_join(thread_id, &exit_code);
456 }
457
458 sys_ppu_thread_exit(0);
459}
460
461static void finalize_module(void)
462{
463 uint64_t meminfo[5];
464
465 sys_prx_id_t prx = prx_get_module_id_by_address(finalize_module);
466
467 meminfo[0] = 0x28;
468 meminfo[1] = 2;
469 meminfo[3] = 0;
470
471 system_call_3(482, prx, 0, (uint64_t)(uint32_t)meminfo);
472}
473
474int testplugin_stop(void)
475{
476 sys_ppu_thread_t t;
477 uint64_t exit_code;
478
479 sys_ppu_thread_create(&t, testplugin_stop_thread, 0, 0, 0x2000, SYS_PPU_THREAD_CREATE_JOINABLE, STOP_THREAD_NAME);
480 sys_ppu_thread_join(t, &exit_code);
481
482 finalize_module();
483 _sys_ppu_thread_exit(0);
484 return SYS_PRX_STOP_OK;
485}
486Based on the cobra test plugin.
487
488
489
490EDIT: this is for C, (I like smal plugins).
491
492
493
494Use User's test plugin(into PRXLoader download) for VS and C++.
495
496#include <cellstatus.h>
497#include <sys/prx.h>
498#include <stdio.h>
499#include <stdlib.h>
500#include <string.h>
501
502SYS_MODULE_INFO( test_prx, 0, 1, 1);
503SYS_MODULE_START( _test_prx_prx_entry );
504
505SYS_LIB_DECLARE( cellPrx_test_prx, SYS_LIB_AUTO_EXPORT );
506SYS_LIB_EXPORT( _test_prx_export_function, cellPrx_test_prx );
507
508void ppu_thread_exit()
509{
510 system_call_1(41, 0); //ppu_thread_exit
511}
512
513
514// An exported function is needed to generate the project's PRX stub export library
515extern "C" int _test_prx_export_function(void)
516{
517 return CELL_OK;
518}
519
520extern "C" int _test_prx_prx_entry(void)
521{
522 char test[] = "Hello VSH\n";
523 uint32_t len;
524 system_call_4(403, 0, (uint64_t) test, strlen(test), (uint64_t) &len); //tty write
525 ppu_thread_exit();
526 return SYS_PRX_RESIDENT;
527}
528Do you know the syscall or command for disabling the process in TM so no one can view memory to edit it?
529
5300
5313141card
532Member
5333141card
534Founding Member
535
536V.I.P
537 172
538112 posts
539Location: Germany
540Posted February 18, 2015
541No, and I work not with DEX, I use only rebug 4.46 CEX(to lazy to update on last rebug), therefor no TM, sry.
542
5430
544Lucif3r
545Sarcasmaclysmic
546Lucif3r
547Super Admin
548
549Founding Member
550 2,459
5512,945 posts
552Location: Far away, in a dark cave ,,^..^,,
553Posted February 18, 2015
554 On 2/18/2015 at 12:55 AM, 3141card said:
5551. is not for VS, you need a makefile...
556
557
558
5592. you need the full project, look for the test_prx folder in PRXLoader download.
560
561open the test_prx.sln with VS. Here are e.g. libc.c missing for `memcpy' and `strlen'.
562
563
564
565ahh I see. Yea adding that libc got rid of those 2 errors and it compiled fine, and runs fine on the ps3 as well... However, that doesnt bring me any closer to understanding why the PS3 freezes/"busy loops" with the code I included in my first post...
566
567
568
569Man, I have a lot to learn :P
570
5710
5723141card
573Member
5743141card
575Founding Member
576
577V.I.P
578 172
579112 posts
580Location: Germany
581Posted February 18, 2015 (edited)
582#include <cellstatus.h>
583#include <sys/prx.h>
584#include <stdio.h>
585#include <stdlib.h>
586#include <string.h>
587
588SYS_MODULE_INFO( test_prx, 0, 1, 1);
589SYS_MODULE_START( _test_prx_prx_entry );
590
591SYS_LIB_DECLARE( cellPrx_test_prx, SYS_LIB_AUTO_EXPORT );
592SYS_LIB_EXPORT( _test_prx_export_function, cellPrx_test_prx );
593
594void ppu_thread_exit()
595{
596 system_call_1(41, 0); //ppu_thread_exit
597}
598
599
600// An exported function is needed to generate the project's PRX stub export library
601extern "C" int _test_prx_export_function(void)
602{
603 return CELL_OK;
604}
605
606extern "C" int _test_prx_prx_entry(void)
607{
608 // do work... e.g. your sleep
609
610 ppu_thread_exit();
611 return SYS_PRX_RESIDENT;
612}
613This is, at bottom, the prototype you have to use for start your own projects.
614
615
616
617EDIT:
618
619
620
621Look also on mysis plugins, you can learn a lot from this :)
622
623Edited February 18, 2015 by 3141card
624Upvote 1
625Lucif3r reacted to this
6260
627Lucif3r
628Sarcasmaclysmic
629Lucif3r
630Super Admin
631
632Founding Member
633 2,459
6342,945 posts
635Location: Far away, in a dark cave ,,^..^,,
636Posted February 18, 2015
637I... see... So a lack of a simple ppu_thread_exit() was the cause of all this frustration... I knew it was simple -.-...
638
639Plugin compiles and loads fine now, and I even added a function that worked!
640
641
642
643Although I have (already lol) run into a new, weird, issue.
644
645
646
647This is a sample to demonstrate the errors:
648
649extern "C" int dbprint(char * text) //<- line 123
650{
651 uint32_t len;
652 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
653 return true; //<- line 128
654}
655-------------------------------------------------------
6561>prx.c(123,7): error 40: expected an identifier
6571>
6581>prx.c(123,7): error 261-D: explicit type is missing ("int" assumed)
6591>
6601>prx.c(128,8): error 20: identifier "true" is undefined
6611>
6621>prx.c(207,1): warning 224: function "dbprint" declared implicitly <--- A call to the above function.
663Ok so, as you can see it doesnt accept "extern "C" ... ", and somehow it even complains that "true" is undefined.
664
665It doesnt matter where I put "extern "C" " or "true", so its not function-specific, and they are independent of eachother. It also whines about "bool" and "false", and god knows what else.
666
667Ive compared my code and headers with both the test_prx and mysis' rec_plugin, and neither of those has a header that I do not. Ive also compared the output/compiler, and they are the same settings... And yes, both mysis' and test_prx finds "true" and "extern "C" " etc just fine...
668
669
670
671My dbprint function works just fine btw, if I remove the extern "C" and "true"(which I added for demonstration).
672
6730
6743141card
675Member
6763141card
677Founding Member
678
679V.I.P
680 172
681112 posts
682Location: Germany
683Posted February 18, 2015
684extern "C" say the compiler that the code must be compiled with C compiler, in C there is no boolean per default,
685
686to use bool in C I must include stdbool.h or define it self. -> http://stackoverflow.com/questions/1921539/using-boolean-values-in-c
687
688
689
690The function dbprint() is of type int, therefor she must return a int like return 0;. If you not make error checks, you need no return,
691
692than you can even use void dbprint().
693
694
695
696btw, you are on the right way :) play with the code, source of other plugins and you learn it fast.
697
698Upvote 1
699Lucif3r reacted to this
7000
701Lucif3r
702Sarcasmaclysmic
703Lucif3r
704Super Admin
705
706Founding Member
707 2,459
7082,945 posts
709Location: Far away, in a dark cave ,,^..^,,
710Posted February 18, 2015
711Mmm, not sure you got what I meant, the errors are independant of each other.
712
713
714
715I'll give you 2 more examples:
716
717int dbprint(char * text)
718{
719 uint32_t len;
720 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
721 while(true)
722 {
723 //dostuff
724 }
725}
726------------------------------
7271> libc.c
7281> prx.c
7291>prx.c(128,7): error 20: identifier "true" is undefined
730========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
731extern "C" int dbprint(char * text)
732{
733 uint32_t len;
734 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
735
736}
737------------------------------------------
7381> libc.c
7391> prx.c
7401>prx.c(123,7): error 40: expected an identifier
7411>
7421>prx.c(123,7): error 261-D: explicit type is missing ("int" assumed)
743========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
744int dbprint(char * text)
745{
746 uint32_t len;
747 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
748
749}
750-------------------------------------------
751========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
752And this is regardless of function, if both true/bool/etc and external "C" are present or not.
753
754
755
756In fact, I'll throw in another example too. Just a normal definition, outside of any function:
757
758bool exit_thread=false;
759sys_prx_id_t prx_id;
760sys_prx_module_info_t *pInfo;
761--------------------------------
7621> libc.c
7631> prx.c
7641>prx.c(95): error 20: identifier "bool" is undefined
7651>
7661>prx.c(95,17): error 20: identifier "false" is undefined
767========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
768edit: Well, heres an example from test_prx that I just added a while(true) loop in:
769
770extern "C" int _test_prx_prx_entry(void)
771{
772 while(true)
773 {
774 //wasd
775 }
776 char test[] = "Hello VSH\n";
777 uint32_t len;
778 system_call_4(403, 0, (uint64_t) test, strlen(test), (uint64_t) &len); //tty write
779 ppu_thread_exit();
780 return SYS_PRX_RESIDENT;
781}
782-----------------------------
783========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
784And yeah, as I said, I have the same #include's in my code as test_prx have(incl. libc.c/libc.h)...
785
786
787
788And heres the exact same thing in MY entry:
789
790extern "C" int _prx_start(void)
791{
792 while(true)
793 {
794 //fail
795 }
796 ppu_thread_exit();
797 return SYS_PRX_RESIDENT;
798}
799
800-------------------
8011> libc.c
8021> prx.c
8031>prx.c(130,7): error 40: expected an identifier
8041>
8051>prx.c(130,7): error 261-D: explicit type is missing ("int" assumed)
8061>
8071>prx.c(132,7): error 20: identifier "true" is undefined
8081>
809========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
8100
8113141card
812Member
8133141card
814Founding Member
815
816V.I.P
817 172
818112 posts
819Location: Germany
820Posted February 18, 2015
821LOL, now I see, you have renamed prx.cpp to prx.c, a .c file is C code, the extern C is useless,
822
823and bool is not available per default into C.
824
825
826
827I think you would code in C++ like mysis ? Than you must use extern "C" for using C stuff.
828
829to tell the compiler what into your C++ code is C code.
830
831int dbprint(char * text) // a function into a C file, ok
832{
833 uint32_t len;
834 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
835 while(true) // true is bool, not per defaut in C -> error 20: undefined
836 {
837 //dostuff
838 }
839 // return an int; is also missing
840}
841------------------------------
8421> libc.c
8431> prx.c
8441>prx.c(128,7): error 20: identifier "true" is undefined
845========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
846extern "C" int dbprint(char * text) // no extern C, you are in C
847{
848 uint32_t len;
849 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
850 // return missing too
851}
852------------------------------------------
8531> libc.c
8541> prx.c
8551>prx.c(123,7): error 40: expected an identifier
8561>
8571>prx.c(123,7): error 261-D: explicit type is missing ("int" assumed)
858========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
859int dbprint(char * text)
860{
861 uint32_t len;
862 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
863 // return an int missing, no error in VS ?
864}
865-------------------------------------------
866========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
867Upvote 1
868Lucif3r reacted to this
8690
870Lucif3r
871Sarcasmaclysmic
872Lucif3r
873Super Admin
874
875Founding Member
876 2,459
8772,945 posts
878Location: Far away, in a dark cave ,,^..^,,
879Posted February 18, 2015
880 On 2/18/2015 at 5:37 AM, 3141card said:
881
882
883LOL, now I see, you have renamed prx.cpp to prx.c, a .c file is C code, the extern C is useless,
884
885and bool is not available per default into C.
886
887
888
889
890
891......................................................... *renames*
892
893extern "C" int _prx_start(void)
894{
895 while(true)
896 {
897 //work?
898 }
899 ppu_thread_exit();
900 return SYS_PRX_RESIDENT;
901}
902--------------------------------
9031> libc.c
9041> prx.cpp
9051>prx.cpp(128): warning 942: missing return statement at end of non-void function "dbprint" <-- that answer your question :P? I am aware of that :), it whines, but compiles and works fine, I am obviously adding a return now though :)
906========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
907...... Im an idiot... lol... How the hell could I have missed that... Thanks a lot :D
908
909Upvote 1
9103141card reacted to this
9110
912Lucif3r
913Sarcasmaclysmic
914Lucif3r
915Super Admin
916
917Founding Member
918 2,459
9192,945 posts
920Location: Far away, in a dark cave ,,^..^,,
921Posted February 18, 2015
922...
923
924#include <cell/sysmodule.h>
925void loadStuff(void)
926{
927 int32_t ret;
928 ret = cellSysmoduleLoadModule( CELL_SYSMODULE_IO );
929 //a few more calls
930
931}
932---------------------------------------
9331> undefined reference to `cellSysmoduleLoadModule' <-- one for each call
9341>Command line : error : L0303: error generating PRX (prx-fixup failed)
9351>Command line : error : L0064: Linking aborted
936========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
937sysmodule.h
938
939/* function prototypes */
940int cellSysmoduleLoadModule(uint16_t id);
941using 'extern "C" ' for the loadStuff function doesnt change a thing...
942
943
944
94556331217.jpg
946
947Upvote 1
948zecoxao reacted to this
9490
950zecoxao
951Posting Freak
952zecoxao
953Super Admin
954
955Founding Member
956Scene Contributor
957V.I.P
958 1,348
959882 posts
960Posted February 18, 2015 (edited)
961 On 2/18/2015 at 7:28 AM, Lucif3r said:
962snip
963
964you need to link the library (-l<name of library) in the Makefile
965
9661>Command line : error : L0064: Linking aborted Edited February 18, 2015 by zecoxao
967Upvote 1
968Lucif3r reacted to this
9690
970Lucif3r
971Sarcasmaclysmic
972Lucif3r
973Super Admin
974
975Founding Member
976 2,459
9772,945 posts
978Location: Far away, in a dark cave ,,^..^,,
979Posted February 18, 2015
980 On 2/18/2015 at 7:43 AM, zecoxao said:
981you need to link the library (-l<name of library) in the Makefile
982
983
984
985lol... Thanks, that fixed it. Weird though, you'd imagine VS would add that automatically... Or maybe Im just too spoiled by C# lol.
986
987
988
989
990
991Alright, time to take a break from this, theres only so much info I can take in each day lol. Thanks for all the help so far :) Im sure I'll be back with more lol :smashing-computer:
992
9930
9943141card
995Member
9963141card
997Founding Member
998
999V.I.P
1000 172
1001112 posts
1002Location: Germany
1003Posted February 18, 2015
1004Its ok patrick, no need for loading the io module, it is already loaded by vsh. Notice, your plugin is only a thread into
1005
1006the vsh process, things like network, io, fs, ... are loaded and running.
1007
1008
1009
1010If you would use a pad, look at mysis plugin.
1011
10120
1013Lucif3r
1014Sarcasmaclysmic
1015Lucif3r
1016Super Admin
1017
1018Founding Member
1019 2,459
10202,945 posts
1021Location: Far away, in a dark cave ,,^..^,,
1022Posted February 19, 2015
1023Aaand Im stuck again... Similar issue as the last one, except I cant seem to find a fix for this...
1024
1025This time its printf(and sprintf) that gives me "undefined reference to `printf'". This reference is located in stdio.h, and is included properly, and libio_stub.a is included in the 'make' argument...
1026
1027
1028
1029I also tried stealing mysis' vsh_sprintf function, incl his * getNIDfunc function. That one gives me "undefined reference to `strncmp'", which is located in string.h, which is included in the project...
1030
1031
1032
1033Ugh... Im getting sick of all these undefined references that are referenced already lol...
1034
10350
1036Frankie
1037Member
1038Frankie
1039Regular Member
1040
1041 2
104214 posts
1043Posted February 19, 2015
1044 On 2/19/2015 at 2:29 PM, Lucif3r said:
1045Aaand Im stuck again... Similar issue as the last one, except I cant seem to find a fix for this...
1046
1047This time its printf(and sprintf) that gives me "undefined reference to `printf'". This reference is located in stdio.h, and is included properly, and libio_stub.a is included in the 'make' argument...
1048
1049
1050
1051I also tried stealing mysis' vsh_sprintf function, incl his * getNIDfunc function. That one gives me "undefined reference to `strncmp'", which is located in string.h, which is included in the project...
1052
1053
1054
1055Ugh... Im getting sick of all these undefined references that are referenced already lol...
1056
1057#define TOC 0x12345678
1058
1059struct opd_s
1060{
1061 uint32_t sub;
1062 uint32_t toc;
1063};
1064
1065opd_s printf_stub = { 0x12345678, TOC };
1066int(*printf)(const char * format, ...) = (int(*)(const char*, ...))&printf_stub;
1067You could always do this.
1068
10690
1070Lucif3r
1071Sarcasmaclysmic
1072Lucif3r
1073Super Admin
1074
1075Founding Member
1076 2,459
10772,945 posts
1078Location: Far away, in a dark cave ,,^..^,,
1079Posted February 19, 2015
1080Yeah, if only...
1081
10821>prx.cpp(278,5): error 102: "printf" has already been declared in the current scope
10831>
10841>prx.cpp(278,5): error 160: declaration is incompatible with previous "std::printf" (declared at line 143 of "$(SCE_PS3_ROOT)\target\ppu\include\stdio.h")
1085time to borrow mr.dutch's wall.... :bash_head:
1086
10870
10883141card
1089Member
10903141card
1091Founding Member
1092
1093V.I.P
1094 172
1095112 posts
1096Location: Germany
1097Posted February 20, 2015
1098libio_stub.a has nothing to do with stdio.h or C, its the PS3 IO library, -> pad, mouse, keyboard, remote control, ....
1099
1100
1101
1102I try to use the stub libs (I create for vsh exports) in VS project, works fine:
1103
1104
1105
1106http://www.mediafire.com/download/dtahiqronu1nk2d/test_plugin.rar
1107
1108
1109
1110I hate VS and to work with it, I include only 3 libs for test, If you would add the rest:
1111
1112
1113
1114Into the export headers you have C functions, so you must use extern "C"
1115
1116or you get name mangling trouble. Regarding classes, look at mysis code.
1117
1118
1119
1120Using this export libs is the most comfortable way to use vsh exports, if you need
1121
1122e.g. printf(), simply use it. :)
1123
1124Upvote 1
1125Lucif3r reacted to this
11260
1127Lucif3r
1128Sarcasmaclysmic
1129Lucif3r
1130Super Admin
1131
1132Founding Member
1133 2,459
11342,945 posts
1135Location: Far away, in a dark cave ,,^..^,,
1136Posted February 20, 2015
1137Ok, I got it to work... However I didnt actually learn anything :( Except libio_stub has nothing to do with it lol, and I should include headers with #include "header.h" and not #include <header.h>(<- thats just for external dependencies if I understood it correctly?)
1138
1139
1140
1141But why did this work, and not the normal stdio definition? How can I learn when I need to apply special witchcraft and when not? Any references available so I can learn to make this witchcraft( :P)?
1142
1143
1144
1145I have been looking a lot at mysis plugins, or well, his record plugin... But when he starts with gibberish like "(void*&)(vshmain_981D7E9F) = (void*)((int)getNIDfunc("vshmain",0x981D7E9F));", thats when I crawl into a corner and weep lol. I understand (somewhat) what it does, but I dont understand how you find out you should use e.g "981D7E9F" and whatelse. or how to "translate" it to "words". I have no problems understanding stuff like "rec_interface = (rec_plugin_interface *)plugin_GetInterface(View_Find("rec_plugin"),1);", but all those random numbers..... lol
1146
1147I think Ive bitten off more than I can chew :/
1148
1149
1150
1151
1152
1153Thanks for all your help by the way, really appreciate it :)
1154
1155
1156
1157edit: actually, you could help me with one more thing if you want. :)
1158
1159
1160
1161It seems I misunderstood what s/printf did. What Im looking for is a way to output messages to the console in TM(sprintf actually did that, but not on request, it outputted a while after the call, seemingly random).
1162
1163I have one, "system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len);", but I cant seem to get it working similar as "sprintf("moo %02x", randomint)", it only accepts a single string/chararray, and ignores the ",randomint" arg(meaning the output is literally "moo %02x").
1164
1165Upvote 1
11663141card reacted to this
11670
11683141card
1169Member
11703141card
1171Founding Member
1172
1173V.I.P
1174 172
1175112 posts
1176Location: Germany
1177Posted February 20, 2015
1178#include <header.h> its a standard header into systemdir, if you write e.g. a own -> #include "header.h".
1179
1180
1181
1182 Quote
1183
1184
1185But why did this work,...
1186
1187this prx coding is not like normal coding, again, the plugin main thread is only a thread into the vsh process of ps3.
1188
1189
1190
1191There is no way for use e.g. standard C things like memset(). But the vsh proc export many functions, and
1192
1193we can use this exports.
1194
1195
1196
1197 Quote
1198
1199
1200(void*&)(vshmain_981D7E9F) = (void*)((int)getNIDfunc("vshmain",0x981D7E9F));",
1201
1202
1203
1204Its a functions pointer, an addr into vsh code where the code of an function (e.g. one of the exports) starts.
1205
1206mysis getNIDfunc() get this addr by module name ("vshmain") and node-id (0x981D7E9F).
1207
1208If you call this addr with the proper args, this code/function will be exec.
1209
1210
1211
1212 Quote
1213
1214
1215..., but I dont understand how you find out you should use e.g "981D7E9F"...
1216
1217I use e.g. the old IDA scripts from kakaroto, this scripts identify a many, the rest must be disassembled, e.g. by mysis.
1218
1219http://www.psdevwiki.com/ps3/VSH#Exports
1220
1221
1222
1223A many gcm functions was easy to identify by method codes. Syscalls, error-codes and strings are allways helpfull.
1224
1225The rest is simply reversing, its like a puzzle, thats fun.
1226
1227
1228
1229The plugin stuff is maybe not the best start into a new lang, :) And yes, names are better than nid's.
1230
1231
1232
1233Upvote 3
1234Lucif3r, mysis and zecoxao reacted to this
12350
12363141card
1237Member
12383141card
1239Founding Member
1240
1241V.I.P
1242 172
1243112 posts
1244Location: Germany
1245Posted February 20, 2015
1246char msg[128]; // a string buffer
1247int val = 666;
1248
1249sprintf(msg, // buffer to hold the result
1250 "number %d", // string format
1251 val); // var
1252http://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
1253
1254
1255
1256
1257
1258
1259
1260
1261Lucif3r
1262Sarcasmaclysmic
1263Lucif3r
1264Super Admin
1265
1266Founding Member
1267 2,459
12682,945 posts
1269Location: Far away, in a dark cave ,,^..^,,
1270Posted February 20, 2015
1271Yes, I know that already :).
1272
1273I fixed it all by myself(!!!) though. The issue was it couldnt handle its job alongside tty_write. Removing all simultaneous tty_write calls improved it alot.
1274
1275However its still not perfect, I got the output in the while(true) loop, with a somewhat long(3sec) delay between each loop to not get spammed to death. However it stops working after 6-7 loops. Is there some kind of buffer thats not getting erased that I need to manually erase after each printf or something?
1276
1277Worth pointing out is that tty_write can keep spamming the console forever with a 100ms delay between each loop...
1278
12790
12803141card
1281Member
12823141card
1283Founding Member
1284
1285V.I.P
1286 172
1287112 posts
1288Location: Germany
1289Posted February 20, 2015
1290Its bad to say something without to see the code.
1291
1292
1293
1294Give out msg's only if something is hapen, and not continously into a while-loop
1295
1296
1297
1298The memory you have into your plugin thread is = the stack size of your plugin main thread.
1299
1300if you need more, for whatever, use sys_memory_allocate() ...
1301
1302
1303
1304If you have e.g. char msg[128]; into your main, than yes, without freeing, your stack memory runs out.
1305
1306put such things never into a while loop. You need only one string buffer to hold you msg, not each round
1307
1308a new.
1309
13100
1311Lucif3r
1312Sarcasmaclysmic
1313Lucif3r
1314Super Admin
1315
1316Founding Member
1317 2,459
13182,945 posts
1319Location: Far away, in a dark cave ,,^..^,,
1320Posted February 21, 2015
1321Mmm, heres a snippet of the code.
1322
1323while(true)
1324{
1325 sys_timer_usleep(2000); //tried different delays
1326 if(cellPadGetData(0, &data) == CELL_PAD_OK && data.len > 0)
1327 {
1328 if(data.button[CELL_PAD_BTN_OFFSET_PRESS_R2] > 0)// & CELL_PAD_CTRL_R2)
1329 {
1330 //printf("moo %02d ", data.button[CELL_PAD_BTN_OFFSET_PRESS_R2]);
1331 sys_timer_usleep(100); //tried different delays here as well
1332 dbprint("char test ");
1333 //printf("char test1 ");
1334 }
1335 }
1336}
1337the above code, with dbprint (tty_write), can spam the console(TM's console) forever when holding R2, even if I completely remove the first delay and only keep the 100ms delay(I have not tried to go lower, why would I lol).
1338
1339Replacing dbprint("char test ") with printf("char test1 "), regardless of delay(I tried up to a total of 5sec), and it stops printing after 4-7 loops. Using both dbprint and printf at the same time pretty much causes printf to not not print anything at all, while dbprint still prints(not exactly an issue, kinda makes sense when I think about it).
1340
1341printf("moo %02d", ...) behaves exactly the same as printf("char test1 "), so its not related to the reading of the button-data. The few times it prints, even printf("moo %02d", ...) works as expected.
1342
1343Since Im not actually using char x[x];, and instead pass the string directly in printf, I shouldnt be filling any buffer... At least not on purpose lol
1344
1345
1346
1347-----
1348
1349
1350
1351Printing debug shit to the console aside, having this kind of loop kinda causes the controller to be quite unresponsive outside of the plugin(which is not surprising, and was expected). :P
1352
1353Would it be a better option to completely hook the controller to the plugin, and then just redirect the button presses from the plugin to the PS3? I think I saw a method of doing that in some of Sony's documents/examples... Although Im not sure if it would work for a plugin, as pretty much all of sony's examples works from within a self(which seems to have more access, but sony doesnt know about CFW in their documents, so I dunno...).
1354
1355
1356
1357I dont want to copy mysis' method from his record plugin, as his button-registration to the plugin is slow-as-hell, thats not really what Im after. At the moment I pretty much just want to show the buttons "live", not X seconds after the press(mysis' R3(start recording) can take up to 10sec to register :/).
1358
13590
13603141card
1361Member
13623141card
1363Founding Member
1364
1365V.I.P
1366 172
1367112 posts
1368Location: Germany
1369Posted February 21, 2015
1370sys_timer_usleep(100); is nothing
1371
1372
1373
1374If I have a menu and would select a line e.g. with d-pad up/down, I use a button delay of 80000 or 100000(1/10 sec)
1375
1376or it is not posible to select proper, too fast.
1377
1378
1379
1380And I use CEX, so I have no tty syscalls.
1381
1382
1383
1384How look your dbprint() ?
1385
13860
1387Lucif3r
1388Sarcasmaclysmic
1389Lucif3r
1390Super Admin
1391
1392Founding Member
1393 2,459
13942,945 posts
1395Location: Far away, in a dark cave ,,^..^,,
1396Posted February 21, 2015
1397I posted it earlier, but here it is again(you even commented about it, about the return etc :>);
1398
1399int dbprint(const char * text, ...)
1400{
1401 uint32_t len;
1402 system_call_4(403, 0, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
1403 return 1;
1404
1405}
1406Btw, 100ms is, last I checked, 1/10th of a second ;)
1407
14080
14093141card
1410Member
14113141card
1412Founding Member
1413
1414V.I.P
1415 172
1416112 posts
1417Location: Germany
1418Posted February 21, 2015
1419u(micro)sleep(), not milli ;) 1/10 sec = 100 millisecond = 100000 microseconds
1420
1421
1422
1423int dbprint(const char * text, ...) the ... is useless, int dbprint(const char * text)
1424
1425
1426
1427I test some things...
1428
14290
1430Lucif3r
1431Sarcasmaclysmic
1432Lucif3r
1433Super Admin
1434
1435Founding Member
1436 2,459
14372,945 posts
1438Location: Far away, in a dark cave ,,^..^,,
1439Posted February 21, 2015
1440Thats funny, because usleep(2000) results in the exact same delay as sleep(2)? :s
1441
1442And sony docs even said it was used for ms... I'll try increasing the delay just-because. I actually believe you more than Sony's pile of garbage docs lol, because I reacted to the func.naming and sonys docs when I first read it as well.
1443
1444
1445
1446 On 2/21/2015 at 4:23 AM, 3141card said:
1447int dbprint(const char * text, ...) the ... is useless, int dbprint(const char * text)
1448
1449
1450
1451
1452
1453I know the "..." is useless, I was trying a few things and just havnt removed it. :) It doesnt harm anyone being there, except looking ugly of course.
1454
14550
14563141card
1457Member
14583141card
1459Founding Member
1460
1461V.I.P
1462 172
1463112 posts
1464Location: Germany
1465Posted February 21, 2015
1466I think this it you search for:
1467
1468#include <stdio.h>
1469#include <stdarg.h> // for va_list, va_start, va_arg, va_end
1470
1471...
1472
1473extern "C" void dbprint(const char * text, ...)
1474{
1475 uint32_t len;
1476 char buf[0x200];
1477 va_list arg;
1478
1479 va_start(arg, text);
1480 vsnprintf(buf, sizeof(buf), text, arg);
1481 va_end(arg);
1482
1483 system_call_4(403, 0, (uint64_t) buf, strlen(buf), (uint64_t) &len); //tty write
1484}
1485
1486...
1487
1488 dbprint("test: %d", 666); // output: test: 666
1489Upvote 1
1490Lucif3r reacted to this
14910
1492Lucif3r
1493Sarcasmaclysmic
1494Lucif3r
1495Super Admin
1496
1497Founding Member
1498 2,459
14992,945 posts
1500Location: Far away, in a dark cave ,,^..^,,
1501Posted February 21, 2015
1502Thanks, unfortunately that gave me about the same result as my own attempts, namely some kind of crash on load(or, more accurately, the first call to dbprint()).
1503
1504
1505
1506Heres the log, maybe you can make some sense of it lol:
1507
1508 Reveal hidden contents
1509HAI! lv2(2): # lv2(2): # lv2(2): # system software version: 4.65 (DEX) lv2(2): # revision: 50402 lv2(2): # lv2(2): # Lv-2 detected an interrupt(exception) in a user PPU Thread. lv2(2): # lv2(2): # Interrupt(exception) Info. lv2(2): # Type : Data Segment lv2(2): # SRR0 : 0x00000000000a4e68 lv2(2): # SRR1 : 0x800000000000c032 lv2(2): # DSISR: 0x0000000000200000 lv2(2): # DAR : 0xffffffffffff90a8 lv2(2): # TB : 0x0000000250a1db50 lv2(2): # HW Thread #: 1 lv2(2): # lv2(2): # Backtrace lv2(2): # 0xfffffffffffffffc lv2(2): # 0x00000000000aa544 lv2(2): # 0x00000000000a2c88 lv2(2): # 0x00000000008e0368 lv2(2): # 0x00000000008e0448 lv2(2): # 0xbadadd0010200fac lv2(2): # lv2(2): # User PPU Thread Info. lv2(2): # ID : 0x010200fb lv2(2): # Name : lv2(2): # Stack addr: 0x00000000d00c2000 lv2(2): # Stack size: 0x0000000000001000 lv2(2): # Priority : 0 lv2(2): # Proc name : /dev_flash/vsh/module/vsh.self lv2(2): # Proc ID : 0x1000300 lv2(2): # lv2(2): # Register Info. lv2(2): # LR: 0x00000000000aa548 CR:0x48000008 lv2(2): # CTR: 0x0000000000000000 lv2(2): # lv2(2): # GPR 0: 0x00000000000aa548 GPR 1: 0x00000000d00c2a20 lv2(2): # GPR 2: 0x0000000000705ea0 GPR 3: 0x00000000d00c2b20 lv2(2): # GPR 4: 0x00000000008e080c GPR 5: 0x000000007fffffff lv2(2): # GPR 6: 0x00000000d00c2b28 GPR 7: 0xffffffffffff90a8 lv2(2): # GPR 8: 0x0000000000000000 GPR 9: 0x00000000000001ff lv2(2): # GPR10: 0x8000000000402800 GPR11: 0x0000000000000000 lv2(2): # GPR12: 0x00000000006fca50 GPR13: 0x0000000000000000 lv2(2): # GPR14: 0x0000000000000000 GPR15: 0x0000000000000000 lv2(2): # GPR16: 0x0000000000000000 GPR17: 0x0000000000000000 lv2(2): # GPR18: 0x0000000000000000 GPR19: 0x0000000000000000 lv2(2): # GPR20: 0x0000000000000000 GPR21: 0x0000000000000000 lv2(2): # GPR22: 0x0000000000000000 GPR23: 0x0000000000000000 lv2(2): # GPR24: 0x0000000000000000 GPR25: 0x00000000d00c2b24 lv2(2): # GPR26: 0x00000000d00c2b28 GPR27: 0x00000000d00c2c80 lv2(2): # GPR28: 0x00000000008e080c GPR29: 0x00000000008e080c lv2(2): # GPR30: 0x00000000d00c2b20 GPR31: 0x00000000008e080c lv2(2): # lv2(2): # XER: 0x0000000000000000 FPSCR: 0x00000000 lv2(2): # lv2(2): # FPR 0: 0x00000010203fb000 FPR 1: 0x0000000000000000 lv2(2): # FPR 2: 0x0000000000000000 FPR 3: 0x0000000000000000 lv2(2): # FPR 4: 0x0000000000000000 FPR 5: 0x0000000000000000 lv2(2): # FPR 6: 0x0000000000000000 FPR 7: 0x0000000000000000 lv2(2): # FPR 8: 0x0000000000000000 FPR 9: 0x0000000000000000 lv2(2): # FPR10: 0x0000000000000000 FPR11: 0x0000000000000000 lv2(2): # FPR12: 0x0000000000000000 FPR13: 0x0000000000000000 lv2(2): # FPR14: 0x0000000000000000 FPR15: 0x0000000000000000 lv2(2): # FPR16: 0x0000000000000000 FPR17: 0x0000000000000000 lv2(2): # FPR18: 0x0000000000000000 FPR19: 0x0000000000000000 lv2(2): # FPR20: 0x0000000000000000 FPR21: 0x0000000000000000 lv2(2): # FPR22: 0x0000000000000000 FPR23: 0x0000000000000000 lv2(2): # FPR24: 0x0000000000000000 FPR25: 0x0000000000000000 lv2(2): # FPR26: 0x0000000000000000 FPR27: 0x0000000000000000 lv2(2): # FPR28: 0x0000000000000000 FPR29: 0x0000000000000000 lv2(2): # FPR30: 0x0000000000000000 FPR31: 0x0000000000000000 lv2(2): # lv2(2): # PRX Info: 5 PRX in process lv2(2): # --/--: id-------- path------------------------------ version segments--- lv2(2): # 0/ 5: 0x23001603 [/dev_flash/sys/internal/sys_audio.sprx] 1. 1 2 segme nts lv2(2): # ---/--- base------+filesz----+(mem-file) [flags-----] lv2(2): # 0/ 2: 0x00770000+0x000aa080+0x00000000 [0x00000001] lv2(2): # 1/ 2: 0x00820000+0x00004574+0x00039d74 [0x00000001] lv2(2): # 1/ 5: 0x23003606 [/dev_flash/vsh/module/webftp_server.sprx] 0. 1 2 seg ments lv2(2): # ---/--- base------+filesz----+(mem-file) [flags-----] lv2(2): # 0/ 2: 0x00cc0000+0x0002980c+0x00000000 [0x00000001] lv2(2): # 1/ 2: 0x00b60000+0x00004e44+0x00000928 [0x00000001] lv2(2): # 2/ 5: 0x23010e06 [/dev_flash/vsh/module/basic_plugins.sprx] 1. 1 2 seg ments lv2(2): # ---/--- base------+filesz----+(mem-file) [flags-----] lv2(2): # 0/ 2: 0x00860000+0x0004e6f0+0x00000000 [0x00000001] lv2(2): # 1/ 2: 0x008b0000+0x00002714+0x00003a88 [0x00000001] lv2(2): # 3/ 5: 0x23010408 [/dev_flash/vsh/module/eseidle.sprx] 1. 1 2 segments lv2(2): # ---/--- base------+filesz----+(mem-file) [flags-----] lv2(2): # 0/ 2: 0x008c0000+0x00000d5c+0x00000000 [0x00000001] lv2(2): # 1/ 2: 0x008d0000+0x000000d4+0x00005144 [0x00000001] lv2(2): # 4/ 5: 0x23023807 [/dev_hdd0/game/PRXLOADER/USRDIR/simple-c_prx.sprx] 1. 1 2 segments lv2(2): # ---/--- base------+filesz----+(mem-file) [flags-----] lv2(2): # 0/ 2: 0x008e0000+0x00000850+0x00000000 [0x00000001] lv2(2): # 1/ 2: 0x008f0000+0x00000070+0x00000018 [0x00000001] lv2(2): # lv2(2): # Continue... (Lv-2 is still running.) lv2(2): # lv2(2): System Warning : busy loop detected lv2(2): System Warning : busy loop detected lv2(2): System Warning : busy loop detected lv2(2): System Warning : busy loop detected <-- continues until I reset the , black screen
1510
1511
1512And this is how it should look when everything's fine:
1513
1514Game: game exec processID = [0x01010200]
1515HAI!
1516Thread created
1517Im ready!
1518Note that these are still just string calls(dbprint("HAI! \n") for example). I tried changing the first call to "dbprint("HAI! %d\n", 123)", and the same thing happened, except "HAI! 123" got printed after the error log, before the system warning.
1519
1520Seeing as it did in fact print the "123" part, the function code itself seems to be working, but something is causing the ps3 to freeze after the first call. :(
1521
1522
1523
1524
1525
1526Edit: And yes, this IS exactly what Im looking for and been trying to pull off for quite a while now lol
1527
15280
15293141card
1530Member
15313141card
1532Founding Member
1533
1534V.I.P
1535 172
1536112 posts
1537Location: Germany
1538Posted February 21, 2015
1539No idea, I never use tty.
1540
1541
1542
1543Maybe you can try a other channel than 0, 0 to 2 are system reserved, 3 to 15 are for user.
1544
1545
1546
1547Maybe this fix the prob.
1548
1549Upvote 1
1550Lucif3r reacted to this
15510
1552Lucif3r
1553Sarcasmaclysmic
1554Lucif3r
1555Super Admin
1556
1557Founding Member
1558 2,459
15592,945 posts
1560Location: Far away, in a dark cave ,,^..^,,
1561Posted February 21, 2015
1562Unfortunately, changing channel did jack-squat, still same shit... ughhhhhhhhhhhh *flips table*
1563
15640
1565Lucif3r
1566Sarcasmaclysmic
1567Lucif3r
1568Super Admin
1569
1570Founding Member
1571 2,459
15722,945 posts
1573Location: Far away, in a dark cave ,,^..^,,
1574Posted February 21, 2015
1575vsnprintf(buf, sizeof(buf), text, arg);
1576
1577Thats what causing the freeze/crash, if I comment that line it doesnt freeze. If I comment any other line except that one, the freeze still happens
1578
1579
1580
1581
1582
1583edit: after sniffing google Ive concluded the crash happens when trying to convert int to char *. When doing the conversion, 1 of 2 things happens: First one is a crash/freeze, second one is nothing. Nothing at all.
1584
1585I think I've gone through all different methods by now, except 'itoa', as that command doesnt exist(?). It exists in stdlib, but that doesnt help me lol...
1586
15870
15883141card
1589Member
15903141card
1591Founding Member
1592
1593V.I.P
1594 172
1595112 posts
1596Location: Germany
1597Posted February 21, 2015
1598Sry my friend, I forget something into the C++ plugin. And btw, it can't be vsnprintf().
1599
1600
1601
1602There is a usleep(70000) at the end of the main while of the cobra test plugin,
1603
1604the reason for this delay is the usage of cellPadGetData(0, &data).
1605
1606
1607
1608If our plugin ask, without delay, for pad data for pad port 0, than the vsh process
1609
1610can't ask, therefor pad bug into xmb. Our main while block the system:
1611
1612
1613
1614lv2(2): System Warning : busy loop detected (our main while)
1615
1616
1617
1618I use for a long time no own pad data struct or cellPadGetData() into my C plugins.
1619
1620I found it idiotic, to ask for data which are already here. The vsh process have a own
1621
1622pad data struct, so why ask a second time for data which are already exist.
1623
1624
1625
1626Therefore I forget it, add this delay at the end of your main while for proper sync:
1627
1628...
1629 while(true)
1630 {
1631 if(cellPadGetData(0, &data) == CELL_PAD_OK && data.len > 0)
1632 {
1633 bool start = (data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_START);
1634
1635 if(start)
1636 {
1637 exit_thread = true;
1638 vshtask_notify("plugin stop...");
1639 }
1640 }
1641
1642 if(exit_thread == true)
1643 ppu_thread_exit();
1644
1645 sys_timer_usleep(70000); // pad get data sync delay
1646 } // main while end
16470
1648Lucif3r
1649Sarcasmaclysmic
1650Lucif3r
1651Super Admin
1652
1653Founding Member
1654 2,459
16552,945 posts
1656Location: Far away, in a dark cave ,,^..^,,
1657Posted February 21, 2015
1658FIXED IT! all by myself lol(see, I can do something on my own!). So this is how I had to do it:
1659
1660//inside while(true), after checking pad data etc
1661char f[0x40];
1662snprintf(f,100,"moo %02d ", data.button[CELL_PAD_BTN_OFFSET_PRESS_R2]);
1663dbprint(f);
1664sys_timer_usleep(100000);
1665f[sizeof(f) / sizeof(f[0])] = '\0';
1666//rinse and repeat
1667Output:
1668
1669Im ready!
1670moo 255 moo 255 moo 255 moo 255 moo 255 moo 255 moo 255 moo 255 moo 100 moo 127 moo 66 mo
1671o 72 moo 56 moo 56 moo 18 moo 39 moo 38 moo 58 moo 255 moo 255 moo 50 moo 55 moo 97 moo 2
167255 moo 255 moo 122 moo 108 moo 190 moo 255 moo 255
1673Im going to tidy it up so it looks better... atm its a mess lol.
1674
16750
16763141card
1677Member
16783141card
1679Founding Member
1680
1681V.I.P
1682 172
1683112 posts
1684Location: Germany
1685Posted February 21, 2015
1686sys_timer_usleep(100000); this is the fix, a delay for non blocking the vsh
1687
16880
1689Lucif3r
1690Sarcasmaclysmic
1691Lucif3r
1692Super Admin
1693
1694Founding Member
1695 2,459
16962,945 posts
1697Location: Far away, in a dark cave ,,^..^,,
1698Posted February 21, 2015
1699Ive had that all a long though, well, since you said that thing about usleep a couple of posts back.
1700
1701----
1702
1703Dunno if its something still not right with my code, or if its just something else, but it seems to randomly lose the pressed-data, resulting in it becoming unresponsive for a little while, then it picks up again just fine. Meh, dont care, I got my debug-printing-function now and it works fine, and the controller no longer clogs up in XMB like it used to(So I guess you were right about usleep :)).
1704
1705
1706
1707With that out of the way, I can actually start trying to MAKE something out of this lol
1708
1709Upvote 1
17103141card reacted to this
17110
17123141card
1713Member
17143141card
1715Founding Member
1716
1717V.I.P
1718 172
1719112 posts
1720Location: Germany
1721Posted February 21, 2015
1722Ok, than learn, try out things and release nice stuff in future :)
1723
1724Upvote 1
1725Lucif3r reacted to this
17260
1727Lucif3r
1728Sarcasmaclysmic
1729Lucif3r
1730Super Admin
1731
1732Founding Member
1733 2,459
17342,945 posts
1735Location: Far away, in a dark cave ,,^..^,,
1736Posted February 21, 2015
1737Well, merging the above into the dbprint function caused it to go haywire again(freezing).. After much trial and error I have found the cause, but no solution...
1738
1739The cause is when you call dbprint with no extra argument, e.g 'dbprint("string!");'. That will cause the freeze Ive struggled with for so long. However, calling dbprint with another arg, e.g 'dbprint("string! %d", 1);' works just fine.
1740
1741And there doesnt seem to be any way of determining if va_list contains an additional argument or not, at least not if the static arg isnt an int(and in my case its a char*) :(
1742
1743
1744
1745So, yeah, unless someone has a cleaver way of determining if theres an addition argument or not, I guess I'll just have to split it into 2 different functions.
1746
1747
1748
1749Heres the dbprint in its current form for reference, its not much different from 3141card's on the previous page(which has the exact same issue).
1750
1751void dbprint(const char * text, ...)
1752{
1753 uint32_t len;
1754 va_list arg;
1755 char f[0x40];
1756 va_start(arg, text);
1757 int g = va_arg(arg, int);
1758 sprintf(f,text, g);
1759 va_end(arg);
1760 system_call_4(403, 3, (uint64_t) f, strlen(f), (uint64_t) &len); //tty write
1761 f[sizeof(f) / sizeof(f[0])] = '\0';
1762}
1763So, yeah, it works fine when theres an additional arg, but not as a single-arg call. According to all info I found on google, passing no argument shouldnt be an issue... But the PS3 obviously thinks otherwise....
1764
17650
1766Lucif3r
1767Sarcasmaclysmic
1768Lucif3r
1769Super Admin
1770
1771Founding Member
1772 2,459
17732,945 posts
1774Location: Far away, in a dark cave ,,^..^,,
1775Posted February 21, 2015
1776First experiment = success! Its not much, just remapped the controller to do other stuff when buttons are pressed...
1777
1778
1779
1780Still, its a start!
1781
17829q1Qe7i.png
1783
1784Upvote 2
1785sandungas and TheDarkprogramer reacted to this
17860
17873141card
1788Member
17893141card
1790Founding Member
1791
1792V.I.P
1793 172
1794112 posts
1795Location: Germany
1796Posted February 22, 2015
1797I switch to DEX to for test it, the code I post works fine.
1798
1799prx: no var's
1800prx: 666
1801prx: 888 0x1234AABB
1802prx: 0.967000
1803prx: r2 pressed
1804prx: r2 pressed
1805prx: r2 pressed
1806prx: r2 pressed
1807prx: r2 pressed
1808prx: r2 pressed
1809prx: r2 pressed
1810prx: r2 pressed
1811prx: r2 pressed
1812prx: r2 pressed
1813prx: r2 pressed
1814prx: start pressed
1815no probs with dbprintf():
1816
1817extern "C" void dbprint(const char * text, ...)
1818{
1819 uint32_t len;
1820 char buf[0x200];
1821 va_list arg;
1822
1823 va_start(arg, text);
1824 vsnprintf(buf, sizeof(buf), text, arg);
1825 va_end(arg);
1826
1827 //vshtask_notify(buf);
1828
1829 system_call_4(403, 0, (uint64_t) buf, strlen(buf), (uint64_t) &len); //tty write
1830
1831}
1832
1833...
1834
1835// into main thread
1836
1837 dbprint("prx: no var's\n");
1838 dbprint("prx: %d\n", 666);
1839 dbprint("prx: %d 0x%08X\n", 888, 0x1234AABB);
1840 dbprint("prx: %f\n", 0.967);
1841
1842...
1843// into main while
1844
1845 if(start)
1846 {
1847 exit_thread = true;
1848 dbprint("prx: start pressed\n");
1849 sys_timer_usleep(300000);
1850 }
1851
1852 if(r2)
1853 {
1854 dbprint("prx: r2 pressed\n");
1855 sys_timer_usleep(300000);
1856 }
18570
1858Lucif3r
1859Sarcasmaclysmic
1860Lucif3r
1861Super Admin
1862
1863Founding Member
1864 2,459
18652,945 posts
1866Location: Far away, in a dark cave ,,^..^,,
1867Posted February 22, 2015
1868Funny... Any theories why it goes completely emo for me?
1869
1870I split it into 2 funcs. yesterday and that works just fine, calling them at the same time, spamming them etc etc. But as soon as I try to call dbprint(char*, ...) without an additional arg it gives me the finger lol...
1871
1872
1873
1874Could it be FW or SDK related? Im using sony's 3.70 SDK, on VSC2010, along with rebug 4.65.2(previously tried on rebug 4.46, same thing there).
1875
1876
1877
1878This is how I do it now anyway.
1879void dbprintf(const char * text, ...)
1880//'extern "C" ' or not doesnt make a difference, and your function causes the exact same issues.
1881//I chose to keep my function over yours though because... Well, I made it :P, cant keep copy-pasting everyone else's code if I want to learn^^
1882{
1883 uint32_t len;
1884 va_list arg;
1885 char f[0x40];
1886 va_start(arg, text);
1887 int g = va_arg(arg, int);
1888 sprintf(f,text, g);
1889 va_end(arg);
1890 system_call_4(403, 3, (uint64_t) f, strlen(f), (uint64_t) &len); //tty write
1891 f[sizeof(f) / sizeof(f[0])] = '\0';
1892}
1893void dbprint(const char * text, ...)
1894{
1895 uint32_t len;
1896 system_call_4(403, 3, (uint64_t) text, strlen(text), (uint64_t) &len); //tty write
1897}
1898
1899//main
1900while(true)
1901{
1902 if(cellPadGetData(0, &data) == CELL_PAD_OK && data.len > 0)
1903 {
1904 if(data.button[CELL_PAD_BTN_OFFSET_PRESS_R2] > 0)
1905 {
1906 dbprintf("R2; %d pressure ", data.button[CELL_PAD_BTN_OFFSET_PRESS_R2]);
1907 data.button[3] = CELL_PAD_CTRL_CIRCLE;
1908 cellPadLddDataInsert( vPadHandle, &data );
1909 dbprint("Circle was pressed!\n");
1910 sys_timer_sleep(1); //going to adjust this sleep obviously, theres no point to have a whole second delay here.
1911 //my awesome R2 "remapper", aint it a beauty? lol........ its shit I know :(
1912 }
1913 }
1914}
1915
1916
1917
1918Oh, and again, thank you for all your help. If it wasnt for your help, I'd given up ages ago :P
1919
1920Upvote 1
19213141card reacted to this
19220
19233141card
1924Member
19253141card
1926Founding Member
1927
1928V.I.P
1929 172
1930112 posts
1931Location: Germany
1932Posted February 22, 2015 (edited)
1933No idea :(
1934
1935
1936
1937Iam furthermore on 4.46 rebug, make norbin dump with toolbox, convert with cec2dex, flash it with mm, change lv2 kernel in toolbox.
1938
1939
1940
1941sdk 400.001, TM 400.1.35.3, VS2010(I add also sys_prx_for_user_export_stub_lib, but the sample prx use no export from this module)
1942
1943
1944
1945and vsnprintf() is from stdc_lib not sys_vsnprintf() aka sysPrxForUser_0618936B.
1946
1947
1948
1949And no prob, its a nice hobby :)
1950
1951
1952
1953EDIT: I think not is a versions prob, new sdks have often impro. of highlevel stuff like thread managment
1954
1955and such things, but simply lowlevel things like tty...
1956
1957Edited February 22, 2015 by 3141card
19580
1959Lucif3r
1960Sarcasmaclysmic
1961Lucif3r
1962Super Admin
1963
1964Founding Member
1965 2,459
19662,945 posts
1967Location: Far away, in a dark cave ,,^..^,,
1968Posted February 22, 2015
1969I dont suppose you know how to intercept a button command? e.g. preventing it from doing stuff on the PS3? Simply setting the button to 'not pressed'-state right when its pressed doesnt work :)
1970
1971I can make the buttons do other stuff just fine, but not stopping it from doing its original task(e.g. 'accept' or similar) at the same time :)
1972
19730
19743141card
1975Member
19763141card
1977Founding Member
1978
1979V.I.P
1980 172
1981112 posts
1982Location: Germany
1983Posted February 22, 2015
1984I use only delays to prevent to fast inputs, works fine for me, even in complex psl1ght progs
1985
1986with menus.
1987
1988
1989
1990What you search for need status variables, something like old_pad, new_pad...
1991
1992
1993
1994sure you will find something in the sdk samples, e.g. sysutil/, I never need it.
1995
19960
1997Lucif3r
1998Sarcasmaclysmic
1999Lucif3r
2000Super Admin
2001
2002Founding Member
2003 2,459
20042,945 posts
2005Location: Far away, in a dark cave ,,^..^,,
2006Posted February 22, 2015
2007Okey, yeah I got all the pad examples open, but as usual they are meant for .self's. I also noticed I have no control over the pad in a game, dunno if its possible to get around that, or if youre limited to XMB(or your own self's)...
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024therifboy
2025Newbie
2026therifboy
2027New Member
2028
2029 0
20304 posts
2031Posted February 22, 2015 (edited)
2032You don't really need to have your own version of printf seeing VSH is exporting it. Link your program to -lc_stub. (unlink -lc)
2033
2034
2035
2036You'll have a new import stub in your plugin.
2037http://i.imgur.com/NfKAMAV.png
2038
2039
2040
2041VSH exports that same stub but under a different name.
2042http://i.imgur.com/lLrEpa7.png
2043
2044
2045What I do is open up my plugin, edit "sys_libc" to "stdc". The ps3 will take care of the rest. I don't know if there's an easier way to match the strings.
2046
2047
2048
2049edit:
2050
2051f[sizeof(f) / sizeof(f[0])] = '\0';
2052should be
2053
2054f[sizeof(f) / sizeof(f[0]) - 1] = '\0'; Edited February 22, 2015 by therifboy
20550
20563141card
2057Member
20583141card
2059Founding Member
2060
2061V.I.P
2062 172
2063112 posts
2064Location: Germany
2065Posted February 22, 2015
2066I mean samples like recording, this samples needs a pad, look at this code. :)
2067
2068Pad events are only in xmb or ingame-xmb, not ingame, thats normal, I use a other way:
2069
2070
2071
2072CellPadData *getPadDataStruct()
2073{
2074 uint64_t ret = 0;
2075 uint32_t start = 0x00708B10; // start .bss segment
2076 int32_t size = 0x00049010; // size .bss segment
2077
2078
2079 while(start != (start + size)){
2080 if((ret = *(uint64_t*)start) == 0x0000004600000046ULL)
2081 return (CellPadData*)(start - 0x8C);
2082 start+=8;
2083 }
2084
2085 return (CellPadData*)0;
2086}
2087
2088...
2089
2090 //CellPadData data;
2091 CellPadData *data = getPadDataStruct();
2092
2093 while(true)
2094 {
2095 // ask for data of the vsh pad data struct, no need for a own
2096 if(data->len > 0)
2097 {
2098 if(data->button[2] & CELL_PAD_CTRL_START)
2099 {
2100 exit_thread = true;
2101 dbprint("prx: start pressed\n");
2102 sys_timer_usleep(300000);
2103 }
2104
2105 if(data->button[3] & CELL_PAD_CTRL_R2)
2106 {
2107 dbprint("prx: r2 pressed\n");
2108 sys_timer_usleep(300000);
2109 }
2110 }
2111
2112 if(exit_thread == true)
2113 ppu_thread_exit();
2114
2115 sys_timer_usleep(70000);
2116 }
2117the vsh_pad_data are available all the time, not only in xmb and ingame xmb,
2118
2119but there is no warranty that it is generic. The search value is from a other pad object, maybe not ever
2120
2121direct behind vsh_pad_data or a other value.
2122
2123
2124
2125Hi therifboy :)