DEADSOFTWARE

allow resources in non current directory (warning: res downloader are broken)
[d2df-sdl.git] / src / game / g_console.pas
index 4141f27aeb4b6f66d7f2809559ec52fa42c7e184..6b8ddc82c2538e53156457e687d7e2a0fa1ae1c5 100644 (file)
@@ -86,9 +86,13 @@ implementation
 
 uses
   g_textures, g_main, e_graphics, e_input, g_game,
-  SysUtils, g_basic, g_options, Math, g_touch,
+  SysUtils, g_basic, g_options, Math, g_touch, e_res,
   g_menu, g_gui, g_language, g_net, g_netmsg, e_log, conbuf;
 
+const
+  configScript = 'dfconfig.cfg';
+  autoexecScript = 'autoexec.cfg';
+  configComment = 'generated by doom2d, do not modify';
 
 type
   PCommand = ^TCommand;
@@ -580,7 +584,7 @@ begin
   begin
     // exec <filename>
     if Length(p) = 2 then
-      g_Console_ReadConfig(GameDir + '/' + p[1])
+      g_Console_ReadConfig(p[1])
     else
       g_Console_Add('exec <script file>');
   end;
@@ -589,9 +593,14 @@ begin
   begin
     // writeconfig <filename>
     if Length(p) = 2 then
-      g_Console_WriteConfig(GameDir + '/' + p[1])
+    begin
+      s := e_GetDir(ConfigDirs);
+      g_Console_WriteConfig(e_CatPath(s, p[1]))
+    end
     else
-      g_Console_Add('writeconfig <file>');
+    begin
+      g_Console_Add('writeconfig <file>')
+    end
   end;
 
   if (cmd = 'ver') or (cmd = 'version') then
@@ -1015,8 +1024,8 @@ begin
   WhitelistCommand('g_timelimit');
 
   g_Console_ResetBinds;
-  g_Console_ReadConfig(GameDir + '/dfconfig.cfg');
-  g_Console_ReadConfig(GameDir + '/autoexec.cfg');
+  g_Console_ReadConfig(configScript);
+  g_Console_ReadConfig(autoexecScript);
   gParsingBinds := False;
 end;
 
@@ -1881,8 +1890,10 @@ end;
 procedure g_Console_ReadConfig (filename: String);
   var f: TextFile; s: AnsiString; i, len: Integer;
 begin
-  if FileExists(filename) then
+  e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename]);
+  if e_FindResource(ConfigDirs, filename, false) = true then
   begin
+    e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename]);
     AssignFile(f, filename);
     Reset(f);
     while not EOF(f) do
@@ -1908,7 +1919,7 @@ procedure g_Console_WriteConfig (filename: String);
 begin
   AssignFile(f, filename);
   Rewrite(f);
-  WriteLn(f, '// generated by doom2d, do not modify');
+  WriteLn(f, '// ' + configComment);
   WriteLn(f, 'unbindall');
   for i := 0 to e_MaxInputKeys - 1 do
     if (Length(gInputBinds[i].down) > 0) or (Length(gInputBinds[i].up) > 0) then
@@ -1950,10 +1961,13 @@ begin
 end;
 
 procedure g_Console_WriteGameConfig;
+  var s: AnsiString;
 begin
-  if gParsingBinds then
-    Exit;
-  g_Console_WriteConfig(GameDir + '/dfconfig.cfg');
+  if gParsingBinds = false then
+  begin
+    s := e_GetDir(ConfigDirs);
+    g_Console_WriteConfig(e_CatPath(s, configScript))
+  end
 end;
 
 initialization