diff --git a/src/Command.mm b/src/Command.mm index e6709e8..ad4194f 100644 --- a/src/Command.mm +++ b/src/Command.mm @@ -46,48 +46,34 @@ ((void(__cdecl *)())_function)(); break; case ARG_1STR: - if (isDown) { - @autoreleasepool { - ((void(__cdecl *)(OFString *))_function)( - @(arguments[1])); - } - } + if (isDown) + ((void(__cdecl *)(OFString *))_function)( + @(arguments[1])); break; case ARG_2STR: - if (isDown) { - @autoreleasepool { - ((void(__cdecl *)( - OFString *, OFString *))_function)( - @(arguments[1]), @(arguments[2])); - } - } + if (isDown) + ((void(__cdecl *)(OFString *, OFString *))_function)( + @(arguments[1]), @(arguments[2])); break; case ARG_3STR: - if (isDown) { - @autoreleasepool { - ((void(__cdecl *)(OFString *, OFString *, - OFString *))_function)(@(arguments[1]), - @(arguments[2]), @(arguments[3])); - } - } + if (isDown) + ((void(__cdecl *)( + OFString *, OFString *, OFString *))_function)( + @(arguments[1]), @(arguments[2]), @(arguments[3])); break; case ARG_5STR: - if (isDown) { - @autoreleasepool { - ((void(__cdecl *)(OFString *, OFString *, - OFString *, OFString *, - OFString *))_function)(@(arguments[1]), - @(arguments[2]), @(arguments[3]), - @(arguments[4]), @(arguments[5])); - } - } + if (isDown) + ((void(__cdecl *)(OFString *, OFString *, OFString *, + OFString *, OFString *))_function)(@(arguments[1]), + @(arguments[2]), @(arguments[3]), @(arguments[4]), + @(arguments[5])); break; case ARG_DOWN: ((void(__cdecl *)(bool))_function)(isDown); break; case ARG_DWN1: - ((void(__cdecl *)(bool, char *))_function)( - isDown, arguments[1]); + ((void(__cdecl *)(bool, OFString *))_function)( + isDown, @(arguments[1])); break; case ARG_1EXP: if (isDown) @@ -101,13 +87,14 @@ break; case ARG_1EST: if (isDown) - return ((int(__cdecl *)(char *))_function)( - arguments[1]); + return ((int(__cdecl *)(OFString *))_function)( + @(arguments[1])); break; case ARG_2EST: if (isDown) - return ((int(__cdecl *)(char *, char *))_function)( - arguments[1], arguments[2]); + return ( + (int(__cdecl *)(OFString *, OFString *))_function)( + @(arguments[1]), @(arguments[2])); break; case ARG_VARI: if (isDown) { @@ -121,7 +108,7 @@ break; strcat_s(r, " "); } - ((void(__cdecl *)(char *))_function)(r); + ((void(__cdecl *)(OFString *))_function)(@(r)); } break; } diff --git a/src/client.mm b/src/client.mm index 1790aac..daa17ec 100644 --- a/src/client.mm +++ b/src/client.mm @@ -166,16 +166,18 @@ trydisconnect() string ctext; void -toserver(const char *text) +toserver(OFString *text) { - conoutf(@"%s:\f %s", player1->name, text); - strn0cpy(ctext, text, 80); + @autoreleasepool { + conoutf(@"%s:\f %@", player1->name, text); + strn0cpy(ctext, text.UTF8String, 80); + } } void -echo(char *text) +echo(OFString *text) { - conoutf(@"%s", text); + conoutf(@"%@", text); } COMMAND(echo, ARG_VARI) diff --git a/src/clientextras.mm b/src/clientextras.mm index af1bd2d..3f3b568 100644 --- a/src/clientextras.mm +++ b/src/clientextras.mm @@ -204,9 +204,10 @@ sendmap(OFString *mapname) enet_packet_resize(packet, p - start); sendpackettoserv(packet); conoutf(@"sending map %@ to server...", mapname); - sprintf_sd(msg)( - "[map %@ uploaded to server, \"getmap\" to receive it]", - mapname); + OFString *msg = + [OFString stringWithFormat:@"[map %@ uploaded to server, " + @"\"getmap\" to receive it]", + mapname]; toserver(msg); } } diff --git a/src/commands.mm b/src/commands.mm index 3c4fd7d..9deae9b 100644 --- a/src/commands.mm +++ b/src/commands.mm @@ -463,39 +463,48 @@ whilea(OFString *cond_, OFString *body_) } void -onrelease(bool on, char *body) +onrelease(bool on, OFString *body) { - if (!on) - execute(body); -} - -void -concat(char *s) -{ - @autoreleasepool { - alias(@"s", @(s)); + if (!on) { + std::unique_ptr copy(strdup(body.UTF8String)); + execute(copy.get()); } } void -concatword(char *s) +concat(OFString *s) { - for (char *a = s, *b = s; *a = *b; b++) - if (*a != ' ') - a++; + @autoreleasepool { + alias(@"s", s); + } +} + +void +concatword(OFString *s) +{ + // The original used this code which does nothing: + // for (char *a = s, *b = s; *a = *b; b++) + // if (*a != ' ') + // a++; concat(s); } int -listlen(char *a) +listlen(OFString *a_) { - if (!*a) - return 0; - int n = 0; - while (*a) - if (*a++ == ' ') - n++; - return n + 1; + @autoreleasepool { + const char *a = a_.UTF8String; + + if (!*a) + return 0; + + int n = 0; + while (*a) + if (*a++ == ' ') + n++; + + return n + 1; + } } void @@ -508,7 +517,7 @@ at(OFString *s_, OFString *pos) loopi(n) s += strspn(s += strcspn(s, " \0"), " "); s[strcspn(s, " \0")] = 0; - concat(s); + concat(@(s)); } } @@ -579,9 +588,9 @@ gt(int a, int b) COMMANDN(>, gt, ARG_2EXP) int -strcmpa(char *a, char *b) +strcmpa(OFString *a, OFString *b) { - return strcmp(a, b) == 0; + return [a isEqual:b]; } COMMANDN(strcmp, strcmpa, ARG_2EST) diff --git a/src/console.mm b/src/console.mm index c48b11d..7b659db 100644 --- a/src/console.mm +++ b/src/console.mm @@ -128,9 +128,9 @@ bindkey(OFString *key, OFString *action) COMMANDN(bind, bindkey, ARG_2STR) void -saycommand(const char *init) // turns input to the command line on or off +saycommand(OFString *init) // turns input to the command line on or off { - saycommandon = (init != NULL); + saycommandon = (init != nil); if (saycommandon) SDL_StartTextInput(); else @@ -139,10 +139,10 @@ saycommand(const char *init) // turns input to the command line on or off if (!editmode) Cube.sharedInstance.repeatsKeys = saycommandon; - if (!init) - init = ""; + if (init == nil) + init = @""; - commandbuf = [[OFMutableString alloc] initWithUTF8String:init]; + commandbuf = [init mutableCopy]; } COMMAND(saycommand, ARG_VARI) @@ -255,7 +255,7 @@ keypress(int code, bool isdown, int cooked) commandbuf.UTF8String)); execute(copy.get(), true); } else - toserver(commandbuf.UTF8String); + toserver(commandbuf); } saycommand(NULL); } else if (code == SDLK_ESCAPE) { diff --git a/src/protos.h b/src/protos.h index a4ce99e..298e078 100644 --- a/src/protos.h +++ b/src/protos.h @@ -71,7 +71,7 @@ extern void setarraypointers(); extern void localservertoclient(uchar *buf, int len); extern void connects(OFString *servername); extern void disconnect(int onlyclean = 0, int async = 0); -extern void toserver(const char *text); +extern void toserver(OFString *text); extern void addmsg(int rel, int num, int type, ...); extern bool multiplayer(); extern bool allowedittoggle(); diff --git a/src/sound.mm b/src/sound.mm index 6e77f0d..482727c 100644 --- a/src/sound.mm +++ b/src/sound.mm @@ -131,26 +131,23 @@ vector samples; static OFMutableArray *snames; int -registersound(char *name_) +registersound(OFString *name) { - @autoreleasepool { - OFString *name = @(name_); + int i = 0; + for (OFString *iter in snames) { + if ([iter isEqual:name]) + return i; - int i = 0; - for (OFString *iter in snames) { - if ([iter isEqual:name]) - return i; - - i++; - } - - if (snames == nil) - snames = [[OFMutableArray alloc] init]; - - [snames addObject:name]; - samples.add(NULL); - return samples.length() - 1; + i++; } + + if (snames == nil) + snames = [[OFMutableArray alloc] init]; + + [snames addObject:name]; + samples.add(NULL); + + return samples.length() - 1; } COMMAND(registersound, ARG_1EST)