Alpha Centauri 2

Sid Meier's Alpha Centauri & Alien Crossfire => Modding => Topic started by: Mart on June 22, 2015, 12:58:06 AM

Title: Movies - new possibilities for modding
Post by: Mart on June 22, 2015, 12:58:06 AM
I am not sure, how much of what I am going to post is already "old" stuff, but here it goes.

Working with coding, I tried to do recently something with playing our wve movie files. Recent PRACX patch made somewhat easier to watch them. Also, the "wve" format is old. I was wondering, if some new movies, or movie corrections, upgrades, etc. could be made. After looking for, unsuccessfully, encoders that would match the playuv15.exe player provided by SMACX, I made a solution in a different way.
By writing a short executable I was able to insert movie playing with ffplay.exe, which is part of the FFMpeg freeware.
The only thing not working, presently, is that after SPs there was this screenie with text giving some details about the SP. It is not there anymore. But maybe in the future, that could be solved.

What new capabilities that gives?
The ffplay.exe can be replaced at any time when there is a new version. This allows for making/having videos with even some newest encodings, resolutions, etc.
Also one would have broader choice of formats/codecs. Anything, that ffplay can show, it will be shown.
game exe sends the ".wve" file name, but that is not a problem. We could have e.g. avi file simply renamed to .wve and ffplay will take that without problems. These applications detect what kind of video types they deal with.

For now, the command is hardcoded, but future versions can make that customizable, when someone wants to adjust ffplay command.
Current settings are:
- fullscreen
- autoexit, which turned out to be necessary on my machine. But probably this is neutral in other cases.
And there was needed a solution for how PRACX patch works, since it has "-software" argument passed to playuv15, which is not understood by ffplay.
The executable has though the same name: "playuv15.exe" since this is what terran.exe and terranx.exe uses.

Only for windows presently.

Should I make that downloadable? (the original playuv15.exe would be there too, for easier uninstall of the option).
FFplay (FFmpeg) is freeware, so there will be probably no problem, one would need to acknowledge the FFmpeg creators, which I will make in a readme file.
Any interest in this in the current state?
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on June 22, 2015, 01:03:24 AM
I think it was Davyboy who posted some research into the text at the end a few years ago.  Might be worth looking for.
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 22, 2015, 01:12:24 AM
Yes, I remember a thread about it. I will look for it.

On the other hand. Recently, I need to learn few things in coding (to make a living), so I would combine that with writing an application showing a text we want. I'm for it. :)
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 22, 2015, 12:20:35 PM
As it turns out, ffmpeg is presently on github in public access.
They way it works, everyone can download source code and compile it.
And this is what I am going to do, so when providing appropriate license GNU LGPL, that is sufficient.

And regarding the text display after the SP movies, it looks like it is gone already in either PRACX or Yitzi patches, or maybe even earlier.
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 24, 2015, 10:37:52 PM
Well, after some time spent on trying compilation of source code destined for linux on windows platform, and figuring out which bash version would digest the config and make on my system, I decided to settle on pre-compiled 32-bit ffplay for windows.
Already tried it, so it works ok.

I plan to make that a part of the Unity Mod v0.5, which hopefully will be soon for testing.

The replacement code for playuv15.exe is really simple:
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
 
main( int argc, char *argv[] )
{
    int c = 0;   
    char String[255];
    sprintf(String, "start ffplay -fs -autoexit %s ", argv[2]);
    chdir(".\\movies");
    int a = 1;
    a = system(String);
    do{;}while(a!=0);
return ;
}
And that's it. Compiled with gcc (freeware c compiler) from command line.
The resulting exe file should be renamed to "playuv15.exe" unless this name is given as output name when we compile in command line.
What is does is taking the command passed to original playuv and forwarding it to ffplay.exe
argv[1] is "-software", so it is dropped.
argv[2] is file name to play.
Instead, -fs (fullscreen), and -autoexit (player quits and we get back to smax screen) are given to ffplay.exe

