Compare commits

...

4 commits

Author SHA1 Message Date
Syping
f345963710 libragephoto: update .NET version to 0.6.1.3
- RagePhoto.cs: update all [return: MarshalAs(UnmanagedType.Bool)] to
[return: MarshalAs(UnmanagedType.I1)]
2025-10-08 09:38:36 +02:00
Syping
a0ec84cbc8 libragephoto: update .NET version to 0.6.1.2
- RagePhoto.cs: add missing [return: MarshalAs(UnmanagedType.Bool)]
- RagePhoto.cs: update filePath instances to path
- RagePhotoData.cs: update Strings to IntPtr (more safe to Marshal)
- RagePhotoTypes.cs: move DefaultSize, PhotoError and PhotoFormat to
here
2025-10-08 09:19:25 +02:00
Syping
59bd3c1249 libragephoto: update .NET version to 0.6.1.1 and add license 2025-10-08 04:28:49 +02:00
Syping
aa82187de3 RagePhoto.cs: add saveFile function 2025-10-08 04:28:02 +02:00
4 changed files with 105 additions and 79 deletions

View file

@ -1,7 +1,8 @@
using System;
using System.Runtime.InteropServices;
namespace Syping.RagePhoto {
namespace Syping.RagePhoto {
public class Photo : IDisposable {
private bool _disposed;
@ -15,10 +16,10 @@ namespace Syping.RagePhoto {
[DllImport(_library)]
private static extern void ragephoto_close(IntPtr instance);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.Bool)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_load(IntPtr instance, Byte[] data, UIntPtr size);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.Bool)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_loadfile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename);
[DllImport(_library)]
private static extern Int32 ragephoto_error(IntPtr instance);
@ -45,10 +46,18 @@ namespace Syping.RagePhoto {
[DllImport(_library)]
private static extern UIntPtr ragephoto_getsavesizef(IntPtr instance, UInt32 photoFormat);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_save(IntPtr instance, [Out] Byte[] data);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_savef(IntPtr instance, [Out] Byte[] data, UInt32 photoFormat);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_savefile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_savefilef(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename, UInt32 photoFormat);
[DllImport(_library)]
private static extern void ragephoto_setbufferdefault(IntPtr instance);
[DllImport(_library)]
private static extern void ragephoto_setbufferoffsets(IntPtr instance);
@ -57,7 +66,7 @@ namespace Syping.RagePhoto {
[DllImport(_library)]
private static extern void ragephoto_setphotoformat(IntPtr instance, UInt32 photoFormat);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.Bool)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool ragephoto_setphotojpeg(IntPtr instance, Byte[] jpeg, UInt32 size, UInt32 bufferSize);
[DllImport(_library)]
private static extern void ragephoto_setphotojson(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String json, UInt32 bufferSize);
@ -66,67 +75,7 @@ namespace Syping.RagePhoto {
[DllImport(_library)]
private static extern void ragephoto_setphototitle(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String title, UInt32 bufferSize);
[DllImport(_library)]
[return: MarshalAs(UnmanagedType.LPStr)]
private static extern String ragephoto_version();
public enum DefaultSize : UInt32 {
DEFAULT_GTA5_PHOTOBUFFER = 524288U,
DEFAULT_RDR2_PHOTOBUFFER = 1048576U,
DEFAULT_DESCBUFFER = 256U,
DEFAULT_JSONBUFFER = 3072U,
DEFAULT_TITLBUFFER = 256U,
GTA5_HEADERSIZE = 264U,
RDR2_HEADERSIZE = 272U
}
public enum PhotoError : Int32 {
DescBufferTight = 39,
DescMallocError = 31,
DescReadError = 32,
HeaderBufferTight = 35,
HeaderMallocError = 4,
IncompatibleFormat = 2,
IncompleteChecksum = 7,
IncompleteDescBuffer = 30,
IncompleteDescMarker = 28,
IncompleteDescOffset = 11,
IncompleteEOF = 8,
IncompleteHeader = 3,
IncompleteJendMarker = 33,
IncompleteJpegMarker = 12,
IncompleteJsonBuffer = 20,
IncompleteJsonMarker = 18,
IncompleteJsonOffset = 9,
IncompletePhotoBuffer = 14,
IncompletePhotoSize = 15,
IncompleteTitleBuffer = 25,
IncompleteTitleMarker = 23,
IncompleteTitleOffset = 10,
IncorrectDescMarker = 29,
IncorrectJendMarker = 34,
IncorrectJpegMarker = 13,
IncorrectJsonMarker = 19,
IncorrectTitleMarker = 24,
JsonBufferTight = 37,
JsonMallocError = 21,
JsonReadError = 22,
NoError = 255,
NoFormatIdentifier = 1,
PhotoBufferTight = 36,
PhotoMallocError = 16,
PhotoReadError = 17,
TitleBufferTight = 38,
TitleMallocError = 26,
TitleReadError = 27,
UnicodeInitError = 5,
UnicodeHeaderError = 6,
Uninitialised = 0
}
public enum PhotoFormat : UInt32 {
GTA5 = 0x01000000U,
RDR2 = 0x04000000U
}
private static extern IntPtr ragephoto_version();
public Photo() {
try {
@ -166,8 +115,8 @@ namespace Syping.RagePhoto {
throw new RagePhotoException(this, string.Format("Failed to load Photo: {0}", Error.ToString()));
}
public void LoadFile(String filePath) {
bool result = ragephoto_loadfile(_instance, filePath);
public void LoadFile(String path) {
bool result = ragephoto_loadfile(_instance, path);
if (!result)
throw new RagePhotoException(this, string.Format("Failed to load Photo: {0}", Error.ToString()));
}
@ -288,6 +237,18 @@ namespace Syping.RagePhoto {
return photo;
}
public void SaveFile(String path) {
bool result = ragephoto_savefile(_instance, path);
if (!result)
throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error.ToString()));
}
public void SaveFile(String path, PhotoFormat photoFormat) {
bool result = ragephoto_savefilef(_instance, path, (UInt32)photoFormat);
if (!result)
throw new RagePhotoException(this, string.Format("Failed to save Photo: {0}", Error.ToString()));
}
public void SetBufferDefault() {
ragephoto_setbufferdefault(_instance);
}
@ -306,7 +267,10 @@ namespace Syping.RagePhoto {
}
public static String Version {
get => ragephoto_version();
get {
IntPtr versionPtr = ragephoto_version();
return versionPtr == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(versionPtr);
}
}
}
}

View file

@ -2,17 +2,14 @@
using System.Runtime.InteropServices;
namespace Syping.RagePhoto {
[StructLayout(LayoutKind.Sequential)]
public readonly struct RagePhotoData {
readonly IntPtr jpeg;
[MarshalAs(UnmanagedType.LPUTF8Str)]
readonly String description;
[MarshalAs(UnmanagedType.LPUTF8Str)]
readonly String json;
[MarshalAs(UnmanagedType.LPUTF8Str)]
readonly String header;
[MarshalAs(UnmanagedType.LPUTF8Str)]
readonly String title;
readonly IntPtr description;
readonly IntPtr json;
readonly IntPtr header;
readonly IntPtr title;
readonly Int32 error;
readonly UInt32 descBuffer;
readonly UInt32 descOffset;

View file

@ -0,0 +1,63 @@
using System;
namespace Syping.RagePhoto {
public enum DefaultSize : UInt32 {
DEFAULT_GTA5_PHOTOBUFFER = 524288U,
DEFAULT_RDR2_PHOTOBUFFER = 1048576U,
DEFAULT_DESCBUFFER = 256U,
DEFAULT_JSONBUFFER = 3072U,
DEFAULT_TITLBUFFER = 256U,
GTA5_HEADERSIZE = 264U,
RDR2_HEADERSIZE = 272U
}
public enum PhotoError : Int32 {
DescBufferTight = 39,
DescMallocError = 31,
DescReadError = 32,
HeaderBufferTight = 35,
HeaderMallocError = 4,
IncompatibleFormat = 2,
IncompleteChecksum = 7,
IncompleteDescBuffer = 30,
IncompleteDescMarker = 28,
IncompleteDescOffset = 11,
IncompleteEOF = 8,
IncompleteHeader = 3,
IncompleteJendMarker = 33,
IncompleteJpegMarker = 12,
IncompleteJsonBuffer = 20,
IncompleteJsonMarker = 18,
IncompleteJsonOffset = 9,
IncompletePhotoBuffer = 14,
IncompletePhotoSize = 15,
IncompleteTitleBuffer = 25,
IncompleteTitleMarker = 23,
IncompleteTitleOffset = 10,
IncorrectDescMarker = 29,
IncorrectJendMarker = 34,
IncorrectJpegMarker = 13,
IncorrectJsonMarker = 19,
IncorrectTitleMarker = 24,
JsonBufferTight = 37,
JsonMallocError = 21,
JsonReadError = 22,
NoError = 255,
NoFormatIdentifier = 1,
PhotoBufferTight = 36,
PhotoMallocError = 16,
PhotoReadError = 17,
TitleBufferTight = 38,
TitleMallocError = 26,
TitleReadError = 27,
UnicodeInitError = 5,
UnicodeHeaderError = 6,
Uninitialised = 0
}
public enum PhotoFormat : UInt32 {
GTA5 = 0x01000000U,
RDR2 = 0x04000000U
}
}

View file

@ -4,12 +4,14 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>Syping.RagePhoto.Core</AssemblyName>
<RootNamespace>Syping.RagePhoto</RootNamespace>
<Version>0.6.1</Version>
<AssemblyVersion>0.6.1.0</AssemblyVersion>
<FileVersion>0.6.1.0</FileVersion>
<Version>0.6.1.3</Version>
<AssemblyVersion>0.6.1.3</AssemblyVersion>
<FileVersion>0.6.1.3</FileVersion>
<Authors>Syping</Authors>
<Copyright>Copyright © 2025 Syping</Copyright>
<Description>Open Source RAGE Photo Parser for GTA V and RDR 2</Description>
<PackageLicenseExpression>BSD-2-Clause</PackageLicenseExpression>
<RepositoryUrl>https://github.com/Syping/libragephoto</RepositoryUrl>
</PropertyGroup>
<ItemGroup>