Migrate strings for all commands

FossilOrigin-Name: 11889bf242c1346514823c710dcf369bebc7339b24399f2c6369b146c644996c
This commit is contained in:
Jonathan Schleifer 2025-03-07 22:30:15 +00:00
parent 63a6c72954
commit 039efe612d
7 changed files with 89 additions and 93 deletions

View file

@ -46,48 +46,34 @@
((void(__cdecl *)())_function)(); ((void(__cdecl *)())_function)();
break; break;
case ARG_1STR: case ARG_1STR:
if (isDown) { if (isDown)
@autoreleasepool { ((void(__cdecl *)(OFString *))_function)(
((void(__cdecl *)(OFString *))_function)( @(arguments[1]));
@(arguments[1]));
}
}
break; break;
case ARG_2STR: case ARG_2STR:
if (isDown) { if (isDown)
@autoreleasepool { ((void(__cdecl *)(OFString *, OFString *))_function)(
((void(__cdecl *)( @(arguments[1]), @(arguments[2]));
OFString *, OFString *))_function)(
@(arguments[1]), @(arguments[2]));
}
}
break; break;
case ARG_3STR: case ARG_3STR:
if (isDown) { if (isDown)
@autoreleasepool { ((void(__cdecl *)(
((void(__cdecl *)(OFString *, OFString *, OFString *, OFString *, OFString *))_function)(
OFString *))_function)(@(arguments[1]), @(arguments[1]), @(arguments[2]), @(arguments[3]));
@(arguments[2]), @(arguments[3]));
}
}
break; break;
case ARG_5STR: case ARG_5STR:
if (isDown) { if (isDown)
@autoreleasepool { ((void(__cdecl *)(OFString *, OFString *, OFString *,
((void(__cdecl *)(OFString *, OFString *, OFString *, OFString *))_function)(@(arguments[1]),
OFString *, OFString *, @(arguments[2]), @(arguments[3]), @(arguments[4]),
OFString *))_function)(@(arguments[1]), @(arguments[5]));
@(arguments[2]), @(arguments[3]),
@(arguments[4]), @(arguments[5]));
}
}
break; break;
case ARG_DOWN: case ARG_DOWN:
((void(__cdecl *)(bool))_function)(isDown); ((void(__cdecl *)(bool))_function)(isDown);
break; break;
case ARG_DWN1: case ARG_DWN1:
((void(__cdecl *)(bool, char *))_function)( ((void(__cdecl *)(bool, OFString *))_function)(
isDown, arguments[1]); isDown, @(arguments[1]));
break; break;
case ARG_1EXP: case ARG_1EXP:
if (isDown) if (isDown)
@ -101,13 +87,14 @@
break; break;
case ARG_1EST: case ARG_1EST:
if (isDown) if (isDown)
return ((int(__cdecl *)(char *))_function)( return ((int(__cdecl *)(OFString *))_function)(
arguments[1]); @(arguments[1]));
break; break;
case ARG_2EST: case ARG_2EST:
if (isDown) if (isDown)
return ((int(__cdecl *)(char *, char *))_function)( return (
arguments[1], arguments[2]); (int(__cdecl *)(OFString *, OFString *))_function)(
@(arguments[1]), @(arguments[2]));
break; break;
case ARG_VARI: case ARG_VARI:
if (isDown) { if (isDown) {
@ -121,7 +108,7 @@
break; break;
strcat_s(r, " "); strcat_s(r, " ");
} }
((void(__cdecl *)(char *))_function)(r); ((void(__cdecl *)(OFString *))_function)(@(r));
} }
break; break;
} }

View file

@ -166,16 +166,18 @@ trydisconnect()
string ctext; string ctext;
void void
toserver(const char *text) toserver(OFString *text)
{ {
conoutf(@"%s:\f %s", player1->name, text); @autoreleasepool {
strn0cpy(ctext, text, 80); conoutf(@"%s:\f %@", player1->name, text);
strn0cpy(ctext, text.UTF8String, 80);
}
} }
void void
echo(char *text) echo(OFString *text)
{ {
conoutf(@"%s", text); conoutf(@"%@", text);
} }
COMMAND(echo, ARG_VARI) COMMAND(echo, ARG_VARI)

View file