So if some high resolution, nice looking movies are inserted into place of Secret Project movies, or opening movie, etc. we can watch them in very good quality.
=====
Corrected the code. The addition seems to fix the problem (originating in terranx.exe?) that for longer movies, smax was displaying its intro screenie, covering the movie, no video, but sound is on.
playuv15.exe terminating before ffplay completes?
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 28, 2015, 01:58:11 PM
Some more findings.

The simple "redirecting" application does not work 100% satisfactory. And I am not sure, what is causing this. I have to take a look into PRACX functionality, so also check, how that would work with exe before PRACX patching. Problems so far:
- Sometimes ffplay starts in fullscreen ok, sometimes it does not. And it seems also to scale its window according to some unknown to me yet factors.
- It looks like after some 2 minutes? terranx.exe takes over display, showing the intro screen, you can hear sound though, in some cases. The original playuv15.exe seems to prevent this, but possibly only when it plays a video. I launched it as suspended process, and it did not help the problem. Or, maybe, it needs to be suspended after some time, when it already has done some actions?
- And I wonder, how much of that would be an issue of using 32-bit application on 64-bit system. The 32-bit one will have to be "the base." I compile to 32-bit, while having 64-bit OS.

I tried to find out more about encoders for wve format. So this is actually, what they call Electronic Arts TQI. For sound there is some PCM codec.
And while ffmpeg has a lot of codecs, decoders, encoders, for this range of them (EA stuff) there is decoding, but no encoding. Probably we are not going to see these encoders anytime soon. They are not to be used by public, it seems.

The original playuv15.exe says, it is uV, uV2, TGV, ASF. The TGV is like that TQI, that reports from wve in SMACX. I wonder, if there are possibly some public-available codecs, that original playuv15.exe could show from that era, 1997, and used in AVI files. And maybe ASF would work.
But having possibility to play more and newer movies encoded with recent codecs, like in mp4 format, would be better. ffplay provides during-play functionality from keyboard, like pause, move a single frame forward, switch fullscreen on/off. But it is not a good solution to need hit keybord some few times each time a smacx movie plays.
It will most likely turn out, that "redirecting" will be a bit more complex code.
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on June 28, 2015, 02:00:58 PM
Hmmm.  I recall years ago talking about how handy it would be for scenarios to be able to put in our own movies.  VERY handy, given a movie relevant.

Good research. ;b;
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 28, 2015, 04:54:34 PM
Yes, we can already put our own movies in mods, and with that idea of writing your own executable, that passes movie file name to another player, ffplay being here only one of many possibilities, we can replace any movie file. For some movies, we probably have no good control, when they are played and how they are named, but there is this file:
movlist.txt
where we can rearrange/add SP movies (even rename). I haven't checked that yet, but possibly we can have 64 SP movies.
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on June 28, 2015, 06:30:00 PM
I linked a movie in the GotM folder at WPC long ago - it's dirty, but the first few minutes are cool CGI ships flying and docking.  That part could be useful, and not hard to toss the rest w/ Windows Movie Maker or something.
Title: Re: Movies - new possibilities for modding
Post by: Mart on June 30, 2015, 01:33:37 AM
We may have a kinda Hollywood on this forum soon.
Movie maker from Microsoft does not have many options for pan, transitions, animations, etc.
I found some other programs that can help:
- VirtualDub
- Avisynth
but I need to use them to find out more what they can do.

