// AUTO-GENERATED FILE, MOVE TO 'gh_fix' FOLDER PREVENT OVERWRITING!!!!! 

#include <r3/binders/auto.h>
#include <gh_global.h>

extern "C" {
undefined4 get_one(void); // 00485bd0 // get_one
void set_unk(HWND wnd); // 0043e620 // set_unk
int r3_get_gli_width0(void); // 004012c0 // r3_get_gli_width0
int r3_get_gli_height0(void); // 004012d0 // r3_get_gli_height0
undefined4 FUN_0046ed70(char * param_1, short * param_2); // 0046ed70 // FUN_0046ed70
undefined FUN_0046f640(undefined param_1, short param_2, undefined4 * param_3); // 0046f640 // FUN_0046f640
void FUN_0047c150(short param_1, short param_2, int param_3); // 0047c150 // FUN_0047c150
long r3_windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); // 004025e0 // r3_windowProc
int r3_get_gli_width1(void); // 0047baf0 // r3_get_gli_width1
void r3_load_splash_bitmap(HWND unused); // 00402450 // r3_load_splash_bitmap
int r3_get_gli_height1(void); // 0047bb00 // r3_get_gli_height1
undefined4 FUN_0046f0b0(short param_1, undefined4 * param_2, short * param_3); // 0046f0b0 // FUN_0046f0b0
void r3_set_window_wh(undefined4 param_1, undefined4 param_2); // 004012a0 // r3_set_window_wh

// 00402140
undefined4 r3_setupWindow(HINSTANCE hInstance,undefined4 param_2,int maximizeWindow)

{
  ATOM AVar1;
  int iVar2;
  HWND hWnd;
  HWND pHVar3;
  bool bVar4;
  char acStack_e0 [28];
  int iStack_c4;
  int iStack_c0;
  undefined4 uStack_bc;
  HWND pHStack_b8;
  HWND pHStack_b4;
  undefined4 uStack_b0;
  undefined4 uStack_ac;
  undefined4 auStack_80 [5];
  undefined4 uStack_6c;
  DWORD dwStyle;
  int iVar5;
  int iVar6;
  undefined local_28 [28];
  HBRUSH pHStack_c;
  LPCSTR pCStack_8;
  char *pcStack_4;
  
  INT_0077d0a4 = 1;
                    /* WindowClassA (overlaps usage below) */
  local_28 + Field<0, 4>() = 0x3003;
  local_28 + Field<4, 4>() = r3_windowProc;
  local_28 + Field<8, 4>() = 0;
  local_28 + Field<12, 4>() = 0;
  local_28 + Field<16, 4>() = hInstance;
  local_28 + Field<20, 4>() = LoadIconA(hInstance,(LPCSTR)0x65);
  local_28 + Field<24, 4>() = LoadCursorA((HINSTANCE)0x0,(LPCSTR)0x7f00);
  pHStack_c = (HBRUSH)0x6;
  pCStack_8 = (LPCSTR)0x0;
  pcStack_4 = g_windowTitle;
  AVar1 = RegisterClassA((WNDCLASSA *)local_28);
  if (AVar1 != 0) {
    bVar4 = maximizeWindow == 0;
    if (bVar4) {
      iVar5 = GetSystemMetrics(0x20);
      iVar5 = iVar5 * 2 + 0x140;
      iVar6 = GetSystemMetrics(0x21);
      iVar2 = GetSystemMetrics(4);
      iVar6 = iVar2 + 0xf0 + iVar6 * 2;
      dwStyle = 0x90cf0000;
    }
    else {
      iVar6 = 0xf0;
      iVar5 = 0x140;
      dwStyle = 0x91000000;
    }
    uStack_6c = 0x40221d;
    hWnd = CreateWindowExA(0,g_windowTitle,g_windowTitle,dwStyle,(uint)bVar4,(uint)bVar4,iVar5,iVar6
                           ,(HWND)0x0,(HMENU)0x0,hInstance,(LPVOID)0x0);
    g_gameHWND1 = hWnd;
    if (hWnd != (HWND)0x0) {
      g_gameHWND = hWnd;
      SetWindowTextA(hWnd,s_windowTitle);
      if (maximizeWindow == 0) {
                    /* SW_NORMAL */
        iVar5 = 1;
      }
      else {
                    /* SW_MAXIMIZE */
        iVar5 = 3;
      }
      ShowWindow(hWnd,iVar5);
      SetWindowPos(hWnd,(HWND)0x0,0,0,0,0,0x43);
      EnableWindow(hWnd,1);
      SetFocus(hWnd);
      UpdateWindow(hWnd);
      SetForegroundWindow(hWnd);
      pHVar3 = GetFocus();
      while (pHVar3 != hWnd) {
        SetWindowPos(hWnd,(HWND)0x0,0,0,0,0,0x43);
        EnableWindow(hWnd,1);
        SetFocus(hWnd);
        UpdateWindow(hWnd);
        SetForegroundWindow(hWnd);
        pHVar3 = GetFocus();
      }
      set_unk(hWnd);
      r3_load_splash_bitmap(hWnd);
      INT_0077d0a4 = 1;
      iVar5 = get_one();
                    /* always taken */
      if (iVar5 != 0) {
        iVar5 = get_one();
                    /* never taken */
        if (iVar5 == 0) {
                    /* WARNING: Subroutine does not return */
          exit(-1);
        }
        iVar5 = r3_get_gli_height1();
        iVar6 = r3_get_gli_width1();
        r3_set_window_wh(iVar6,iVar5);
        GetClientRect(g_gameHWND,(LPRECT)(local_28 + 0x18));
        uStack_b0 = 1;
        iStack_c4 = r3_get_gli_width0();
        iStack_c0 = r3_get_gli_height0();
        uStack_bc = 0x10;
        pHStack_b8 = g_gameHWND;
        pHStack_b4 = g_gameHWND;
        uStack_ac = 10;
        iVar5 = FUN_0046ed70(acStack_e0,(short *)&WORD_0077d4d4);
        if (iVar5 != 0) {
          local_28 + Field<0, 4>() = 0;
          local_28 + Field<4, 4>() = (WNDPROC)0x0;
          iVar5 = FUN_0046f0b0(WORD_0077d4d4,auStack_80,(short *)&WORD_0077d4d6);
          if ((iVar5 != 0) &&
             (iVar5 = FUN_0046f640((char)WORD_0077d4d4,WORD_0077d4d6,&DWORD_0077d4d8), iVar5 != 0))
          {
            if (DWORD_0077d4d8 != 0) {
              FUN_0047c150(WORD_0077d4d4,WORD_0077d4d6,DWORD_0077d4d8);
            }
            return 1;
          }
        }
                    /* Failed */
        return 0;
      }
                    /* WARNING: Subroutine does not return */
      exit(-1);
    }
  }
                    /* Failed */
  return 0;
}

}

