#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
#ifdef MEDIA772_SU1E
char G4197_[] = "A:\\FTLCODE";
#endif


void F7090_MakeNewAdventure( /* BUGX_XX: In the Atari ST version only, function is F7020_RemoveObjectModifiersFromStatistics is missing. When importing champions from a saved game, the temporary effects of champion possessions on skill and statistics become permanent. In other versions, these modifiers are removed before the champions are imported. */
)
{
#ifdef MEDIA772_SU1E
        register CHAMPION* L5817_ps_Champion;
        CSB_SAVE_HEADER* L4039_ps_;
        CSB_SAVE_HEADER* L4040_ps_;
        register int16_t L4052_i_;
        register int16_t L4051_i_;


        L4039_ps_ = &G7111_Games[C1_GAME_DESTINATION].SaveHeader;
        if (G7111_Games[C0_GAME_SOURCE].SaveHeaderFormat == C0x02_SAVE_HEADER_FORMAT_CHAOS_STRIKES_BACK) {
                L4040_ps_ = &G7111_Games[C0_GAME_SOURCE].SaveHeader;
        } else {
                L4040_ps_ = NULL;
        }
        if (L4040_ps_) {
                F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 256, (char*)L4039_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 288, (char*)L4039_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                L4039_ps_->GameID = L4040_ps_->GameID + 1;
                if (L4040_ps_->FormatID == C1_FORMAT_DM_ATARI_ST) {
                        L4039_ps_->Platform = C1_PLATFORM_ATARI_ST;
                } else {
                        L4039_ps_->Platform = L4040_ps_->Platform;
                }
        } else {
                F7317_MAIN_CopyBytes_Alt((char*)&G7111_Games[C0_GAME_SOURCE].SaveHeader + 256, (char*)L4039_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                F7317_MAIN_CopyBytes_Alt((char*)&G7111_Games[C0_GAME_SOURCE].SaveHeader + 288, (char*)L4039_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                L4039_ps_->GameID = G7111_Games[C0_GAME_SOURCE].SaveHeader.GameID + 1;
                if (G7111_Games[C0_GAME_SOURCE].SaveHeader.FormatID == C1_FORMAT_DM_ATARI_ST) {
                        L4039_ps_->Platform = C1_PLATFORM_ATARI_ST;
                } else {
                        L4039_ps_->Platform = G7111_Games[C0_GAME_SOURCE].SaveHeader.Platform;
                }
        }
        F0088_strcpy(G7111_Games[C1_GAME_DESTINATION].FileName, G3799_pc_ChaosStrikesBackSavedGameFileName);
        F7317_MAIN_CopyBytes_Alt(G7111_Games[C0_GAME_SOURCE].Party.Champions, G7111_Games[C1_GAME_DESTINATION].Party.Champions, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(G7111_Games[C1_GAME_DESTINATION].Party.Champions));
        G7111_Games[C1_GAME_DESTINATION].GlobalData.PartyChampionCount = G7114_LoadedChampionCount;
        L4052_i_ = 0;
        L5817_ps_Champion = G7111_Games[C1_GAME_DESTINATION].Party.Champions;
        while (L4052_i_ < G7114_LoadedChampionCount) {
                if ((L4051_i_ = G7111_Games[C1_GAME_DESTINATION].GlobalData.PartyDirection - G7111_Games[C0_GAME_SOURCE].GlobalData.PartyDirection) != 0) {
                        L4051_i_ += 4;
                        L5817_ps_Champion->Cell = (L5817_ps_Champion->Cell + L4051_i_) & 3;
                        L5817_ps_Champion->Direction = (L5817_ps_Champion->Direction + L4051_i_) & 3;
                }
                L5817_ps_Champion->Useless1 = 1;
                L5817_ps_Champion->Useless2 = 2;
                L5817_ps_Champion->ActionIndex = 0xFF;
                L5817_ps_Champion->SymbolStep = 0;
                L5817_ps_Champion->Symbols[0] = 0;
                L5817_ps_Champion->DirectionMaximumDamageReceived = 0;
                L5817_ps_Champion->MaximumDamageReceived = 0;
                L5817_ps_Champion->PoisonEventCount = 0;
                L5817_ps_Champion->EnableActionEventIndex = -1;
                L5817_ps_Champion->HideDamageReceivedEventIndex = -1;
                L5817_ps_Champion->Attributes &= MASK0x0010_MALE;
                L5817_ps_Champion->Wounds = 0;
                L5817_ps_Champion->CurrentHealth = L5817_ps_Champion->MaximumHealth;
                L5817_ps_Champion->CurrentStamina = L5817_ps_Champion->MaximumStamina;
                L5817_ps_Champion->CurrentMana = L5817_ps_Champion->MaximumMana;
                L5817_ps_Champion->ActionDefense = 0;
                L5817_ps_Champion->Food = M003_RANDOM(256) + 1500;
                L5817_ps_Champion->Water = M003_RANDOM(256) + 1500;
                for (L4051_i_ = C0_STATISTIC_LUCK; L4051_i_ <= C6_STATISTIC_ANTIFIRE; L4051_i_++) {
                        L5817_ps_Champion->Statistics[L4051_i_][C2_MINIMUM] = 30;
                        L5817_ps_Champion->Statistics[L4051_i_][C1_CURRENT] = L5817_ps_Champion->Statistics[L4051_i_][C0_MAXIMUM];
                }
                L5817_ps_Champion->Statistics[C0_STATISTIC_LUCK][C2_MINIMUM] = 10;
                L4051_i_ = C00_SKILL_FIGHTER;
                while (L4051_i_ < C19_SKILL_WATER + 1) {
                        L5817_ps_Champion->Skills[L4051_i_++].TemporaryExperience = 0;
                }
                L4051_i_ = C00_SLOT_READY_HAND;
                while (L4051_i_ < C29_SLOT_BACKPACK_LINE1_9 + 1) {
                        L5817_ps_Champion->Slots[L4051_i_++] = C0xFFFF_THING_NONE;
                }
                L5817_ps_Champion->Load = 0;
                L5817_ps_Champion->ShieldDefense = 0;
                L4052_i_++;
                L5817_ps_Champion++;
        }
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        REGISTER int16_t L4051_i_;
        unsigned int16_t L4052_ui_;
        CSB_SAVE_HEADER* L4038_ps_;
        CSB_SAVE_HEADER* L4039_ps_;
        DM_SAVE_HEADER* L4040_ps_;
        DM_SAVE_HEADER* L4041_ps_;
        unsigned char L4042_uc_;
        unsigned int16_t L4043_ui_;
        int16_t L4044_i_;
        GAME* L4045_ps_;
        GAME* L4046_ps_;
        char* L4047_pc_;
        unsigned char (*L4048_paauc_)[7][3];
        SKILL* L4049_ps_;
        THING* L4050_ps_;


        L4040_ps_ = NULL;
        L4038_ps_ = NULL;
        L4041_ps_ = NULL;
        L4039_ps_ = NULL;
        L4045_ps_ = &G7111_Games[C0_GAME_SOURCE];
        L4046_ps_ = &G7111_Games[C1_GAME_DESTINATION];
        if (L4045_ps_->SaveHeaderFormat == C0x02_SAVE_HEADER_FORMAT_CHAOS_STRIKES_BACK) {
                L4038_ps_ = (CSB_SAVE_HEADER*)&L4045_ps_->SaveHeader;
        } else {
                L4040_ps_ = &L4045_ps_->SaveHeader;
        }
        if (L4046_ps_->SaveHeaderFormat == C0x02_SAVE_HEADER_FORMAT_CHAOS_STRIKES_BACK) {
                L4039_ps_ = (CSB_SAVE_HEADER*)&L4046_ps_->SaveHeader;
        } else {
                L4041_ps_ = &L4046_ps_->SaveHeader;
        }
        if (L4038_ps_) {
                if (L4039_ps_) {
                        F7317_MAIN_CopyBytes_Alt((char*)L4038_ps_ + 256, (char*)L4039_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                        F7317_MAIN_CopyBytes_Alt((char*)L4038_ps_ + 288, (char*)L4039_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                        L4039_ps_->GameID = L4038_ps_->GameID + 1;
                        L4039_ps_->Platform = L4038_ps_->Platform;
                        L4039_ps_->Useless = 2;
                } else {
                        F7317_MAIN_CopyBytes_Alt((char*)L4038_ps_ + 256, (char*)L4041_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                        F7317_MAIN_CopyBytes_Alt((char*)L4038_ps_ + 288, (char*)L4041_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                        L4041_ps_->GameID = L4038_ps_->GameID + 1;
                        L4041_ps_->Platform = L4038_ps_->Platform;
                        L4041_ps_->Useless = 2;
                }
        } else {
                if (L4039_ps_) {
                        F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 256, (char*)L4039_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                        F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 288, (char*)L4039_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                        L4039_ps_->GameID = L4040_ps_->GameID + 1;
                        L4039_ps_->Platform = L4040_ps_->Platform;
                        L4039_ps_->Useless = 2;
                } else {
                        F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 256, (char*)L4041_ps_ + 256, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 32L);
                        F7317_MAIN_CopyBytes_Alt((char*)L4040_ps_ + 288, (char*)L4041_ps_ + 288, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                        L4041_ps_->GameID = L4040_ps_->GameID + 1;
                        L4041_ps_->Platform = L4040_ps_->Platform;
                        L4041_ps_->Useless = 2;
                }
        }
        F7088_CopyChampionPortraits(L4045_ps_, L4046_ps_);
        L4046_ps_->GlobalData.PartyChampionCount = G7114_LoadedChampionCount;
        for (L4052_ui_ = 0; L4052_ui_ < G7114_LoadedChampionCount; L4052_ui_++) {
                if ((L4051_i_ = L4046_ps_->GlobalData.PartyDirection - L4045_ps_->GlobalData.PartyDirection) != 0) {
                        L4051_i_ += 4;
                        L4042_uc_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C04_CHAMPION_INFO_CELL);
                        L4042_uc_ = (L4042_uc_ + L4051_i_) & 3;
                        F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C04_CHAMPION_INFO_CELL, (long)L4042_uc_);
                        L4042_uc_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C03_CHAMPION_INFO_DIRECTION);
                        L4042_uc_ = (L4042_uc_ + L4051_i_) & 3;
                        F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C03_CHAMPION_INFO_DIRECTION, (long)L4042_uc_);
                }
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C05_CHAMPION_INFO_ACTIONINDEX, (long)C0xFF_ACTION_NONE);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C06_CHAMPION_INFO_SYMBOLSTEP, 0L);
                L4047_pc_ = (char*)F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C09_CHAMPION_INFO_SYMBOLS);
                L4047_pc_[0] = 0;
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C10_CHAMPION_INFO_DIRECTIONMAXIMUMDAMAGERECEIVED, 0L);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C11_CHAMPION_INFO_MAXIMUMDAMAGERECEIVED, 0L);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C12_CHAMPION_INFO_POISONEVENTCOUNT, 0L);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C13_CHAMPION_INFO_ENABLEACTIONEVENTINDEX, -1L);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C14_CHAMPION_INFO_HIDEDAMAGERECEIVEDEVENTINDEX, -1L);
                L4043_ui_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C15_CHAMPION_INFO_ATTRIBUTES);
                L4043_ui_ &= MASK0x0010_MALE;
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C15_CHAMPION_INFO_ATTRIBUTES, (long)L4043_ui_);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C16_CHAMPION_INFO_WOUNDS, 0L);
                L4044_i_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C18_CHAMPION_INFO_MAXIMUMHEALTH);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C17_CHAMPION_INFO_CURRENTHEALTH, (long)L4044_i_);
                L4044_i_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C20_CHAMPION_INFO_MAXIMUMSTAMINA);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C19_CHAMPION_INFO_CURRENTSTAMINA, (long)L4044_i_);
                L4044_i_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C22_CHAMPION_INFO_MAXIMUMMANA);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C21_CHAMPION_INFO_CURRENTMANA, (long)L4044_i_);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C23_CHAMPION_INFO_ACTIONDEFENSE, 0L);
                L4044_i_ = M003_RANDOM(256) + 1500;
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C24_CHAMPION_INFO_FOOD, (long)L4044_i_);
                L4044_i_ = M003_RANDOM(256) + 1500;
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C25_CHAMPION_INFO_WATER, (long)L4044_i_);
                L4048_paauc_ = (unsigned char (*)[7][3])F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C26_CHAMPION_INFO_STATISTICS);
                for (L4051_i_ = 0; L4051_i_ <= 6; L4051_i_++) {
                        (*L4048_paauc_)[L4051_i_][C2_MINIMUM] = 30;
                        (*L4048_paauc_)[L4051_i_][C1_CURRENT] = (*L4048_paauc_)[L4051_i_][C0_MAXIMUM];
                }
                (*L4048_paauc_)[C0_STATISTIC_LUCK][C2_MINIMUM] = 10;
                L4049_ps_ = (SKILL*)F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C27_CHAMPION_INFO_SKILLS);
                L4051_i_ = 0;
                while (L4051_i_ < 20) {
                        L4049_ps_[L4051_i_++].TemporaryExperience = 0;
                }
                L4050_ps_ = (THING*)F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C28_CHAMPION_INFO_SLOTS);
                for (L4051_i_ = 0; L4051_i_ < 30; L4051_i_++) {
                        F7020_RemoveObjectModifiersFromStatistics(L4045_ps_, L4052_ui_, L4051_i_, L4050_ps_[L4051_i_]);
                        L4050_ps_[L4051_i_] = C0xFFFF_THING_NONE;
                }
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C29_CHAMPION_INFO_LOAD, 0L);
                F7068_SetChampionInfo(L4046_ps_, L4052_ui_, C30_CHAMPION_INFO_SHIELDDEFENSE, 0L);
        }
        for (L4052_ui_ = 0; L4052_ui_ < G7114_LoadedChampionCount; L4052_ui_++) {
                L4042_uc_ = F7067_GetChampionInfo(L4046_ps_, L4052_ui_, C04_CHAMPION_INFO_CELL);
                for (L4051_i_ = 0; L4051_i_ < G7114_LoadedChampionCount; L4051_i_++) {
                        if ((L4051_i_ != L4052_ui_) && ((unsigned char)F7067_GetChampionInfo(L4046_ps_, L4051_i_, C04_CHAMPION_INFO_CELL) == L4042_uc_)) {
                                L4042_uc_ = F7089_GetFirstCellWithNoChampion(L4046_ps_);
                                F7068_SetChampionInfo(L4046_ps_, L4051_i_, C04_CHAMPION_INFO_CELL, (long)L4042_uc_);
                        }
                }
        }