One problem solved, the movie now can play more than 2 minutes.
Done with c++, about 150 lines of code...
So the trick is to suspend terranx.exe for the time of playing the video and resume after.
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on June 30, 2015, 01:46:52 AM
...My sister is a Poser artist and quite adept with the video creation/editing, so a 30 seconds from scratch might be doable, if not too complex...
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 06, 2015, 12:32:20 PM
Update, but no big improvement.
At present, what is possible, is to have intro movie showing ok, and this is due to the game window having status: SW_SHOWNORMAL (int value 1) at this time. The problem of game screen taking over after 2 minutes (around, I am not sure how specific it is to OS settings on someone's computer) can be overcome by suspending terranx.exe process for that time. It all can be done with Win32 API.
Problem is still with other movies, like during SP completion, as I found, game window has status SW_SHOWMAXIMIZED (int value 3). Generally windows at that time are covered by terranx fullscreen. Although pushing 'f' few times can bring fullscreen ffplay to the front. How many times to push 'f'? This seems to be windows thing - just it depends on something, no idea what. It is known, that there is so-called "fight" over showing windows on top of other windows. Like you have advertisements screenies popping out into your face while doing something on your computer. People, comp users, really do not like that, so there is some ongoing development to control when and how windows can pop out on top of other windows. Not really easy stuff to overcome.

There are though ways, e.g. D3D hook. Not a perfect solution.
I try also to automatically change smacx window placement, but it looks like not an easy thing to do. C++ used functions like showwindow or setwindowplacement do not work.
And all this may be OS version specific, like versions of windows have different level of control over these permissions to change other windows' parameters. Or maybe this is more to the directx version.

So when someone runs a game in windowed mode, there is no problem, you can watch ffplay ok, it is not covered by smacx game. But I think many people play fullscreen.
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 10, 2015, 01:36:14 PM
Ok, so it seems I have a solution. For windows OS. Short explanation.
If we start terranx.exe in a regular way, some other application that we place in our game folder for purpose of playing movies, will not have sufficient rights to work around how the window of terranx.exe is displayed. How it is done in original playuv15.exe, I do not know. My attempts to force terranx.exe window to a particular state from such replaced playuv15.exe faild.
The solution, that I found is to use a launcher application, simple exe, that will launch terranx.exe and then "observe" if the playuv15.exe is launched by the game. If so, it fires the appropriate movie file.
The thing is, it seems like this launcher exe now can force smax main window to properly minimize and allow ffplay window to display on top.

I went further with testing release, now there will be "movies2" folder. Any new movie in this folder with matching body name (extensions .wve or .mp4 do not matter) will replace the original one.

I have downloaded the demo zip (renamed to .z) and it awaits approval.
In next posts:
- how to install and run the demo, uninstal.
- save file for testing.
- source code for those who prefer to compile executables themselves.
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 10, 2015, 02:22:58 PM
Installing smax-movie-demo

First, you may want to backup your playuv15.exe file from "movies" folder, although the rescue file (copy of it) is provided in the zip.
Most likely, the file you have (downloaded), has name ending with .z
Rename it to .zip
Unpack the content "keeping folders tree" into your game folder
- file: terx_movie.exe should be in the same folder as your terranx.exe, that you play smax with.

There will be one file replacement needed: playuv15.exe, make the replacement.
- there is provided PP version: playuv15.exe.original in case you did not make a backup.

Important:

Start the game clicking the terx_movie.exe, otherwise you will not be able to watch any movies in the game.

Additional:
- After a movie, in this demo/test, for now, use mouse to click appropriate buttons rather than enter from keyboard. It works better this way.
New version will have appropriately set activate window function.

Uninstalling smax-movie-demo

You can remove completely:
- folder "TERX_movie"
- folder "movies2", thogh you may want to keep your alternative movies.
- terx_movie.exe file from main game folder.
- As for folder "movies" you can delete files:
-- playuv15.exe
-- ffplay.exe
-- ffplay-LICENSE.txt

At this point you either:
- place your buckup playuv15.exe to restore functionality from before demo
- rename 'playuv15.exe.original' to 'playuv15.exe'

If you choose the first option, you can delete the ' .original' file.

How to add replacement movies to the game


1) Make a movie and save it in some format readable for ffplay. They have broad range of codecs, so mp4 or avi would work ok. The original wve format can also be played by ffplay!
2) Name this new movie with the same file body name, as the one you want to replace. The extension does not matter, so for example:
making file 'openingx.mp4' will replace 'openingx.wve' during game.
3) Place this new movie in "movies2" folder.
You do not need to move or delete or replace the file in "movies" folder. You can keep the original movies there.

In case you want return to original movie, either:
- delete new file from "movies2"
- change the name of the file in "movies2" so the name bodies do not match, e.g.:
'openingx.mp4' to 'openingx_1.mp4'

Notes:

