From 4b47ce1f9bbb7847f6d55a9bd8760575141487f6 Mon Sep 17 00:00:00 2001 From: Pavel <68122101+red-prig@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:54:49 +0300 Subject: [PATCH] Branch in libSceNpCommon --- fpPS4.lpi | 7 +- fpPS4.lpr | 1 + src/np/ps4_libscenpcommon.pas | 145 +++++++++++++++++++++++++++++++++ src/np/ps4_libscenpmanager.pas | 133 +----------------------------- src/np/ps4_libscenpscore.pas | 3 +- src/ps4_libscenpwebapi.pas | 5 +- 6 files changed, 156 insertions(+), 138 deletions(-) create mode 100644 src/np/ps4_libscenpcommon.pas diff --git a/fpPS4.lpi b/fpPS4.lpi index c66ca1e..50ed00d 100644 --- a/fpPS4.lpi +++ b/fpPS4.lpi @@ -31,7 +31,7 @@ - + @@ -606,6 +606,11 @@ + + + + + diff --git a/fpPS4.lpr b/fpPS4.lpr index f960a60..a3322fd 100644 --- a/fpPS4.lpr +++ b/fpPS4.lpr @@ -35,6 +35,7 @@ uses ps4_libSceNpScore, ps4_libSceNpTrophy, ps4_libSceSystemService, + ps4_libSceNpCommon, ps4_libSceNpManager, ps4_libSceNpGameIntent, ps4_libSceSaveData, diff --git a/src/np/ps4_libscenpcommon.pas b/src/np/ps4_libscenpcommon.pas new file mode 100644 index 0000000..c956e22 --- /dev/null +++ b/src/np/ps4_libscenpcommon.pas @@ -0,0 +1,145 @@ +unit ps4_libSceNpCommon; + +{$mode ObjFPC}{$H+} + +interface + +uses + ps4_program; + +const + SCE_NP_ERROR_INVALID_ARGUMENT =-2141913085; //80550003 + SCE_NP_ERROR_CALLBACK_ALREADY_REGISTERED=-2141913080; //80550008 + + SCE_NP_ERROR_SIGNED_OUT =-2141913082; //80550006 + + + SCE_NP_UTIL_ERROR_NOT_MATCH=-2141911543; //80550609 + +const + SCE_NP_ONLINEID_MIN_LENGTH=3; + SCE_NP_ONLINEID_MAX_LENGTH=16; + +type + pSceNpOnlineId=^SceNpOnlineId; + SceNpOnlineId=packed record + data:array[0..SCE_NP_ONLINEID_MAX_LENGTH-1] of AnsiChar; + term:AnsiChar; + dummy:array[0..2] of AnsiChar; + end; + + PSceNpId=^SceNpId; + SceNpId=packed record + handle:SceNpOnlineId; + opt:array[0..7] of Byte; + reserved:array[0..7] of Byte; + end; + +implementation + +uses + ps4_map_mm; + +function ps4_sceNpCmpNpId(npid1,npid2:PSceNpId):Integer; SysV_ABI_CDecl; +begin + if (npid1=nil) or (npid2=nil) then Exit(SCE_NP_ERROR_INVALID_ARGUMENT); + + if (CompareChar0(npid1^.handle,npid2^.handle,SCE_NP_ONLINEID_MAX_LENGTH)=0) and + (QWORD(npid1^.opt)=QWORD(npid2^.opt)) then + begin + Result:=0; + end else + begin + Result:=SCE_NP_UTIL_ERROR_NOT_MATCH; + end; + +end; + +function ps4_sceNpCmpOnlineId(str1,str2:PChar):Integer; SysV_ABI_CDecl; +begin + if (str1=nil) or (str2=nil) then + Exit(SCE_NP_ERROR_INVALID_ARGUMENT); + if CompareChar0(str1,str2,SCE_NP_ONLINEID_MAX_LENGTH)=0 then + Result:=0 + else + Result:=SCE_NP_UTIL_ERROR_NOT_MATCH; +end; + +type + pnp_mem=^np_mem; + np_mem=packed record + len:qword; + unknow:qword; + ptr:Pointer; + end; + +function ps4_sceNpAllocateKernelMemoryWithAlignment( + len:qword; + name:Pchar; + ptr_out:PPointer; + mem_out:pnp_mem):Integer; SysV_ABI_CDecl; +var + pad_len:qword; +begin + if (mem_out=nil) then + begin + Exit(-$7faa7ffb); //NP-32268-1 + end; + + mem_out^.unknow:=0; + pad_len:=0; + if (len and $3fff)<>0 then + begin + pad_len:=$4000-(len and $3fff); + end; + mem_out^.len:=pad_len+len; + + Result:=ps4_sceKernelMapNamedFlexibleMemory(@mem_out^.ptr,mem_out^.len,3,0,name); + + if (ptr_out<>nil) and (Result>-1) then + begin + ptr_out^:=mem_out^.ptr; + end; +end; + +function ps4_sceNpAllocateKernelMemoryNoAlignment( + len:qword; + name:Pchar; + ptr_out:PPointer; + mem_out:pnp_mem):Integer; SysV_ABI_CDecl; +begin + if (mem_out=nil) then + begin + Exit(-$7faa7ffb); //NP-32268-1 + end; + + mem_out^.unknow:=0; + mem_out^.len:=len; + + Result:=ps4_sceKernelMapNamedFlexibleMemory(@mem_out^.ptr,mem_out^.len,3,0,name); + + if (ptr_out<>nil) and (Result>-1) then + begin + ptr_out^:=mem_out^.ptr; + end; +end; + +function Load_libSceNpCommon(Const name:RawByteString):TElf_node; +var + lib:PLIBRARY; +begin + Result:=TElf_node.Create; + Result.pFileName:=name; + + lib:=Result._add_lib('libSceNpCommon'); + lib^.set_proc($8BC5265D34AAECDE,@ps4_sceNpCmpNpId); + lib^.set_proc($763F8EE5A0F66B44,@ps4_sceNpCmpOnlineId); + lib^.set_proc($80C958E9E7B0AFF7,@ps4_sceNpAllocateKernelMemoryWithAlignment); + lib^.set_proc($3163CE92ACD8B2CD,@ps4_sceNpAllocateKernelMemoryNoAlignment); +end; + +initialization + ps4_app.RegistredPreLoad('libSceNpCommon.prx' ,@Load_libSceNpCommon); + +end. + diff --git a/src/np/ps4_libscenpmanager.pas b/src/np/ps4_libscenpmanager.pas index fbd195e..c83582f 100644 --- a/src/np/ps4_libscenpmanager.pas +++ b/src/np/ps4_libscenpmanager.pas @@ -7,8 +7,7 @@ interface uses windows, ps4_program, - Classes, - SysUtils; + ps4_libSceNpCommon; Const SCE_NP_COUNTRY_CODE_LENGTH=2; @@ -37,25 +36,6 @@ type ageRestriction:SceNpAgeRestriction; end; -const - SCE_NP_ONLINEID_MIN_LENGTH=3; - SCE_NP_ONLINEID_MAX_LENGTH=16; - -type - pSceNpOnlineId=^SceNpOnlineId; - SceNpOnlineId=packed record - data:array[0..SCE_NP_ONLINEID_MAX_LENGTH-1] of AnsiChar; - term:AnsiChar; - dummy:array[0..2] of AnsiChar; - end; - - PSceNpId=^SceNpId; - SceNpId=packed record - handle:SceNpOnlineId; - opt:array[0..7] of Byte; - reserved:array[0..7] of Byte; - end; - const SCE_NP_TITLE_ID_LEN=12; @@ -120,17 +100,8 @@ type state:Integer; //SceNpReachabilityState userdata:Pointer); SysV_ABI_CDecl; -const - SCE_NP_ERROR_INVALID_ARGUMENT =-2141913085; //80550003 - SCE_NP_ERROR_CALLBACK_ALREADY_REGISTERED=-2141913080; //80550008 - - SCE_NP_ERROR_SIGNED_OUT =-2141913082; //80550006 - implementation -uses - ps4_map_mm; - function ps4_sceNpSetContentRestriction(pRestriction:PSceNpContentRestriction):Integer; SysV_ABI_CDecl; begin Writeln('sceNpSetContentRestriction:',HexStr(pRestriction)); @@ -474,93 +445,6 @@ begin Result:=0; end; -Const - SCE_NP_UTIL_ERROR_NOT_MATCH=-2141911543; //80550609 - -function ps4_sceNpCmpNpId(npid1,npid2:PSceNpId):Integer; SysV_ABI_CDecl; -begin - if (npid1=nil) or (npid2=nil) then Exit(SCE_NP_ERROR_INVALID_ARGUMENT); - - if (CompareChar0(npid1^.handle,npid2^.handle,SCE_NP_ONLINEID_MAX_LENGTH)=0) and - (QWORD(npid1^.opt)=QWORD(npid2^.opt)) then - begin - Result:=0; - end else - begin - Result:=SCE_NP_UTIL_ERROR_NOT_MATCH; - end; - -end; - -function ps4_sceNpCmpOnlineId(str1,str2:PChar):Integer; SysV_ABI_CDecl; -begin - if (str1=nil) or (str2=nil) then - Exit(SCE_NP_ERROR_INVALID_ARGUMENT); - if StrLComp(str1,str2,SCE_NP_ONLINEID_MAX_LENGTH)=0 then - Result:=0 - else - Result:=SCE_NP_UTIL_ERROR_NOT_MATCH; -end; - -type - pnp_mem=^np_mem; - np_mem=packed record - len:qword; - unknow:qword; - ptr:Pointer; - end; - -function ps4_sceNpAllocateKernelMemoryWithAlignment( - len:qword; - name:Pchar; - ptr_out:PPointer; - mem_out:pnp_mem):Integer; SysV_ABI_CDecl; -var - pad_len:qword; -begin - if (mem_out=nil) then - begin - Exit(-$7faa7ffb); //NP-32268-1 - end; - - mem_out^.unknow:=0; - pad_len:=0; - if (len and $3fff)<>0 then - begin - pad_len:=$4000-(len and $3fff); - end; - mem_out^.len:=pad_len+len; - - Result:=ps4_sceKernelMapNamedFlexibleMemory(@mem_out^.ptr,mem_out^.len,3,0,name); - - if (ptr_out<>nil) and (Result >-1) then - begin - ptr_out^:=mem_out^.ptr; - end; -end; - -function ps4_sceNpAllocateKernelMemoryNoAlignment( - len:qword; - name:Pchar; - ptr_out:PPointer; - mem_out:pnp_mem):Integer; SysV_ABI_CDecl; -begin - if (mem_out=nil) then - begin - Exit(-$7faa7ffb); //NP-32268-1 - end; - - mem_out^.unknow:=0; - mem_out^.len:=len; - - Result:=ps4_sceKernelMapNamedFlexibleMemory(@mem_out^.ptr,mem_out^.len,3,0,name); - - if (ptr_out<>nil) and (Result >-1) then - begin - ptr_out^:=mem_out^.ptr; - end; -end; - function Load_libSceNpManager(Const name:RawByteString):TElf_node; var lib:PLIBRARY; @@ -608,23 +492,8 @@ begin lib^.set_proc($2442C77F8C4FB9FA,@ps4_sceNpCheckCallbackForLib); end; -function Load_libSceNpCommon(Const name:RawByteString):TElf_node; -var - lib:PLIBRARY; -begin - Result:=TElf_node.Create; - Result.pFileName:=name; - - lib:=Result._add_lib('libSceNpCommon'); - lib^.set_proc($8BC5265D34AAECDE,@ps4_sceNpCmpNpId); - lib^.set_proc($763F8EE5A0F66B44,@ps4_sceNpCmpOnlineId); - lib^.set_proc($80C958E9E7B0AFF7,@ps4_sceNpAllocateKernelMemoryWithAlignment); - lib^.set_proc($3163CE92ACD8B2CD,@ps4_sceNpAllocateKernelMemoryNoAlignment); -end; - initialization ps4_app.RegistredPreLoad('libSceNpManager.prx',@Load_libSceNpManager); - ps4_app.RegistredPreLoad('libSceNpCommon.prx' ,@Load_libSceNpCommon); end. diff --git a/src/np/ps4_libscenpscore.pas b/src/np/ps4_libscenpscore.pas index e783ac4..19b541c 100644 --- a/src/np/ps4_libscenpscore.pas +++ b/src/np/ps4_libscenpscore.pas @@ -6,8 +6,7 @@ interface uses ps4_program, - Classes, - SysUtils, + ps4_libSceNpCommon, ps4_libSceNpManager; implementation diff --git a/src/ps4_libscenpwebapi.pas b/src/ps4_libscenpwebapi.pas index 3ec4740..6fecdb7 100644 --- a/src/ps4_libscenpwebapi.pas +++ b/src/ps4_libscenpwebapi.pas @@ -6,9 +6,8 @@ interface uses ps4_program, - ps4_libSceNpManager, - Classes, - SysUtils; + ps4_libSceNpCommon, + ps4_libSceNpManager; implementation