//------------------------------------------------------------------------- /* Copyright (C) 2016 EDuke32 developers and contributors This file is part of EDuke32. EDuke32 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- #include "duke3d.h" #include "scriplib.h" #include "osdcmds.h" #include "renderlayer.h" #include "cmdline.h" #ifdef __ANDROID__ # include "android.h" #endif #if defined RENDERTYPESDL && defined SDL_TARGET && SDL_TARGET > 1 # include "sdl_inc.h" #endif // we load this in to get default button and key assignments // as well as setting up function mappings #define __SETUP__ // JBF 20031211 #include "_functio.h" hashtable_t h_gamefuncs = { NUMGAMEFUNCTIONS<<1, NULL }; int32_t CONFIG_FunctionNameToNum(const char *func) { int32_t i; if (!func) return -1; i = hash_find(&h_gamefuncs,func); if (i < 0) { char *str = Bstrtolower(Xstrdup(func)); i = hash_find(&h_gamefuncs,str); Bfree(str); return i; } return i; } char *CONFIG_FunctionNumToName(int32_t func) { if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS) return NULL; return gamefunctions[func]; } int32_t CONFIG_AnalogNameToNum(const char *func) { if (!func) return -1; if (!Bstrcasecmp(func,"analog_turning")) { return analog_turning; } if (!Bstrcasecmp(func,"analog_strafing")) { return analog_strafing; } if (!Bstrcasecmp(func,"analog_moving")) { return analog_moving; } if (!Bstrcasecmp(func,"analog_lookingupanddown")) { return analog_lookingupanddown; } return -1; } const char *CONFIG_AnalogNumToName(int32_t func) { switch (func) { case analog_turning: return "analog_turning"; case analog_strafing: return "analog_strafing"; case analog_moving: return "analog_moving"; case analog_lookingupanddown: return "analog_lookingupanddown"; } return NULL; } void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN]) { Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); CONTROL_ClearAllBinds(); for (size_t i=0; i < ARRAY_SIZE(gamefunctions); ++i) { if (gamefunctions[i][0] == '\0') continue; ud.config.KeyboardKeys[i][0] = KB_StringToScanCode(keyptr[i<<1]); ud.config.KeyboardKeys[i][1] = KB_StringToScanCode(keyptr[(i<<1)+1]); if (i == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[i][0]); else CONFIG_MapKey(i, ud.config.KeyboardKeys[i][0], 0, ud.config.KeyboardKeys[i][1], 0); } } void CONFIG_SetDefaults(void) { // JBF 20031211 int32_t i; ud.config.scripthandle = -1; #ifdef __ANDROID__ droidinput.forward_sens = 5.f; droidinput.strafe_sens = 5.f; droidinput.pitch_sens = 5.f; droidinput.yaw_sens = 5.f; droidinput.hideStick = 0; droidinput.gameControlsAlpha = 0.5; droidinput.toggleCrouch = 1; droidinput.quickSelectWeapon = 1; ud.config.ScreenWidth = droidinfo.screen_width; ud.config.ScreenHeight = droidinfo.screen_height; #else # if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1 uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO); if (inited == 0) SDL_Init(SDL_INIT_VIDEO); else if (!(inited & SDL_INIT_VIDEO)) SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(0, &dm) == 0) { ud.config.ScreenWidth = dm.w; ud.config.ScreenHeight = dm.h; } else # endif { ud.config.ScreenWidth = 1024; ud.config.ScreenHeight = 768; } #endif ud.config.ScreenMode = 1; #ifdef USE_OPENGL ud.config.ScreenBPP = 32; #else ud.config.ScreenBPP = 8; #endif ud.config.useprecache = 1; ud.config.ForceSetup = 1; ud.config.NoAutoLoad = 1; ud.config.AmbienceToggle = 1; ud.config.AutoAim = 1; ud.config.FXVolume = 255; #if defined(_WIN32) ud.config.MixRate = 44100; #elif defined __ANDROID__ ud.config.MixRate = droidinfo.audio_sample_rate; #else ud.config.MixRate = 48000; #endif ud.config.MouseBias = 0; ud.config.MouseDeadZone = 0; ud.config.MusicToggle = 1; ud.config.MusicVolume = 195; g_myAimMode = g_player[0].ps->aim_mode = 1; ud.config.NumBits = 16; ud.config.NumChannels = 2; #if defined GEKKO || defined __OPENDINGUX__ ud.config.NumVoices = 32; #else ud.config.NumVoices = 64; #endif ud.config.ReverseStereo = 0; ud.auto_run = 1; ud.config.ShowOpponentWeapons = 0; ud.config.SmoothInput = 1; ud.config.SoundToggle = 1; ud.althud = 1; ud.automsg = 0; ud.autovote = 0; ud.brightness = 8; ud.camerasprite = -1; #if defined GEKKO || defined __OPENDINGUX__ ud.camera_time = 11; #elif defined(__ANDROID__) ud.camera_time = 7; #else ud.camera_time = 4; #endif ud.color = 0; ud.crosshair = 1; ud.crosshairscale = 50; ud.obituaries = 1; ud.democams = 1; ud.detail = 0; ud.drawweapon = 1; ud.idplayers = 1; ud.levelstats = 0; ud.lockout = 0; ud.m_ffire = 1; ud.m_marker = 1; ud.menu_slidebarz = 65536; ud.menu_slidebarmargin = RR ? 6 * 65536 : 65536; ud.menu_slidecursorz = RR ? 32768 : 65536; ud.mouseaiming = 0; ud.mouseflip = 1; ud.msgdisptime = 120; ud.pwlockout[0] = '\0'; ud.runkey_mode = 0; ud.screen_size = 4; ud.screen_tilting = 1; ud.shadows = 1; ud.statusbarflags = STATUSBAR_NOSHRINK; ud.statusbarmode = 1; ud.statusbarscale = 100; ud.team = 0; ud.viewbob = 1; ud.weaponsway = 1; ud.weaponswitch = 3; // new+empty ud.angleinterpolation = 0; #ifdef GEKKO ud.config.UseJoystick = 1; #else ud.config.UseJoystick = 0; #endif ud.config.UseMouse = 1; ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM ud.display_bonus_screen = 1; ud.show_level_text = 1; ud.configversion = 0; ud.weaponscale = 100; ud.textscale = 200; ud.screenfade = 1; ud.menubackground = 1; ud.hudontop = 0; ud.default_skill = 1; ud.slidebar_paldisabled = 1; ud.shadow_pal = 4; ud.menu_scrollbartilenum = -1; ud.menu_scrollbarz = 65536; ud.menu_scrollcursorz = 65536; ud.autosave = 1; ud.autosavedeletion = 1; ud.maxautosaves = 5; ud.config.CheckForUpdates = 1; Bstrcpy(ud.rtsname, G_DefaultRtsFile()); Bstrcpy(szPlayerName, "Player"); //if (RR) //{ // Bstrcpy(ud.ridecule[0], "Yer as ugly as a mud fence!"); // Bstrcpy(ud.ridecule[1], "Duck you pecker-head!"); // Bstrcpy(ud.ridecule[2], "You like that boy?"); // Bstrcpy(ud.ridecule[3], "Yer lower than catfish crap!"); // Bstrcpy(ud.ridecule[4], "Eat lead, you shit monkey!"); // Bstrcpy(ud.ridecule[5], "You dumb-ass!"); // Bstrcpy(ud.ridecule[6], "Yer slower'n a three legged dog!"); // Bstrcpy(ud.ridecule[7], "Come on...Squeal like a pig!"); // Bstrcpy(ud.ridecule[8], "Haw, haw, haw!"); // Bstrcpy(ud.ridecule[9], "Now you gone and done it!"); //} //else //{ Bstrcpy(ud.ridecule[0], "An inspiration for birth control."); Bstrcpy(ud.ridecule[1], "You're gonna die for that!"); Bstrcpy(ud.ridecule[2], "It hurts to be you."); Bstrcpy(ud.ridecule[3], "Lucky son of a bitch."); Bstrcpy(ud.ridecule[4], "Hmmm... payback time."); Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker."); Bstrcpy(ud.ridecule[6], "Damn, you're ugly."); Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!"); Bstrcpy(ud.ridecule[8], "You suck!"); Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!"); //} // JBF 20031211 if (RR) { Bstrcpy((char*)keydefaults[gamefunc_Holo_Duke<<1], "B"); Bstrcpy((char*)keydefaults[gamefunc_Jetpack<<1], "C"); Bstrcpy((char*)keydefaults[gamefunc_NightVision<<1], "Y"); Bstrcpy((char*)keydefaults[gamefunc_MedKit<<1], "R"); Bstrcpy((char*)keydefaults[gamefunc_Steroids<<1], "M"); Bstrcpy((char*)keydefaults[gamefunc_Show_Opponents_Weapon<<1], "V"); Bstrcpy((char*)oldkeydefaults[gamefunc_Holo_Duke<<1], "B"); Bstrcpy((char*)oldkeydefaults[gamefunc_Jetpack<<1], "C"); Bstrcpy((char*)oldkeydefaults[gamefunc_NightVision<<1], "Y"); Bstrcpy((char*)oldkeydefaults[gamefunc_MedKit<<1], "W"); Bstrcpy((char*)oldkeydefaults[gamefunc_Steroids<<1], "M"); Bstrcpy((char*)oldkeydefaults[gamefunc_Show_Opponents_Weapon<<1], "E"); Bstrcpy((char*)oldkeydefaults[gamefunc_Show_Console<<1], "V"); } CONFIG_SetDefaultKeys(keydefaults); memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions)); for (i=0; i=4) continue; ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]); CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse); } memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions)); for (i=0; i=0; i--) { if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k]) { Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i)); Bstrcat(tempbuf,buf); } } i = Bstrlen(tempbuf); if (i >= 2) { tempbuf[i-2] = 0; // cut off the trailing "; " CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : ""); } else { CONTROL_FreeKeyBind(ii[k]); } } } void CONFIG_SetupMouse(void) { int32_t i; char str[80]; char temp[80]; int32_t scale; if (ud.config.scripthandle < 0) return; for (i=0; i 10) tempbuf[Bstrlen(tempbuf) - 1] = '\0'; Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName)); SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.config.ForceSetup); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.config.NoAutoLoad); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &dummy); if (dummy > MAXCACHE1DSIZE) MAXCACHE1DSIZE = dummy; if (g_noSetup == 0 && g_modDir[0] == '/') { struct Bstat st; SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]); if (Bstat(g_modDir, &st)) { if ((st.st_mode & S_IFDIR) != S_IFDIR) { initprintf("Invalid mod dir in cfg!\n"); Bsprintf(g_modDir,"/"); } } } if (g_grpNamePtr == NULL && g_addonNum == 0) { SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr); if (g_grpNamePtr && !Bstrlen(g_grpNamePtr)) g_grpNamePtr = dup_filename(G_DefaultGrpFile()); } SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout); SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos); windowx = -1; windowy = -1; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP); if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32; #ifdef POLYMER SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy); if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER; else glrendmode = REND_POLYMOST; #endif SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions); #ifdef _WIN32 SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates); SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck); #endif ud.config.setupread = 1; return 0; } void CONFIG_WriteSettings(void) // save binds and aliases to _settings.cfg { int32_t i; BFILE *fp; char *ptr = Xstrdup(g_setupFileName); char tempbuf[128]; if (!Bstrcmp(g_setupFileName, SETUPFILENAME)) Bsprintf(tempbuf, "settings.cfg"); else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, ".")); fp = Bfopen(tempbuf, "wt"); if (fp) { Bfprintf(fp,"// this file is automatically generated by %s\n", AppProperName); Bfprintf(fp,"unbindall\n"); for (i=0; i= (MAXMOUSEBUTTONS-2)) continue; if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1])) { Bsprintf(buf, "MouseButtonClicked%d", dummy); SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1])); } } for (dummy=0; dummy