- Folder "TERX_movie" is crucial for functioning of the system, so it should be there, and:
- Folder "TERX_movie"should be possible to be written into, the playuv15.exe writes movie name to a txt file there. So do not set "read-only" flag for it.
- Inside this folder, "TERX_movie" is the file "ffplay_options.txt", also crucial to the system functioning well. It contains flags for ffplay.
It is recommended to keep -autoexit for automatic movie end. Otherwise, you will need to close ffplay window manually each time.
You can try other options for ffplay, e.g. resizing or full screen, etc.
- when playing movies, you have access to functions of ffplay from keyboard, such as:
"s" step one movie frame, it also makes a "pause"
"f" toggle fullscreen
"p" pause
etc. check ffplay documentation for more.
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 10, 2015, 02:34:04 PM
A short test, that you can quickly check.

The demo zip contains two replacement movies:
- openingx.mp4, so in order to watch it, you should have it "not disabled" in the ini file.
- weatherParadigm.mp4

Attached to this post is save file, for Gaians, that their two bases are completing two SPs next turn:
- Weather Paradigm
- Merchant exchange

So only by pushing "end turn" you can check if both movies play properly, one is replaced, the other is not. Merchant exchange will have in its window .wve name.

How does that work for you?
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 14, 2015, 02:31:41 PM
And the code for playuv15.exe substitute.
What it does in this "project" iteration, is save the movie file name to TERX_movie folder and by its presence give signal to the terx_movie.exe to play the movie.
The presence time is hardcoded to 1 second (old function sleep(1); ) however, if your windows would be very busy, and terx_movie.exe got no CPU time in that second, it would miss the play order. This way of doing detection is not really perfect, I can do it better next time, but for over 99% of cases it works.

Compiled with freeware c++ compiler MinGW.
g++ -m32 name.cpp -o playuv15.exe

flag -m32 forces 32bit executable, when being on 64bit system.
name.cpp is name of text c++ code file.

Code: [Select]
#include <windows.h>
#include <cstdlib>
#include <string>
#include <unistd.h>
#include <tchar.h>
#include <fstream>
using namespace std;
const char g_szClassName[] = "smacxWindowFfplay";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    FreeConsole();
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    if(!RegisterClassEx(&wc))
    {
        ::MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }
    // getting command line
    TCHAR cmdline[4096] ;
    TCHAR* argv[4096] ;
    int argc = 0 ;
    _tcscpy( cmdline, GetCommandLine() ) ;
    argv[argc] = _tcstok( cmdline, TEXT(" \t") ) ;
    while( argv[argc] != 0 )
    {
        argc++ ;
        argv[argc] = _tcstok( 0, TEXT(" \t") ) ;
    }
    // name of the movie to play
    string sargv = argv[argc-1];
    // saving the name to the file
    std::ofstream ofs(".\\TERX_movie\\movie.txt",std::ofstream::out);
    ofs << sargv;
    ofs.close();
    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Playing ...",
        WS_ICONIC,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);
    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }
    ShowWindow(hwnd, SW_SHOWMINIMIZED);
    UpdateWindow(hwnd);
    sleep(1);

 // Step 3: The Message Loop
    ::PostMessage(hwnd, WM_CLOSE, 0, 0);
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}// end of WinMain
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 14, 2015, 02:47:56 PM
And terx_movie.exe
This file should go to main game folder. This is monitoring executable. It launches terranx.exe and then waits for playuv15 to appear, then plays the appropriate movie, then waits further. It quits right after there is no terranx.exe process.
Important: You should rather use one game instance, like do not fire the smax game twice or more simultaneously.
SMAX should be launched with it, otherwise you will see no movies (replaced playuv15.exe).
Like the post previously, compiled with MinGW:
g++ -m32 name.cpp -o terx_movie.exe -lpsapi
flag -lpsapi is required for proper linking of psapi.h

Code: [Select]

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <tlhelp32.h>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <psapi.h>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
void suspend(DWORD processId);
void resume(DWORD processId);
string ExePath();

