Skip to content

Instantly share code, notes, and snippets.

@JuniorDjjr
Created May 13, 2017 06:27
Show Gist options
  • Save JuniorDjjr/bf6732f41760a62d3cb1888fa8222230 to your computer and use it in GitHub Desktop.
Save JuniorDjjr/bf6732f41760a62d3cb1888fa8222230 to your computer and use it in GitHub Desktop.
/*
Map Mod Mover
http://www.mixmods.com.br/2017/05/programa-map-mod-mover-mudar-posicao-mapas.html
*/
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
#pragma warning(disable:4996) // disable 'unsafe' warnings
using namespace std;
int main() {
float fNewX;
float fNewY;
float fNewZ;
char str[510];
string str2;
string FileName;
FILE * pFile;
FILE * pFileNew;
char cMode;
int result;
int iId;
char sDff[20];
int iInterior;
float x;
float y;
float z;
float rot1;
float rot2;
float rot3;
float rot4;
int iFlag;
float totalX = 0.0;
float totalY = 0.0;
float totalZ = 0.0;
int counter = 0;
printf("----------------------------\n");
printf("-- Digite o nome do arquivo (com extensao, como '.ipl')\n");
printf("-- Note que o arquivo *deve* estar localizado na mesma pasta deste aplicativo.\n");
printf("----------------------------\n");
printf("Nome do arquivo: ");
/*printf("----------------------------\n");
printf("-- Enter the name of file (with extension, as '.ipl')\n");
printf("-- Do note that the file *must be* located in same folder of this application.\n");
printf("----------------------------\n");
printf("File name: ");*/
scanf("%s", (char *)&FileName);
printf("\n");
char FileNameBuffer[30];
snprintf(FileNameBuffer, 30, "%s", (char *)&FileName);
pFile = fopen(FileNameBuffer, "r+");
if (pFile != NULL)
{
// calculate central coord (by average values)
while (!feof(pFile))
{
result = fscanf(pFile, "%d, %s %d, %f, %f, %f, %f, %f, %f, %f, %d", &iId, &sDff, &iInterior, &x, &y, &z, &rot1, &rot2, &rot3, &rot4, &iFlag);
if (result == 11)
{
totalX += x;
totalY += y;
totalZ += z;
counter++;
}
else {
if (fgets(str, 500, pFile) == NULL) break;
}
}
rewind(pFile); // ret start of file
totalX /= counter;
totalY /= counter;
totalZ /= counter;
printf("----------------------------\n");
printf("-- A coordenada central deste mapa e de:\n");
printf("-- %f %f %f\n", totalX, totalY, totalZ);
printf("----------------------------\n");
printf("-- Como voce deseja move-lo? Digite '1' ou '2':\n");
printf("--- 1 = Digitar uma coordenada central de destino\n");
printf("--- 2 = Mover o X Y Z manualmente com numeros separados\n");
printf("-- Dica: Primeiro use o modo '1' para determinar a coordenada onde voce deseja que fique. Com certeza o\n");
printf("-- resultado nao ficara correto na primeira vez, portanto, em seguida utilize o modo '2' para ajusta-lo melhor.\n");
printf("-- Por exemplo, se apos usar o modo '1' o mapa ficou 20 metros errado pro leste e 5 pro sul, use o modo '2' com\n");
printf("-- 'X=-20 y=5 z=0' para mover o mapa 20 metros pro oeste e 5 pro norte.\n");
printf("----------------------------\n");
/*printf("----------------------------\n");
printf("-- The central coordinate of this map is:\n");
printf("-- %f %f %f\n", totalX, totalY, totalZ);
printf("----------------------------\n");
printf("-- How you wanto to move it? Enter '1' or '2':\n");
printf("--- 1 = Enter a central destination coordinate\n");
printf("--- 2 = Move the X Y Z manually by separated numbers\n");
printf("-- Tip: Firstly use the mode '1' to determine the coordinate where you want it to be. For sure the\n");
printf("-- result will be not correct by the first time, so, after use the mode '2' to adjust it better.\n");
printf("-- For example, if after use mode '1' the map stayed 20 meters wrong to east and 5 to south use the\n");
printf("-- mode '2' with 'X=-20 y=5 z=0' to move the map 20 meters to west and 5 to north.\n");
printf("----------------------------\n");*/
do {
printf("Modo(1|2): ");
//printf("Mode(1|2): ");
std::cin >> cMode;
} while (cMode != '1' && cMode != '2');
printf("\n");
if (cMode == '1')
{
printf("----------------------------\n");
printf("-- Onde voce quer que este mapa esteja?\n");
printf("-- Digite a coordenada X Y Z que eu tentarei move-lo ate la!\n");
printf("-- Recomendavel que o Z fique bem acima do chao caso este mapa tenha construcoes altas, como predios.\n");
printf("----------------------------\n");
/*printf("----------------------------\n");
printf("-- Where do you want this map to be?\n");
printf("-- Enter the coordinate X Y Z that I'll try to move it for you!\n");
printf("-- It is recommended that the Z be well above the ground if this map has tall buildings such as buildings.\n");
printf("----------------------------\n");*/
printf("X Y Z: ");
std::cin >> fNewX >> fNewY >> fNewZ;
printf("\n");
fNewX -= totalX;
fNewY -= totalY;
fNewZ -= totalZ;
}
else {
printf("----------------------------\n");
printf("-- Digite quantos metros deve ser movido este mapa nas direcoes X, Y e Z\n");
printf("-- Sinta-se livre em usar numeros reais ou negativos, como '-10.5', '24.51' etc\n");
printf("--- Lembre-se que: X=Leste, Y=Norte e Z=Cima. Possivelmente voce tera que re-usar esta ferramenta\n");
printf("--- varias vezes, por exemplo movendo uns 10 metros pro norte, 5 pro leste etc e testando.\n");
printf("--- Por exemplo: 'X=12.5 Y=-20 Z=-2.55' ira mover 12.5 metros pro leste, 20 pro sul e 2.55 pra baixo.\n");
printf("----------------------------\n");
/*printf("----------------------------\n");
printf("-- Enter how many meters this map should be moved in the directions X, Y and Z\n");
printf("-- Feel free to use real numbers or negatives, as '-10.5', '24.51' etc\n");
printf("--- Remember that: X=East, Y=North and Z=Up. Possibly you will need to use this tool\n");
printf("--- several times, for example moving about 10 meters to north, 5 to east etc and testing.\n");
printf("--- For example: 'X=12.5 Y=-20 Z=-2.55' will move 12.5 meters to east, 20 to south and 2.55 down.\n");
printf("----------------------------\n");*/
printf("Mover X: ");
std::cin >> fNewX;
printf("Mover Y: ");
std::cin >> fNewY;
printf("Mover Z: ");
std::cin >> fNewZ;
/*printf("Move X: ");
std::cin >> fNewX;
printf("Move Y: ");
std::cin >> fNewY;
printf("Move Z: ");
std::cin >> fNewZ;*/
printf("\n");
}
pFileNew = fopen("temp.ipl", "w+");
printf("-------------------------------------------------\n");
printf("--- + X=%f Y=%f Z=%f\n", fNewX, fNewY, fNewZ);
printf("-------------------------------------------------\n");
printf("------------------- INICIADO --------------------\n");
//printf("-------------------- STARTED --------------------\n");
printf("\n");
while (!feof(pFile))
{
result = fscanf(pFile, "%d, %s %d, %f, %f, %f, %f, %f, %f, %f, %d", &iId, &sDff, &iInterior, &x, &y, &z, &rot1, &rot2, &rot3, &rot4, &iFlag);
if (result == 11)
{
printf("ORIGINAL(%d): %d, %s, %d, %f, %f, %f, %f, %f, %f, %f, %d \n", result, iId, sDff, iInterior, x, y, z, rot1, rot2, rot3, rot4, iFlag);
x += fNewX;
y += fNewY;
z += fNewZ;
fprintf(pFileNew, "%d, %s %d, %f, %f, %f, %f, %f, %f, %f, %d \n", iId, sDff, iInterior, x, y, z, rot1, rot2, rot3, rot4, iFlag);
printf("NOVA: %d, %s %d, %f, %f, %f, %f, %f, %f, %f, %d \n", iId, sDff, iInterior, x, y, z, rot1, rot2, rot3, rot4, iFlag);
//printf("NEW: %d, %s %d, %f, %f, %f, %f, %f, %f, %f, %d \n", iId, sDff, iInterior, x, y, z, rot1, rot2, rot3, rot4, iFlag);
printf("\n");
}
else {
if (fgets(str, 500, pFile) == NULL) {
break;
}
if (result == 1)
{
sprintf((char *)&str2, "%d%s", iId, &str);
fputs((char *)&str2, pFileNew);
printf("(%d) %s \n", result, (char *)&str2);
}
else {
fputs((char *)&str, pFileNew);
printf("(%d) %s \n", result, (char *)&str);
}
}
}
printf("------------------ TERMINADO --------------------\n");
//printf("------------------- FINISHED --------------------\n");
printf("-------------------------------------------------\n");
fclose(pFile);
fclose(pFileNew);
remove("backup.ipl");
FILE * TempFile = fopen("backup.ipl", "r");
if (TempFile != NULL)
{
printf("\n");
printf("!! Erro ao deletar 'backup.ipl' !!\n");
printf("- Possivelmente foi bloqueado pelo Windows ou outro aplicativo. Utilize este aplicativo em outro lugar, como Documentos, ou inicie-o em modo de administrador.\n");
printf("- Em ultimos casos, espera-se que o arquivo temp.ipl esteja com as devidas alteracoes. Use-o.\n");
/*printf("!! Error when deleting 'backup.ipl' !!\n");
printf("- Possibly was blocked by Windows or another application. Use this app in another location, as Documents, or start it in administrator mode.\n");
printf("- In last cases, it's expected that the file temp.ipl is with the necessary alterations. Use it.\n");*/
printf("\n");
}
else {
rename(FileNameBuffer, "backup.ipl");
rename("temp.ipl", FileNameBuffer);
printf("\n");
printf("Pronto!\n");
printf("O arquivo '%s' esta devidamente atualizado.\n", FileNameBuffer);
printf("Por conveniencia, a versao anterior foi guardada como 'backup.ipl'\n");
printf("Caso fique dois arquivos com nome 'backup.ipl', atualize a pasta (F5).\n");
printf("\n");
printf("Map Mod Mover criado por Junior_Djjr (www.MixMods.com.br).\n");
/*printf("Done!\n");
printf("The file '%s' is properly updated.\n", FileNameBuffer);
printf("For convenience, the old version was stored as 'backup.ipl'\n");
printf("If you get two named files 'backup.ipl', refresh the folder (F5).\n");
printf("\n");
printf("Map Mod Mover created by Junior_Djjr (www.MixMods.com.br).\n");*/
printf("\n");
}
if (TempFile != NULL) fclose(TempFile);
system("pause");
return 0;
}
else
{
printf("\n");
printf("!! Nao foi possivel abrir o arquivo '%s' !! \n", FileNameBuffer);
printf("Possiveis motivos:\n");
printf("- Voce nao digitou a extensao do arquivo ('.ipl')\n");
printf("- O arquivo nao esta na mesma pasta deste .exe\n");
printf("- Bloqueado pelo Windows. Utilize este aplicativo em outro lugar, como Documentos, ou inicie-o em modo de administrador.\n");
/*printf("!! Unable to open file '%s' !! \n", FileNameBuffer);
printf("Possible reasons:\n");
printf("- You didn't type ('.ipl')\n");
printf("- The file isn't at same folder of this .exe\n");
printf("- Blocked by Windows. Use this app elsewhere, as Documents, or start it in administrator mode.\n");*/
printf("\n");
system("pause");
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment