Francesco149 / oppai-ng

difficulty and pp calculator for osu!. better, smaller, faster rewrite of https://github.com/Francesco149/oppai
The Unlicense
155 stars 36 forks source link

Why are api functions not stdcall? #46

Closed MikiraSora closed 5 years ago

MikiraSora commented 5 years ago

the library api default use cdecl , so other lang maybe have to add calling convention description explicitly or will throw exception .

        [DllImport("oppai.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ezpp_n50(ezpp_t ez);
Francesco149 commented 5 years ago

how did you compile oppai.dll? because as far as i know MSVC uses stdcall by default and i even did a RealtimePPDisplayer port that uses the new API without specifying cdecl and it works fine: https://github.com/OsuSync/RealTimePPDisplayer/pull/26/files#diff-c532c12b308b29f796a4df43691fea8eR162

Francesco149 commented 5 years ago

hmm... maybe 32-bit uses stdcall and 64-bit doesn't, either way I'll add it, thanks for the report

Francesco149 commented 5 years ago

according to msdn

On ARM and x64 processors, __stdcall is accepted and ignored by the compiler; on ARM and x64 architectures, by convention, arguments are passed in registers when possible, and subsequent arguments are passed on the stack.

well, I'm gonna go do some tests with a 64-bit c# project, sec...

MikiraSora commented 5 years ago

I just use VS x86 command promto and open libbuild.dat directly.

BTW , I suggest you have better make a function named ApplyChanged() so that PP and others will be changed after ACC/n100/n50 were changed.

Because I found that the pp doesnt automatic changed when acc are changed until I have to call ezpp()/ezpp_data() again. It's disturbing > <

Francesco149 commented 5 years ago

yea it's normal that you have to re-call ezpp/ezpp_data, it's fine, it caches results and doesn't re-parse the map if not necessary

good idea though, I could make a switch that automatically recalcs when you change parameters

Francesco149 commented 5 years ago

hmm i just wrote and compiled a test c# program and it works for both the 32-bit and 64-bit dll without specifying cdecl. could you try using the dll's from x86 or x64 binaries here: https://github.com/Francesco149/oppai-ng/releases ? also I will try adding -Gz to libbuild.bat to ensure stdcall is forced on 32-bit, you can try this too

Francesco149 commented 5 years ago

I have modified libbuild to force __stdcall, see if that works when you build the dll yourself

MikiraSora commented 5 years ago

this is from latest x86 release and it actually throw exception: image this is x64 release but it throw another exception: image

MikiraSora commented 5 years ago

you can clone&run console proj in this repo

Francesco149 commented 5 years ago

that's because you are using x64 dll on x86 or viceversa

if you compile for 32-bit (x86) you need x86 dll. if you compile for 64bit (x64) you need x64 dll

MikiraSora commented 5 years ago

yep , I pulled master branch just now and compile right x86/stdcall dll file successfully. thank you :D

In your rtpp PR ,we have to updated other plugins which depend oppai and then merge your pr for test. I think I could close this issue.

Francesco149 commented 5 years ago

btw i just added the autocalc thing, try ezpp_set_autocalc(ez, 1);