int main( int argc, char *argv[] )
{
FreeConsole();
HWND hWnd1 = NULL;
HWND hWnd2 = NULL;
vector<string> vNameShort;
vector<string> vNameFull;
string nameShort;
string nameFull;
bool replace = false;
std::size_t found;
//for testing and message boxes
std::stringstream os;
// read movie names from movies2
    string folder = ExePath();
    folder.append("\\movies2\\");
    char search_path[200];
    sprintf(search_path, "%s*.*", folder.c_str());
    WIN32_FIND_DATA fd;
    HANDLE hFind = ::FindFirstFile(search_path, &fd);
    if(hFind != INVALID_HANDLE_VALUE) {
        do {
            if(! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) {
                vNameFull.push_back(fd.cFileName);   
            }
        }while(::FindNextFile(hFind, &fd));
        ::FindClose(hFind);
    }
    // creating the second vector
    for(int i=0;i<vNameFull.size();++i){
        found= vNameFull[i].find('.');
        if (found!=std::string::npos){
            nameShort = vNameFull[i].substr(0,found);
        }
        vNameShort.push_back(nameShort);
    }
// Starting terranx.exe
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    CreateProcess( "terranx.exe",
        NULL,
        NULL,
        NULL,
        FALSE,
        0,              //CREATE_NO_WINDOW
        NULL,
        NULL,
        &si,
        &pi ) ;
// Loop
while(true){
usleep(300*1000);
// finding working smacx
hWnd1 = FindWindow(NULL,"Sid Meier's Alpha Centauri");
if(hWnd1==NULL){
// no terranx.exe so quiting
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    return 0;
}
else{
// check if playuv15 is launched
hWnd2 = FindWindow(NULL,"Playing ...");

if(hWnd2!=NULL){
usleep(100*1000);
    DWORD pid;
// find state of smax window, save it
    WINDOWPLACEMENT wp;
    wp.length = sizeof(WINDOWPLACEMENT);
   
    RECT rect1;
    rect1.left = 0;
    rect1.right = 0;
    rect1.top = 800;
    rect1.bottom = 600;
    POINT p1,p2;
    p1.x = 0;
    p1.y = 0;
    WINDOWPLACEMENT wp1;
    wp1.length = sizeof(WINDOWPLACEMENT);
    wp1.flags = WPF_ASYNCWINDOWPLACEMENT;
    wp1.showCmd = 6;
    wp1.ptMinPosition = p1;
    wp1.ptMaxPosition = p1;
    wp1.rcNormalPosition = rect1;
   
    GetWindowPlacement(hWnd1,&wp);
    // change to windowed, or normal state
    SetWindowPlacement(hWnd1,&wp1);
    SetWindowPos(hWnd1,HWND_BOTTOM,0,0,800,600,SWP_NOMOVE);
// find terranx process
// suspend the process
    DWORD aProcesses[1024], cbNeeded, cProcesses;
    bool ret = false;
    ret = EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded );
    if ( !ret )
    {
        ::MessageBox(
            NULL,
            "Enumerating processes problem",
            "Message",
            MB_ICONEXCLAMATION | MB_OK
        );
        return 1;
    }
    // Calculate how many process identifiers were returned.
    cProcesses = cbNeeded / sizeof(DWORD);
    // Print the name and process identifier for each process.
    for ( int i = 0; i < cProcesses; i++ )
    {
        if( aProcesses[i] != 0 )
        {
            DWORD processID = aProcesses[i];
            TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); 
            // Get a handle to the process.
            HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID );
            // Get the process name.
            if (NULL != hProcess )
            {
                HMODULE hMod;
                DWORD cbNeeded;
                if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),&cbNeeded) )
                {
                    GetModuleBaseName( hProcess, hMod, szProcessName,
                                       sizeof(szProcessName)/sizeof(TCHAR) );
                }
            }
            if(!strcmp(szProcessName,"terranx.exe")){
                pid = processID;
                suspend(processID);
            }
        }
    }
