initial tests
This commit is contained in:
26
examples/FFI.cs
Normal file
26
examples/FFI.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// csc FFI.cs
|
||||
// FFI.exe /path/to/file.osu
|
||||
// make sure oppai.dll is in the same directory as FFI.exe
|
||||
// see oppai.c for a full list of functions
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Program
|
||||
{
|
||||
[DllImport(@"oppai.dll")]
|
||||
public static extern IntPtr ezpp_new();
|
||||
|
||||
[DllImport(@"oppai.dll")]
|
||||
public static extern IntPtr ezpp(IntPtr ez, char[] map);
|
||||
|
||||
[DllImport(@"oppai.dll")]
|
||||
public static extern float ezpp_pp(IntPtr ez);
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
IntPtr ez = ezpp_new();
|
||||
ezpp(ez, args[0].ToCharArray());
|
||||
Console.WriteLine($"{ezpp_pp(ez)} pp");
|
||||
}
|
||||
}
|
133
examples/binary.c
Normal file
133
examples/binary.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* example of parsing oppai's binary output
|
||||
*
|
||||
* gcc binary.c
|
||||
* oppai /path/to/file.osu -obinary | ./a.out
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* these are only necessary to ensure endian-ness, if you don't
|
||||
* care about that you can read values like v = *(int*)p
|
||||
*/
|
||||
|
||||
int read2(char** c) {
|
||||
unsigned char* p = (unsigned char*)*c;
|
||||
*c += 2;
|
||||
return p[0] | (p[1] << 8);
|
||||
}
|
||||
|
||||
int read4(char** c) {
|
||||
unsigned char* p = (unsigned char*)*c;
|
||||
*c += 4;
|
||||
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
||||
}
|
||||
|
||||
float read_flt(char** p) {
|
||||
int v = read4(p);
|
||||
float* pf = (float*)&v;
|
||||
return *pf;
|
||||
}
|
||||
|
||||
char* read_str(char** p, int* len) {
|
||||
char* res;
|
||||
*len = read2(p);
|
||||
res = *p;
|
||||
*p += *len + 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
#define MODS_NF (1<<0)
|
||||
#define MODS_EZ (1<<1)
|
||||
#define MODS_HD (1<<3)
|
||||
#define MODS_HR (1<<4)
|
||||
#define MODS_DT (1<<6)
|
||||
#define MODS_HT (1<<8)
|
||||
#define MODS_NC (1<<9)
|
||||
#define MODS_FL (1<<10)
|
||||
#define MODS_SO (1<<12)
|
||||
|
||||
int main() {
|
||||
char buf[8192];
|
||||
char* p = buf;
|
||||
int len;
|
||||
int result;
|
||||
int mods;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
/* read stdin in binary mode */
|
||||
if (!freopen(0, "rb", stdin)) {
|
||||
perror("freopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!fread(buf, 1, sizeof(buf), stdin)) {
|
||||
perror("fread");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strncmp((char const*)p, "binoppai", 8)) {
|
||||
puts("invalid input");
|
||||
return 1;
|
||||
}
|
||||
p += 8;
|
||||
|
||||
printf("oppai %d.%d.%d\n", p[0], p[1], p[2]);
|
||||
p += 3;
|
||||
puts("");
|
||||
|
||||
/* error code */
|
||||
result = read4(&p);
|
||||
if (result < 0) {
|
||||
printf("error %d\n", result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("artist: %s\n", read_str(&p, &len));
|
||||
printf("artist_unicode: %s\n", read_str(&p, &len));
|
||||
printf("title: %s\n", read_str(&p, &len));
|
||||
printf("title_unicode: %s\n", read_str(&p, &len));
|
||||
printf("version: %s\n", read_str(&p, &len));
|
||||
printf("creator: %s\n", read_str(&p, &len));
|
||||
|
||||
mods = read4(&p);
|
||||
puts("");
|
||||
printf("mods: ");
|
||||
if (mods & MODS_NF) printf("NF");
|
||||
if (mods & MODS_EZ) printf("EZ");
|
||||
if (mods & MODS_HD) printf("HD");
|
||||
if (mods & MODS_HR) printf("HR");
|
||||
if (mods & MODS_DT) printf("DT");
|
||||
if (mods & MODS_HT) printf("HT");
|
||||
if (mods & MODS_NC) printf("NC");
|
||||
if (mods & MODS_FL) printf("FL");
|
||||
if (mods & MODS_SO) printf("SO");
|
||||
puts("");
|
||||
|
||||
printf("OD%g ", read_flt(&p));
|
||||
printf("AR%g ", read_flt(&p));
|
||||
printf("CS%g ", read_flt(&p));
|
||||
printf("HP%g\n", read_flt(&p));
|
||||
printf("%d/%dx\n", read4(&p), read4(&p));
|
||||
printf("%d circles ", read2(&p));
|
||||
printf("%d sliders ", read2(&p));
|
||||
printf("%d spinners\n", read2(&p));
|
||||
printf("scorev%d\n", read4(&p));
|
||||
puts("");
|
||||
printf("%g stars ", read_flt(&p));
|
||||
printf("(%g speed, ", read_flt(&p));
|
||||
printf("%g aim)\n", read_flt(&p));
|
||||
read2(&p); /* legacy */
|
||||
read2(&p); /* legacy */
|
||||
puts("");
|
||||
printf("%g aim pp\n", read_flt(&p));
|
||||
printf("%g speed pp\n", read_flt(&p));
|
||||
printf("%g acc pp\n", read_flt(&p));
|
||||
puts("");
|
||||
printf("%g pp\n", read_flt(&p));
|
||||
|
||||
return 0;
|
||||
}
|
16
examples/min.c
Normal file
16
examples/min.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* gcc min.c -lm
|
||||
* cat /path/to/file.osu | ./a.out
|
||||
*/
|
||||
|
||||
#define OPPAI_IMPLEMENTATION
|
||||
#include "../oppai.c"
|
||||
|
||||
int main() {
|
||||
ezpp_t ez = ezpp_new();
|
||||
ezpp_set_mods(ez, MODS_HD | MODS_DT);
|
||||
ezpp(ez, "-");
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
return 0;
|
||||
}
|
||||
|
61
examples/reuse.c
Normal file
61
examples/reuse.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* gcc reuse.c -lm
|
||||
* ./a.out /path/to/file.osu
|
||||
*/
|
||||
|
||||
#define OPPAI_IMPLEMENTATION
|
||||
#include "../oppai.c"
|
||||
|
||||
/*
|
||||
* for better performance, the same instance can be reused
|
||||
* settings are remembered and map is only reparsed if mods or cs change
|
||||
*/
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
ezpp_t ez = ezpp_new();
|
||||
ezpp_set_autocalc(ez, 1); /* autorecalc pp when changing any parameter */
|
||||
ezpp(ez, argv[1]);
|
||||
|
||||
puts("---");
|
||||
puts("nomod fc");
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("nomod 95% fc");
|
||||
ezpp_set_accuracy_percent(ez, 95);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("nomod 1x100 fc");
|
||||
ezpp_set_accuracy(ez, 1, 0);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("HD 1x100 1miss 300x");
|
||||
ezpp_set_mods(ez, MODS_HD);
|
||||
ezpp_set_nmiss(ez, 1);
|
||||
ezpp_set_combo(ez, 300);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("HDDT 1x100 1xmiss 300x");
|
||||
ezpp_set_mods(ez, MODS_HD | MODS_DT);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("HDDT 1x100 1xmiss 300x ends at object 300");
|
||||
ezpp_set_end(ez, 300);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
puts("HDDT fc");
|
||||
ezpp_set_end(ez, 0);
|
||||
ezpp_set_combo(ez, -1);
|
||||
ezpp_set_accuracy(ez, 0, 0);
|
||||
ezpp_set_nmiss(ez, 0);
|
||||
printf("%gpp\n", ezpp_pp(ez));
|
||||
puts("---");
|
||||
|
||||
ezpp_free(ez);
|
||||
return 0;
|
||||
}
|
42
examples/reuse_mem.c
Normal file
42
examples/reuse_mem.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#define OPPAI_IMPLEMENTATION
|
||||
#include "oppai.c"
|
||||
|
||||
char buf[1000000];
|
||||
int mods[] = { 0, MODS_HR, MODS_HD | MODS_HR, MODS_DT, MODS_HD | MODS_DT };
|
||||
#define N_MODS (sizeof(mods) / sizeof(mods[0]))
|
||||
|
||||
void print_mods(int mods) {
|
||||
putchar('+');
|
||||
if (!mods) puts("nomod");
|
||||
else {
|
||||
if (mods & MODS_HD) printf("hd");
|
||||
if (mods & MODS_HR) printf("hr");
|
||||
if (mods & MODS_DT) printf("dt");
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int i, j, n, acc;
|
||||
ezpp_t ez = ezpp_new();
|
||||
ezpp_set_autocalc(ez, 1);
|
||||
for (i = 1; i < argc; ++i) {
|
||||
FILE* f = fopen(argv[i], "r");
|
||||
n = fread(buf, 1, sizeof(buf), f);
|
||||
fclose(f);
|
||||
ezpp_data(ez, buf, n);
|
||||
printf("%s - %s [%s]\n", ezpp_artist(ez), ezpp_title(ez),
|
||||
ezpp_version(ez));
|
||||
for (j = 0; j < N_MODS; ++j) {
|
||||
print_mods(mods[j]);
|
||||
ezpp_set_mods(ez, mods[j]);
|
||||
for (acc = 95; acc <= 100; ++acc) {
|
||||
ezpp_set_accuracy_percent(ez, acc);
|
||||
printf("%d%% -> %gpp\n", acc, ezpp_pp(ez));
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
ezpp_free(ez);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user