Skip to content

Commit

Permalink
fix c# MarshalAs mistakes, remove learnnew from resolvedefines
Browse files Browse the repository at this point in the history
(didn't delete it from the public APIs yet for backwards compat, we can
do that in 2.0)
  • Loading branch information
randomdude999 committed Jan 30, 2024
1 parent 9bedd1e commit 417490b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/asar-dll-bindings/c/asardll.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ asarfunc const char * (*asar_getdefine)(const char * name);
//Gets the values and names of all defines.
asarfunc const struct definedata * (*asar_getalldefines)(int * count);

//Parses all defines in the parameter. The parameter controls whether it'll learn new defines in
// this string if it finds any. Note that it may emit errors.
//Parses all defines in the parameter. If there were any errors, returns an empty string.
//learnnew has not done anything for at least 12 years.
asarfunc const char * (*asar_resolvedefines)(const char * data, bool learnnew);

//Parses a string containing math. It automatically assumes global scope (no namespaces), and has
Expand Down
6 changes: 4 additions & 2 deletions src/asar-dll-bindings/c_sharp/asar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static unsafe class Asar
private static extern RawAsarDefine* asar_getalldefines(out int length);

[DllImport("asar", EntryPoint = "asar_resolvedefines", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr asar_resolvedefines(string data, bool learnNew);
private static extern IntPtr asar_resolvedefines(string data);

[DllImport("asar", EntryPoint = "asar_math", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern double asar_math(string math, out IntPtr error);
Expand Down Expand Up @@ -179,7 +179,9 @@ private struct RawPatchParams
public int warning_setting_count;
public RawMemoryFile* memory_files;
public int memory_file_count;
[MarshalAs(UnmanagedType.I1)]
public bool override_checksum_gen;
[MarshalAs(UnmanagedType.I1)]
public bool generate_checksum;
};

Expand Down Expand Up @@ -518,7 +520,7 @@ public static Asardefine[] getalldefines()
/// <returns></returns>
public static string resolvedefines(string data, bool learnNew)
{
return Marshal.PtrToStringAnsi(asar_resolvedefines(data, learnNew));
return Marshal.PtrToStringAnsi(asar_resolvedefines(data));
}

/// <summary>
Expand Down
11 changes: 5 additions & 6 deletions src/asar-dll-bindings/python/asar.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ def __init__(self, dllname):
self.setup_func("getlabelval", (c_char_p,), c_int)
self.setup_func("getdefine", (c_char_p,), c_char_p)
self.setup_func("getalldefines", (c_int_ptr,), POINTER(_definedata))
self.setup_func("resolvedefines", (c_char_p, ctypes.c_bool),
c_char_p)
self.setup_func("resolvedefines", (c_char_p,), c_char_p)
self.setup_func("math", (c_char_p, POINTER(c_char_p)),
ctypes.c_double)
self.setup_func("getwrittenblocks", (c_int_ptr,),
Expand Down Expand Up @@ -376,14 +375,14 @@ def getalldefines():
return {x.name.decode(): x.contents.decode() for x in definedatas}


def resolvedefines(data, learnnew):
def resolvedefines(data, learnnew=False):
"""Parse all defines in the given data.
Returns the data with all defines evaluated.
learnnew controls whether it'll learn new defines in this string if it
finds any. Note that it may emit errors.
If there were any errors, returns an empty string.
learnnew has never done anything.
"""
return _asar.dll.asar_resolvedefines(data, learnnew)
return _asar.dll.asar_resolvedefines(data)


def math(to_calculate):
Expand Down

0 comments on commit 417490b

Please sign in to comment.