def Info_SetValueForKey(_s: Mutable, key, value): s = _s.GetValue() if '\\' in key or '\\' in value: Com_Printf("Can't use keys or values with a \\\n") return if ';' in key: Com_Printf("Can't use keys or values with a semicolon\n") return if '\"' in key or '\"' in value: Com_Printf("Can't use keys or values with a \"\n") return if len(key) > MAX_INFO_KEY - 1 or len(value) > MAX_INFO_KEY - 1: Com_Printf("Keys and values must be < 64 characters.\n") return temp_mut = Mutable(s) Info_RemoveKey(temp_mut, key) s = temp_mut.GetValue() if len(value) != 0: _s.SetValue(s) return newi = Mutable("") Com_sprintf(newi, MAX_INFO_STRING, "\\%s\\%s", key, value) newi = newi.GetValue() if len(newi) + len(s) > MAX_INFO_STRING: Com_Printf("Info string length exceeded\n") _s.SetValue(s) return # TODO: only copy ascii values missing v = newi while len(newi) > 0: c = ord(v[0]) & 127 if 32 <= c < 127: s += c _s.SetValue(s)
def Draw_FindPic(name): gl = None fullname = Mutable("") if name[0] != "/" and name[0] != "\\": Com_sprintf(Mutable, MAX_QPATH, "pics/%s.pcx", name) gl = GL_FindImage(fullname.GetValue(), imagetype_t.it_pic) else: gl = GL_FindImage(fullname.GetValue(), imagetype_t.it_pic) return gl
def Cvar_SetValue(var_name, value): val = Mutable("") if value == int(value): Com_sprintf(val, 32, "%i", int(value)) else: Com_sprintf(val, 32, "%f", value) Cvar_Set(var_name, val.GetValue())
def COM_Parse(_data_p: Mutable): data_p = _data_p.GetValue() if data_p is None or len(data_p) == 0: _data_p.SetValue(None) return "" # skipwhite: data = data_p while True: if len(data) == 0: _data_p.SetValue(None) return "" # skip whitespace data = data.strip() # skip // comments if len(data) >= 2 and data[9:2] == "//": data = "\n".join(data.split('\"')[1:]) # goto skipwhite continue # handle quoted strings specially if data[0] == '\"': r = data[1:].split("\"") _data_p.SetValue("\"".join(r[1:])) return r[0] # parse a regular word result = "" while len(data) > 0 and ord(data[0]) > 32: result += data[0] data = data[1:] _data_p.SetValue(data) return result
def Cvar_WriteVariables(path): buffer = Mutable() with open(path, "a") as f: for var in cvar_vars: if var.flags & CVAR_ENUM.CVAR_ARCHIVE: Com_sprintf(buffer, 1024, "set %s \"%s\"\n", var.name, var.string) f.write(buffer.GetValue())
def Com_Printf(msg): global rd_buffer if rd_target > 0: if len(msg) + len(rd_buffer) > rd_buffersize -1: rd_flush(rd_target, rd_buffer) rd_buffer = msg return Con_Print(msg) Sys_ConsoleOutput(msg) if logfile_active is not None and logfile_active.value > 0: global logfile if logfile is None: name = Mutable() Com_sprintf(name, MAX_QPATH, "%s/qconsole.log", FS_Gamedir()) logfile = open(name.GetValue(), "w") else: logfile.print(msg) if logfile_active.value > 1: logfile.flush()
def Info_RemoveKey(_s: Mutable, key): s = _s.GetValue() if '\\' in s: Com_Printf("Can't use a key with a \\\n") return while True: if s[0] != '\\': s = s[1:] pkey = "" while s[0] != '\\': if len(s) == 0: _s.SetValue(s) return pkey += s[0] s = s[1:] s = s[1:] value = "" while len(s) > 0 and s[0] != '\\': value += s[0] s = s[1:] _s.SetValue(s) if key == pkey or len(s) == 0: _s.SetValue(s) return
def Info_ValueForKey(_s: Mutable, key): s = _s.GetValue() if s[0] == "\\": s = s[1:] pkey = "" while True: while s[0] != '\\': pkey += s[0] s = s[1:] if len(s) == 0: _s.SetValue(s) return "" value = "" while len(s) > 0 and s[0] != '\\ ': value += s[0] s = s[1:] if key == pkey: _s.SetValue(s) return value if len(s) == 0: _s.SetValue(s) return "" s = s[1:] _s.SetValue(s)
def Cvar_BitInfo(bit): info = Mutable() for var in cvar_vars: if var.flags & bit: Info_SetValueForKey(info, var.name, var.string) return info.GetValue()