// find name of the movie to play and play it, waiting for completion
    string str1;
    string stroptions;
    string nameToPlay = "";
    nameShort = "";
    std::ifstream infile;
    infile.open(".\\TERX_movie\\movie.txt",ios::in);
    getline(infile,nameToPlay);
    nameFull = nameToPlay;
    found=nameFull.find('.');
    if (found!=std::string::npos){
        nameShort = nameFull.substr(0,found);
    }
    if(nameShort != ""){
        // choosing which folder to play
        replace = false;
        for(int i=0;i<vNameShort.size();++i){
            if((replace==false)&&(0==nameShort.compare(vNameShort[i]))){
                replace = true;
                nameToPlay = vNameFull[i];
            }
        }
    }
    infile.close();
    std::ifstream infile2;
    infile2.open(".\\TERX_movie\\ffplay_options.txt",ios::in);
    getline(infile2,stroptions);
    infile2.close();
    str1 = " ";
    str1.append(stroptions);
    str1.append(" ");
    str1.append(nameToPlay);
    // trying to pass LPCTSTR...
    char s[255] = "";
    strcpy(s, str1.c_str());
    LPCTSTR sls;
    sls = s;
    // and folders
    LPCTSTR whichFolder;
    if(replace){
        whichFolder = _T(".\\movies2");
    }else{
        whichFolder = _T(".\\movies");
    }
    SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS|SEE_MASK_NO_CONSOLE ;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "ffplay.exe";       
    ShExecInfo.lpParameters = sls;   
    ShExecInfo.lpDirectory = whichFolder;
    ShExecInfo.nShow = SW_SHOWMAXIMIZED;
    ShExecInfo.hInstApp = NULL;
    if(!ShellExecuteEx(&ShExecInfo))
    {
        ::MessageBox(
        NULL,
        "Failed to create process, and start ffplay",
        "Message",
        MB_ICONEXCLAMATION | MB_OK
        );
        return -1;
    }
    else{
    WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
    }
// resume terranx process
    resume(pid);
// restore window to its state
    SetWindowPlacement(hWnd1,&wp);
    SetFocus(hWnd1);
    SetActiveWindow(hWnd1);
// end of playing procedure, delete movie name file.
}
}//end of if handle to window terranx found
}//end while true
}// end of main

void suspend(DWORD processId)
{
    stringstream stros;
    stros << processId;     
    HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    THREADENTRY32 threadEntry;
    threadEntry.dwSize = sizeof(THREADENTRY32);
    Thread32First(hThreadSnapshot, &threadEntry);
    do
    {
        if (threadEntry.th32OwnerProcessID == processId)
        {
            HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE,
                threadEntry.th32ThreadID);
            SuspendThread(hThread);
            CloseHandle(hThread);
        }
    } while (Thread32Next(hThreadSnapshot, &threadEntry));
    CloseHandle(hThreadSnapshot);
}

void resume(DWORD processId)
{
    HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    THREADENTRY32 threadEntry;
    threadEntry.dwSize = sizeof(THREADENTRY32);
    Thread32First(hThreadSnapshot, &threadEntry);
    do
    {
        if (threadEntry.th32OwnerProcessID == processId)
        {
            HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE,
                threadEntry.th32ThreadID);
            ResumeThread(hThread);
            CloseHandle(hThread);
        }
    } while (Thread32Next(hThreadSnapshot, &threadEntry));
    CloseHandle(hThreadSnapshot);
}