@ -204,9 +204,10 @@ sendmap(OFString *mapname)
enet_packet_resize(packet, p - start); enet_packet_resize(packet, p - start);
sendpackettoserv(packet); sendpackettoserv(packet);
conoutf(@"sending map %@ to server...", mapname); conoutf(@"sending map %@ to server...", mapname);
sprintf_sd(msg)( OFString *msg =
"[map %@ uploaded to server, \"getmap\" to receive it]", [OFString stringWithFormat:@"[map %@ uploaded to server, "
mapname); @"\"getmap\" to receive it]",
mapname];
toserver(msg); toserver(msg);
} }
} }

View file

@ -463,39 +463,48 @@ whilea(OFString *cond_, OFString *body_)
} }
void void
onrelease(bool on, char *body) onrelease(bool on, OFString *body)
{ {
if (!on) if (!on) {
execute(body); std::unique_ptr<char> copy(strdup(body.UTF8String));
} execute(copy.get());
void
concat(char *s)
{
@autoreleasepool {
alias(@"s", @(s));
} }
} }
void void
concatword(char *s) concat(OFString *s)
{ {
for (char *a = s, *b = s; *a = *b; b++) @autoreleasepool {
if (*a != ' ') alias(@"s", s);
a++; }
}
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); concat(s);
} }
int int
listlen(char *a) listlen(OFString *a_)
{ {
if (!*a) @autoreleasepool {
return 0; const char *a = a_.UTF8String;
int n = 0;
while (*a) if (!*a)
if (*a++ == ' ') return 0;
n++;
return n + 1; int n = 0;
while (*a)
if (*a++ == ' ')
n++;
return n + 1;
}
} }
void void
@ -508,7 +517,7 @@ at(OFString *s_, OFString *pos)
loopi(n) s += strspn(s += strcspn(s, " \0"), " "); loopi(n) s += strspn(s += strcspn(s, " \0"), " ");
s[strcspn(s, " \0")] = 0; s[strcspn(s, " \0")] = 0;
concat(s); concat(@(s));
} }
} }
@ -579,9 +588,9 @@ gt(int a, int b)
COMMANDN(>, gt, ARG_2EXP) COMMANDN(>, gt, ARG_2EXP)
int 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) COMMANDN(strcmp, strcmpa, ARG_2EST)

View file

@ -128,9 +128,9 @@ bindkey(OFString *key, OFString *action)
COMMANDN(bind, bindkey, ARG_2STR) COMMANDN(bind, bindkey, ARG_2STR)
void 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) if (saycommandon)
SDL_StartTextInput(); SDL_StartTextInput();
else else
@ -139,10 +139,10 @@ saycommand(const char *init) // turns input to the command line on or off
if (!editmode) if (!editmode)
Cube.sharedInstance.repeatsKeys = saycommandon; Cube.sharedInstance.repeatsKeys = saycommandon;
if (!init) if (init == nil)
init = ""; init = @"";
commandbuf = [[OFMutableString alloc] initWithUTF8String:init]; commandbuf = [init mutableCopy];
} }
COMMAND(saycommand, ARG_VARI) COMMAND(saycommand, ARG_VARI)
@ -255,7 +255,7 @@ keypress(int code, bool isdown, int cooked)
commandbuf.UTF8String)); commandbuf.UTF8String));
execute(copy.get(), true); execute(copy.get(), true);
} else } else
toserver(commandbuf.UTF8String); toserver(commandbuf);
} }
saycommand(NULL); saycommand(NULL);
} else if (code == SDLK_ESCAPE) { } else if (code == SDLK_ESCAPE) {

View file

@ -71,7 +71,7 @@ extern void setarraypointers();
extern void localservertoclient(uchar *buf, int len); extern void localservertoclient(uchar *buf, int len);
extern void connects(OFString *servername); extern void connects(OFString *servername);
extern void disconnect(int onlyclean = 0, int async = 0); 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 void addmsg(int rel, int num, int type, ...);
extern bool multiplayer(); extern bool multiplayer();
extern bool allowedittoggle(); extern bool allowedittoggle();

View file

@ -131,26 +131,23 @@ vector<FSOUND_SAMPLE *> samples;
static OFMutableArray<OFString *> *snames; static OFMutableArray<OFString *> *snames;
int int
registersound(char *name_) registersound(OFString *name)
{ {
@autoreleasepool { int i = 0;
OFString *name = @(name_); for (OFString *iter in snames) {
if ([iter isEqual:name])
return i;
int i = 0; i++;
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;
} }
if (snames == nil)
snames = [[OFMutableArray alloc] init];
[snames addObject:name];
samples.add(NULL);
return samples.length() - 1;
} }
COMMAND(registersound, ARG_1EST) COMMAND(registersound, ARG_1EST)