Any
/
vae
/com3d
/[CM3D2]English Mod Tools Pack
/[CM3D2]Various Modding Tools 151220 (English)
/src
/[CM3D2]tex & menu txt path corrector.ahk
FileEncoding, UTF-8-RAW | |
file_paths := "" | |
Loop, %0% { | |
path := %A_Index% | |
file_paths = %file_paths%%path%| | |
} | |
if (file_paths == "") { | |
default_path := GetDefaultPath() | |
FileSelectFile, paths, 7, %default_path%, please select a .tex or .menu file, Supported files(*.tex;*.menu) | |
if (ErrorLevel == 1) { | |
ExitApp | |
} | |
StringSplit, $, paths, `n | |
if (2 < $0) { | |
Loop, Parse, paths, `n, `r | |
{ | |
if (A_LoopField == "") { | |
continue | |
} | |
if (A_Index == 1) { | |
dir := A_LoopField | |
} | |
else { | |
file_paths = %file_paths%%dir%\%A_LoopField%| | |
} | |
} | |
} | |
else { | |
file_paths := paths | |
file_paths := RTrim(file_paths, "`n`r") | |
} | |
} | |
file_paths := RTrim(file_paths, "|") | |
Loop, Parse, file_paths, | | |
{ | |
file_path := A_LoopField | |
file := FileOpen(file_path, "r") | |
type := ReadString(file) | |
if (type == "CM3D2_TEX") { | |
file.Seek(4, 1) | |
top_len := file.Pos | |
file.Seek(0) | |
file.RawRead(top_raw, top_len) | |
path := ReadString(file) | |
end_len := file.Length - file.Pos | |
file.RawRead(end_raw, end_len) | |
file.Close() | |
if (RegExMatch(file_path, "\\GameData\\texture[^\\]*\\texture\\") != 0) { | |
SplitPath, file_path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive | |
new_path := RegExReplace(OutDir . "\" . OutNameNoExt . ".png", "^.+\\GameData(\\texture[^\\]*\\texture\\)", "$1") | |
new_path = assets%new_path% | |
StringReplace, new_path, new_path, \, /, All | |
MsgBox, %path%`n↓`n%new_path% | |
} | |
else { | |
SplitPath, file_path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive | |
InputBox, new_path, , %OutFileName%Please enter the texture path, , 800, 130, , , , , assets/texture/texture/ | |
if (ErrorLevel != 0) { | |
ExitApp | |
} | |
} | |
file := FileOpen(file_path, "w") | |
file.RawWrite(top_raw, top_len) | |
WriteString(file, new_path) | |
file.RawWrite(end_raw, end_len) | |
file.Close() | |
} | |
else if (type == "CM3D2_MENU") { | |
file.Seek(4, 1) | |
top_len := file.Pos | |
file.Seek(0) | |
file.RawRead(top_raw, top_len) | |
path := ReadString(file) | |
end_len := file.Length - file.Pos | |
file.RawRead(end_raw, end_len) | |
file.Close() | |
if (RegExMatch(file_path, "\\GameData\\menu[^\\]*\\menu\\") != 0) { | |
SplitPath, file_path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive | |
new_path := RegExReplace(OutDir . "\" . OutNameNoExt . ".txt", "^.+\\GameData(\\menu[^\\]*\\menu\\)", "$1") | |
new_path = assets%new_path% | |
StringReplace, new_path, new_path, \, /, All | |
MsgBox, %path%`n↓`n%new_path% | |
} | |
else { | |
SplitPath, file_path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive | |
InputBox, new_path, , %OutFileName%Please enter the texture path, , 800, 130, , , , , assets/menu/menu/ | |
if (ErrorLevel != 0) { | |
ExitApp | |
} | |
} | |
file := FileOpen(file_path, "w") | |
file.RawWrite(top_raw, top_len) | |
WriteString(file, new_path) | |
file.RawWrite(end_raw, end_len) | |
file.Close() | |
} | |
} | |
ExitApp | |
GetStringLength(string) { | |
count = 0 | |
Loop, Parse, string | |
{ | |
count += 1 | |
if (RegExMatch(A_LoopField, "^[^\x01-\x7E]$") != 0) { | |
count += 2 | |
} | |
} | |
return count | |
} | |
ReadString(file, size=-1) { | |
if (size <= -1) { | |
size := 0 | |
chars := Object() | |
Loop { | |
char := file.ReadUChar() | |
chars[A_Index] := char | |
if (char < 128) { | |
break | |
} | |
} | |
num := GetMaxIndex(chars) | |
Loop, %num% { | |
char := chars[A_Index] | |
multi := 256 ** (A_Index - 1) | |
size += char * multi | |
if (1 < A_Index) { | |
size -= (multi / 2) * (char + 1) | |
} | |
} | |
} | |
string := "" | |
count = 0 | |
Loop, 9999 { | |
if (size <= count) { | |
break | |
} | |
s := file.Read(1) | |
string := string . s | |
count += GetStringLength(s) | |
if (GetStringLength(s) == 0) { | |
pos := file.Pos | |
MsgBox, Failed to read file(Path: %pos%)`nQuit | |
ExitApp | |
} | |
} | |
return string | |
} | |
WriteString(file, string) { | |
len := GetStringLength(string) | |
if (128 <= len) { | |
temp := Mod(len, 128) + 128 | |
file.WriteChar(temp) | |
temp := len / 128 | |
file.WriteChar(temp) | |
} | |
else { | |
file.WriteChar(len) | |
} | |
file.Write(string) | |
} | |
GetMaxIndex(obj) { | |
value := obj.MaxIndex() | |
if (value == "") { | |
return 0 | |
} | |
return value | |
} | |
GetDefaultPath() { | |
RegRead, path, HKEY_CURRENT_USER, Software\KISS\カスタムメイド3D2, InstallPath | |
if (ErrorLevel == 0) { | |
path = %path%GameData\ | |
} | |
else { | |
path := A_ScriptDir | |
} | |
return path | |
} | |