#endif
}

#ifdef MEDIA772_SU1E
int16_t F1987_Checksum(
)
{
        asm {
                        lea     F7014_SetCurrentInputInfoList(a5),a0
                        movea.l 2(a0),a0
                        moveq   #0x5F,d0
                        move.w  #1,d1
                        move.l  #0x4E5E4E75,d2
                @Tloc_2A0A:
                        add.w   (a0)+,d0
                        eor.w   d0,d1
                        addq.w  #1,d1
                        cmp.l   (a0),d2
                        bne.s   @Tloc_2A0A
        }
}

int16_t F1988_Checksum(
)
{
        asm {
                        lea     F1991_(a5),a0
                        movea.l 2(a0),a0
                        move.w  #0xFF22,d0
                        move.w  #0x34,d1
                        move.l  #0x4E5E4E75,d2
                @Tloc_2A2C:
                        add.w   (a0)+,d0
                        eor.w   d0,d1
                        addq.w  #1,d1
                        cmp.l   (a0),d2
                        bne.s   @Tloc_2A2C
        }
}
#endif

#ifdef MEDIA773_SU1E_AU1E
#ifdef MEDIA772_SU1E
void main()
#endif
#ifdef MEDIA762_AU1E
void main(FTL_LIBRARY* P5985_, FTL_EXECUTABLE* P5986_)
#endif
{
        char L5753_[128];
        int16_t L5754_;
#ifdef MEDIA762_AU1E
        char L6186_ac_Unreferenced[6];
#endif


#ifdef MEDIA762_AU1E
        if (F9008_OpenPRIM(P5985_, 2)) {
                F1088_OpenAmigaStuff();
                F2102_();
                F2098_();
                G7116_Bitmap_FilePickerArrows = F7023_Alloc((long)1200, MASK0x0008_MEMREQ);
                F7317_MAIN_CopyBytes_Alt(G2268_auc_Graphic_FilePickerArrows, G7116_Bitmap_FilePickerArrows, MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, (long)1200);
                F2104_CHAMPION_ConvertBitmapToAtariSTPlanar(G7116_Bitmap_FilePickerArrows, 32, 75);
                F1282_WriteString("UNPROTECTED version\n\r");
                G7114_LoadedChampionCount = 0;
#endif
                L5754_ = 1;
#ifdef MEDIA772_SU1E
                if (L5754_ == 2) {
                        F7101_sprintf(L5753_, "Copyright (C) %x\n\r", F1988_Checksum());
                        Cconws(L5753_);
                        F7101_sprintf(L5753_, "Software Heavn%x\n\r", F1987_Checksum());
                        Cconws(L5753_);
                        if ((int16_t)Crawcin() != '!') {
                                F1603_TerminateTOSProgram(0); /* Return code 0: no error */
                        }
                }
                F0436_STARTEND_FadeToPalette(G3749_aui_BlankPalette);
                F7021_InitAllocatedMemoryBlocks();
                F1525_OpenVDIWorkstation(0);
                G0348_Bitmap_Screen = Physbase();
                F1531_MouseHandler(1, G3404_VDIHandle);
                F1530_ShowMousePointerAsArrow(G3404_VDIHandle, 0);
                F1372_SetVerticalBlankInterrupt(1);
                F0924_SetCriticalErrorHandler();
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F0008_MAIN_ClearBytes(G0348_Bitmap_Screen, 32000L);
                F0078_MOUSE_DisableScreenUpdate();
                F0436_STARTEND_FadeToPalette(G3751_aui_Palette);
                G7111_Games = F7023_Alloc(8224L);
                F0008_MAIN_ClearBytes(G7111_Games, 8224L);
#endif
#ifdef MEDIA762_AU1E
                F2045_FadeToPalette(G3751_aui_Palette);
                G7111_Games = F2095_AllocateMemory((long)1868);
                F0008_MAIN_ClearBytes(G7111_Games, (long)1868);
#endif
                L5754_ = -1;
                while (L5754_ == -1) {
                        L5754_ = F7051_LoadGame(0);
                }
                if (L5754_ != -99) {
                        F7050_MainLoop();
                }
#ifdef MEDIA772_SU1E
                F7053_FreeGame(&G7111_Games[C0_GAME_SOURCE], 0);
                F7053_FreeGame(&G7111_Games[C1_GAME_DESTINATION], 1);
#endif
#ifdef MEDIA762_AU1E
                F7053_FreeGame(&G7111_Games[C0_GAME_SOURCE]);
                F7053_FreeGame(&G7111_Games[C1_GAME_DESTINATION]);
#endif
                F7024_Free(G7111_Games);
#ifdef MEDIA772_SU1E
                F1992_RequestUtilityDiskInDrive();
                F1372_SetVerticalBlankInterrupt(2);
                F1531_MouseHandler(2, G3404_VDIHandle);
                F1526_CloseWorkstationAndExitApplication();
                F7022_FreeAllAllocatedBlocks();
                asm {
                        move.w  #0x6160,(a5)
                        move.w  #0x5223,2(a5)
                        move.l  G3558_ac_NextFTLModuleToRun(a5),0x1C(a5) /* Next FTL module to run */
                }
#endif
#ifdef MEDIA762_AU1E
                if (G7116_Bitmap_FilePickerArrows) {
                        F7024_Free(G7116_Bitmap_FilePickerArrows);
                }
                G7116_Bitmap_FilePickerArrows = NULL;
                F2099_();
                F2103_();
                P5986_->Parameter = FTL_APPB;
                F1089_CloseAmigaStuff();
        } else {
                P5986_->Parameter = FTL_APPB;
        }
#endif
}
#endif

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
void F7091_RunChampionEditor(
)
{
        int16_t L4053_i_;
        int16_t L4057_i_;
        int16_t L4056_i_;
        PROGRAM_STATE L4054_s_;
        char L6052_ac_Unreferenced[6];
        char L4055_c_;


        L4055_c_ = C0_FALSE;
        G7111_Games = NULL;
        for (L4056_i_ = 0; L4056_i_ < 4; L4056_i_++) {
                G2243_OnScreenPortraitBitmaps[L4056_i_] = NULL;
        }
        for (L4056_i_ = 0; L4056_i_ < 2; L4056_i_++) {
                G2244_apuc_DialogBitmaps[L4056_i_] = NULL;
        }
        G7113_DialogBitmapIndex = 0;
        G7112_HideMousePointerCount = 0;
        G7117_Bitmap_Mirror = NULL;
        G7116_Bitmap_FilePickerArrows = NULL;
        G7114_LoadedChampionCount = 0;
        L4057_i_ = 1;
        G2329_s_UndoPortrait.PortraitBitmap = NULL;
        G2328_s_TempPortrait.PortraitBitmap = NULL;
        G7115_DialogByteCount = 0;
        if (F7269_InitChampionEditor() < 0) {
                L4053_i_ = -1;
        } else {
                L4055_c_ = C1_TRUE;
#ifdef MEDIA699_X31J_AU2E_AU3E
                F0078_MOUSE_DisableScreenUpdate();
#endif
                L4054_s_.Previous = G7128_LastProgramState;
                L4054_s_.Ordinal = ++G7129_ProgramStateOrdinal;
                G7128_LastProgramState = &L4054_s_;
                L4054_s_.ReturnValue = setjmp(L4054_s_.State);
                if (L4054_s_.ReturnValue) {
                        L4053_i_ = -99;
                } else {
                        for (L4056_i_ = 0; L4056_i_ < 4; L4056_i_++) {
                                G2243_OnScreenPortraitBitmaps[L4056_i_] = F7023_Alloc(F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight), MASK0x0008_MEMREQ);
                        }
                        G7115_DialogByteCount = F7254_(G7044_DialogWidth, G7045_DialogHeight);
                        for (L4056_i_ = 0; L4056_i_ < 2; L4056_i_++) {
                                G2244_apuc_DialogBitmaps[L4056_i_] = (unsigned char*)F7023_Alloc(G7115_DialogByteCount, MASK0x0008_MEMREQ);
                        }
                        G2329_s_UndoPortrait.PortraitBitmap = (char*)F7023_Alloc(F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight), MASK0x0400_MEMREQ);
                        G2328_s_TempPortrait.PortraitBitmap = (char*)F7023_Alloc(F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight), MASK0x0400_MEMREQ);
                        G7111_Games = (GAME*)F7023_Alloc((long)(2 * sizeof(GAME)), MASK0x0400_MEMREQ);
                        F0008_MAIN_ClearBytes(M772_CAST_PC(G7111_Games), (long)(2 * sizeof(GAME)));