string ExePath() {
    char buffer[MAX_PATH];
    GetModuleFileName( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\\/" );
    return string( buffer ).substr( 0, pos);
}
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 14, 2015, 02:56:49 PM
That's for now. I would say, this solution is 80-90% satisfactory.
Having an additional process, that monitors terranx.exe is potentially good for other tricks with the game. It may be a drawback though. Sometimes I forget to launch the game with it and click terranx.exe instead. Having a link would probably work much better.

I hope to get soon better knowledge of how Windows work, for example there is this application "Free Alarm Clock" that forces my smax in full screen to windowed mode to play the alarm.
How do they do it? Both processes are not probably connected. So this alarm app is using some proper commands to put its window to the front, and even force a DirectX game out of full screen.
So I am looking for this solution now.
Title: Re: Movies - new possibilities for modding
Post by: Mart on July 20, 2015, 12:04:09 PM
And there is something, that repeats itself, not sure why.
When I start terx_movie.exe, after some longer time not playing SMACX, intro movie does not start. Apparantly, "observer" does not catch playuv15 in time. I usually have more processes started on a computer, so that may be a factor.

Some other way of writing this "observer" app would be better. I have some idea already.
Still, looking for "playuv15 only" solution is preferred.
Title: Re: Movies - new possibilities for modding
Post by: Mart on August 24, 2015, 12:39:50 AM
I have seen, there is already several downloads of the demo.
any comments on how it works?
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on August 24, 2015, 12:47:25 AM
I've passed to question along to the Facebook AC players group.
Title: Re: Movies - new possibilities for modding
Post by: DrazharLn on August 25, 2015, 12:55:54 PM
Can you tell us more about this Unity mod?
Title: Re: Movies - new possibilities for modding
Post by: Mart on August 25, 2015, 04:43:32 PM
It is larger rules overhaul. I did not set complete changes scope yet, being open to new possibilities.
Some time ago (already several years ago) I made version 0.3, which was before scient's patch. Now, with more modding capabilities much more can be made. So what I have now is already quite different from v0.3

Most important highlights:
- making research rate slower in late game, but not in early game.
- decrease of micromanagement, making ICS less of a good strategy
- redesigning some facilities, "policies"
- some tricks with units: pseudo-facilities
- modifying some chassis, foils and copters would work differently, this is going around some hard-coded stuff
- "flattening" energy, so incomes do not go so high up in later game, this is connected to research speed.

I am planning new movies, but it takes time...
I have already done most of changes for new version in alphax.txt, so probably could post it soon. Graphics though needs adjusting.

----
And probably this new feature also needs to be mentioned:
- redesigning some unit abilities. Some appear sooner/have different "allow" values, so their effects are somewhat different.
- and many more.
Title: Re: Movies - new possibilities for modding
Post by: DrazharLn on August 26, 2015, 09:29:08 AM
Thanks for working on this, Mart, it sounds really interesting. I look forward to trying the finished product and I'll help test this film replacement when I have some time at home.
Title: Re: Movies - new possibilities for modding
Post by: Mart on August 31, 2015, 06:09:15 PM
DrazharLn, thank you!

As for movies, at present the biggest problem is, that the replacement executable, which is started by smacx does not have enough privileges to force it out of foreground for time of movie play. I am not sure, if that can be easily done. My knowledge of windows is not that good in this area. SMACX does seem to do it, though, with its original playuv15.exe. The thing is, the replacement "playuv15.exe" would serve only as launcher/manager of new movies and ffplay.exe would actually play movies. So it is ffplay.exe that needs to make smacx(terranx.exe) to go out of foreground and let it play the movie.

The demo uses different solution, where there is yet another executable ("manager"), that launches smacx (terranx.exe), thus as parent process it can force it to go out of foreground and allow ffplay.exe to show the movie.
I do not consider this solution as the best, since one (person playing the game) actually must use it instead of terranx.exe to launch the game. Also, the manager must be active "observing" if terranx.exe launches playuv15.exe.
Title: Re: Movies - new possibilities for modding
Post by: DrazharLn on August 31, 2015, 09:42:25 PM
As for movies, at present the biggest problem is, that the replacement executable, which is started by smacx does not have enough privileges to force it out of foreground for time of movie play... SMACX does seem to do it, though, with its original playuv15.exe.


terran(x).exe doesn't actually call playuv15.exe. You can delete it and SMAC will happily play the movies. The playuv code is actually contained within the terran(x).exe binaries.

I'm afraid I don't know the Windows APIs either. I think Plotinus changed the movie playing behaviour and has them played by playuv directly, so you could look at what he's doing (source code is available but not commented very much) or just try replacing playuv15 with your own thing while running PRACX.

Quote
The thing is, the replacement "playuv15.exe" would serve only as launcher/manager of new movies and ffplay.exe would actually play movies. So it is ffplay.exe that needs to make smacx(terranx.exe) to go out of foreground and let it play the movie.


I got SMAC to call a batch file that called ffplay in a previous experiment, I think I got videos to be played OK and don't remember them being played in the background, but I'm not entirely sure. I can't remember exactly what I was doing, but here's the thread where I talked about it: http://alphacentauri2.info/index.php?topic=8500.0 (http://alphacentauri2.info/index.php?topic=8500.0)

Quote
The demo uses different solution, where there is yet another executable ("manager"), that launches smacx (terranx.exe), thus as parent process it can force it to go out of foreground and allow ffplay.exe to show the movie.

I do not consider this solution as the best, since one (person playing the game) actually must use it instead of terranx.exe to launch the game. Also, the manager must be active "observing" if terranx.exe launches playuv15.exe.


That doesn't sound like a particularly bad solution to me.

I can't find the demo.zip. Is it still uploaded somewhere and would you like it tested?
Title: Re: Movies - new possibilities for modding
Post by: Buster's Uncle on August 31, 2015, 09:57:15 PM
If SMAC will do:  http://alphacentauri2.info/index.php?action=downloads;sa=view;down=66 (http://alphacentauri2.info/index.php?action=downloads;sa=view;down=66)

I had the X demo on a Computer Games+ disk back in the day, if only I could find it...

Are we talking about the same thing?
Title: Re: Movies - new possibilities for modding
Post by: Mart on August 31, 2015, 10:25:59 PM
... I think Plotinus changed the movie playing behaviour and has them played by playuv directly, so you could look at what he's doing (source code is available but not commented very much) or just try replacing playuv15 with your own thing while running PRACX.

Yes, I can see it there. I have not read all the PRACX code, but Plotinus possibly took care of the smacx window going into background, or yielding "topmost" status to playuv15, since with the patch we can see the movies ok, even though they are really played by this external playuv15.exe?

And that gives me an idea of modifying pracx.dll in hex editor. That could work.
Quote
I got SMAC to call a batch file that called ffplay in a previous experiment, I think I got videos to be played OK and don't remember them being played in the background, but I'm not entirely sure. I can't remember exactly what I was doing, but here's the thread where I talked about it: http://alphacentauri2.info/index.php?topic=8500.0 (http://alphacentauri2.info/index.php?topic=8500.0)
...

I'm checking it now...
Title: Re: Movies - new possibilities for modding
Post by: Mart on September 02, 2015, 09:26:06 PM
...
That doesn't sound like a particularly bad solution to me.
Yes, I will have to take a look into IPC, interprocess communication.
The way it is now, there are problems with "catching" playuv15 launch.
And I am not using any of IPc, just an on-the-go solution.
Title: Re: Movies - new possibilities for modding
Post by: DrazharLn on September 03, 2015, 08:55:29 AM
Yes, I can see it there. I have not read all the PRACX code, but Plotinus possibly took care of the smacx window going into background, or yielding "topmost" status to playuv15, since with the patch we can see the movies ok, even though they are really played by this external playuv15.exe?

And that gives me an idea of modifying pracx.dll in hex editor. That could work.

Looking at the code, the call to playuv15 is very simple, one of the parameters might be controlling yielding focus, I suppose, but I don't know for sure.

There should be no need to edit pracx.dll in a hex editor (and it would be better for future development if you did not). You can just edit the c++ source code and compile your own modified .dll.

Are we talking about the same thing?

'Fraid not. I was talking about Mart's demo of this hack.
Title: Re: Movies - new possibilities for modding
Post by: Mart on September 06, 2015, 08:44:57 PM
I checked the demo of movie replacement, it downloads ok, it is 22.7 Mb.
The file is .z, which needs to be renamed to .zip
So it should be ok.

http://alphacentauri2.info/index.php?action=downloads;sa=view;down=303 (http://alphacentauri2.info/index.php?action=downloads;sa=view;down=303)
Title: Re: Movies - new possibilities for modding
Post by: DrazharLn on September 08, 2015, 10:38:08 PM
Cool. I'll have a chance to check that out in a couple of days. Is there anything in particular you'd like me to look at when I try it out?
Title: Re: Movies - new possibilities for modding
Post by: Mart on September 12, 2015, 07:18:59 PM
... Is there anything in particular you'd like me to look at when I try it out?
Nothing in particular. Just overall experience:
- how it works on the comp you are using, opens ok, always or sometimes,
- possibly some bugs
etc.
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 4: index+Modifications.english (default), TopicRating/.english (default), PortaMx/PortaMx.english (default), OharaYTEmbed.english (default).
Style sheets: 0: .
Files included: 31 - 840KB. (show)
Queries used: 15.

[Show Queries]