Can AGS read a variable outside of the game environment?

Started by , Fri 28/06/2013 19:57:25

Previous topic - Next topic

m0ds

Pretty simple but not the foggiest what to look for on this one. I'm wondering if I can make my game EXE check the folder it's in for another EXE. It would then run or quit if it does/does not find it. If that's possible, further whether it can identify the size, creation date/time or any other attributes about the other EXE and return that info or not? Any info much appreciated, even if it can't be done. Maybe there is some other trick that might substitute? Thank you :)

Crimson Wizard

#1
The only thing I know is possible:
Code: ags

if (File.Exists("winsetup.exe"))
  Display("found winsetup.exe!!");

Tested, working.

Khris

There's also ListBox.FillDirList(string filemask)
I have used this to select and load arbitrarily named tilemaps.
I guess one could also use File.ReadRawChar() to determine the filesize, but that could take long if the file is big, since one had to use a loop to read every single char and count them.

m0ds

Sure thank you! Just knowing the exe is there will certainly suffice, great! :)

m0ds

I remembered why them attribs would be useful, because with the above method I could just copy and rename notepad.exe and fake winsetup.exe and it would register that it exists. If you're able to expand on that File.ReadRawChar I can at least give it a try, or again any other tricks perhaps something I haven't thought of - thank you!

What I'm trying to do is admitedely a bit complex and stupid, but determining a size range would at least tighten it up a bit, for example, as long as it found an exe of between 10 and 15 mb for example.

Crimson Wizard

Quote from: Mods on Sat 29/06/2013 14:54:51What I'm trying to do is admitedely a bit complex and stupid
But what are you trying to do exactly?

Now that I think about this, it's a bit surprising there's no File.Length.

m0ds

Sure. Distributing a translation to people but it has to include a new EXE file (due to certain issues we could not simply update the old EXE nor just send out a .tra file due to the fonts in the first edition that can only be replaced, as far as I'm aware, by creating a new EXE). If people just have the new EXE, they can play the game, which I'd prefer to avoid as the main intention is to distribute the translation for free. So I'd like people to have the legitimate first EXE copy to be able to use the new one. So any kind of checks the new EXE can run on the old one are useful to me. I'm not looking for a hardened system and if people can find a way around it that's fine, but yeah, I'd like it to be one step harder than just renaming any EXE :)

I GUESS I could use the original method "File.Read" and make it look for all the files rather than just one EXE if there's no determining size.

Khris

You could do this:

Code: ags
bool SeemsLegit() {
  if (!File.Exists("game.exe")) return false;

  File *f = File.Open("game.exe", eFileRead);

  int count;
  char check[100];
  while (!f.EOF && count < 120) {
    char c = f.ReadRawChar();
    count++;
    int temp = count - 20;
    if (temp >= 0 && temp < 100) check[temp] = c;
  }
  f.Close();

  // compare char 20 - 120 of found game.exe to actual bytes in legitimate game exe
  return checks_out;
}



winsetup.exe is a bad indicator because all it does is call "game.exe --setup". There's a big chance that a mechanism based on it can be fooled by copying any winsetup.exe into the directory.

m0ds

Hi Khris, thank you but I don't understand it. Winsetup should be ignored completely.

Old EXE, let's say is 300mb. So if new EXE finds the old one at 300mb, or its equivalent bytes/kb etc, it will run a-ok.

Where in your code am I defining that 300mb file size? Thank you in advance :)

Khris

The code is not complete yet; all it does is read 100 bytes of the exe.
I was thinking it's a better way of identifying the file as opposed to just filesize, the other thing is that it might take AGS a long time to read 300 million bytes one by one.

You'd have to open the exe in a hex editor, find a position that contains bytes unique to the game, store them in an array, then compare them to the bytes read by my code.

The code I posted was more to give you an idea about the general way, it's not usable as-is, sorry.

m0ds

No prob thanks Khris. Additionally is there any kind of patching possible to ags games. To update an old exe. Never heard it to be possible before but just want to check.

Beyond that, any experiences on a translation for a game that did not have a comatible font originally (and if you had to update the exe) may give me some clues and ideas. Cheers!

Crimson Wizard

Make a universal launcher for your game, not AGS program.
It will let to choose a language and create a temporary file with secret code, then start appropriate AGS game. AGS game will read temporary file, and delete it, and continue only if code is right. For better security the code may be based on date/time of launch.
This launcher, being written not in AGS script but on programming language with wider functionality, will be able to make any possible checks, perhaps even md5 checksumm, of the existing exe files.

SMF spam blocked by CleanTalk