#ifdef MEDIA768_AU2E_AU3E
                        if (F2143_Initialize(&G3918_)) {
                                L4053_i_ = -2;
                        } else {
                                if (F2106_InitializeUsioDataFilteredQueue()) {
                                        L4053_i_ = -3;
                                } else {
#endif
                                        L4057_i_ = -1;
                                        while ((L4057_i_ != 1) && (L4057_i_ != -3)) {
                                                L4057_i_ = F7051_LoadGame(C0_GAME_SOURCE);
                                        }
                                        if (L4057_i_ == 1) {
                                                F7050_MainLoop();
                                        }
                                        L4053_i_ = 0;
#ifdef MEDIA768_AU2E_AU3E
                                }
                        }
#endif
                }
        }
        F7005_Quit(0);
#ifdef MEDIA768_AU2E_AU3E
        F2107_UninitializeUsioDataFilteredQueue();
        F2144_Free(&G3918_);
#endif
        for (L4056_i_ = 0; L4056_i_ < 4; L4056_i_++) {
                if (G2243_OnScreenPortraitBitmaps[L4056_i_]) {
                        F7024_Free(G2243_OnScreenPortraitBitmaps[L4056_i_]);
                }
        }
        for (L4056_i_ = 0; L4056_i_ < 2; L4056_i_++) {
                if (G2244_apuc_DialogBitmaps[L4056_i_]) {
                        F7024_Free(G2244_apuc_DialogBitmaps[L4056_i_]);
                }
        }
        if (G2329_s_UndoPortrait.PortraitBitmap) {
                F7024_Free(G2329_s_UndoPortrait.PortraitBitmap);
        }
        if (G2328_s_TempPortrait.PortraitBitmap) {
                F7024_Free(G2328_s_TempPortrait.PortraitBitmap);
        }
        F7111_RestorePreviousProgramState();
        if (G7111_Games) {
                F7053_FreeGame(&G7111_Games[C0_GAME_SOURCE]);
                F7053_FreeGame(&G7111_Games[C1_GAME_DESTINATION]);
                F7024_Free((char HUGE*)G7111_Games);
        }
#ifdef MEDIA671_F31E_F31J_P31J
        F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
        if (L4055_c_) {
#ifdef MEDIA699_X31J_AU2E_AU3E
                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
                F7270_Cleanup();
        }
}
#endif

#ifdef MEDIA671_F31E_F31J_P31J
int16_t F7092_Unreferenced(char* P3767_pc_)
{
        int16_t L4058_i_;


        F7322_EmptyFunction("!stub called: '");
        F7322_EmptyFunction(P3767_pc_);
        F7322_EmptyFunction("' !\n\r");
        while (F7320_CallF0760_Cconis()) {
                F7319_Crawcin();
        }
        do {
                F7322_EmptyFunction("!f)reeze system, e)xit(-1), r)eturn ?\n\r");
                while (!F7320_CallF0760_Cconis());
                L4058_i_ = F7319_Crawcin();
                if (L4058_i_ == 'f') {
                        F7322_EmptyFunction("!System frozen...\n\r");
                        for (;;);
                }
                if (L4058_i_ == 'e') {
                        F7322_EmptyFunction("!exit(-1) called...\n\r");
                        F7273_DrawDialogThenHang(NULL);
                }
        } while (L4058_i_ != 'r');
        F7322_EmptyFunction("!Returning...\n\r");
        return 0;
}
#endif
#endif
